#!/usr/bin/python
#
# Copyright (c) 2007-2008 The PyAMF Project.
# See LICENSE for details.

"""
Extracts and displays information for files that contain AMF data.
"""

import glob
from optparse import OptionParser
from fnmatch import fnmatch

import pyamf
from pyamf import remoting

def parse_options():
    """
    Parse command-line arguments.
    """
    parser = OptionParser()

    parser.add_option("-d", "--debug", action="store_true", dest="debug",
        default=False, help="Enable debugging")
    parser.add_option("--dump", action="store_true", dest="dump",
        default=False, help="Shows a hexdump of the file")
    parser.add_option("--strict", action="store_true", dest="strict",
        default=False, help="""Option to decode typed but unaliased classes """
        """without raising UnknownClassAlias""")

    return parser.parse_args()

def read_file(fname):
    """
    Read file containing AMF data.
    """
    f = file(fname, "rb")
    data = f.read()
    f.close()

    return data

def main():
    """
    Run AMF decoder on input file.
    """
    (options, args) = parse_options()

    print 'Using pyamf from: %s' % (pyamf,)
    print 'Strict = ' + str(options.strict)

    for arg in args:
        for fname in glob.glob(arg):
            if fnmatch(fname, '*.amf*'):
                body = read_file(fname)

                try:
                    print "\nDecoding file:", fname
                    request = remoting.decode(body, None, options.strict)

                    if options.debug:
                        for name, message in request:
                            print "  %s: %s" % (name, message)
                except pyamf.UnknownClassAlias, c:
                    if options.debug:
                        print '\n    Warning: %s' % c
                except pyamf.DecodeError, c:
                    if options.debug:
                        print '\n    Warning: %s' % c
                except:
                    raise

                if options.dump:
                    print
                    print pyamf.util.hexdump(body)

                print "-" * 80

if __name__ == '__main__':
    main()

@@ -4,16 +4,20 @@
 usr/bin/
+env 
 python%0A#
@@ -44,10 +44,10 @@
 7-20
+1
 0
-8
  The
@@ -282,16 +282,17 @@
 moting%0A%0A
+%0A
 def pars
@@ -350,24 +350,69 @@
 ts.%0A    %22%22%22%0A
+    usage = %22Usage: %25prog %5Boptions%5D file(s)%22%0A
     parser =
@@ -425,16 +425,27 @@
 nParser(
+usage=usage
 )%0A%0A    p
@@ -918,16 +918,17 @@
 args()%0A%0A
+%0A
 def read
@@ -1070,16 +1070,17 @@
 n data%0A%0A
+%0A
 def main
@@ -2179,16 +2179,17 @@
 %22 * 80%0A%0A
+%0A
 if __nam

Improve script usage description and update copyright.