# Path: amfast/decoder.py
# class Decoder(object):
#     """A wrapper class for convenient access to amfast.decode.decode.
# 
#     Decoder
#     ========
#      * amf3 - bool - True to decode as AMF3.
#      * class_def_mapper - amfast.class_def.ClassDefMapper - The object that retrieves ClassDef objects.
#     """ 
# 
#     def __init__(self, amf3=False, class_def_mapper=None):
# 
#         self.amf3 = amf3
# 
#         if class_def_mapper is None:
#             class_def_mapper = ClassDefMapper()
#         self.class_def_mapper = class_def_mapper
# 
#     def _getContext(self, input, amf3=None):
#         if amf3 is None:
#             amf3 = self.amf3
#         return DecoderContext(input, amf3=amf3, class_def_mapper=self.class_def_mapper)
# 
#     def decode(self, val, amf3=None):
#         """Decode a string or file-like-object from AMF."""
#         return decode(self._getContext(val, amf3))
# 
#     def decode_packet(self, val, amf3=None):
#         """Decode a string or file-like-object representing an AMF packet."""
#         return decode_packet(self._getContext(val, amf3))


import unittest
import amfast.decode as decode
import amfast.class_def as class_def
        import datetime
        import xml.dom.minidom
from StringIO import StringIO
from amfast.context import DecoderContext
from amfast.decoder import Decoder
        encoded += '\x00\x00\t' # terminator
        result = decode.decode(DecoderContext(encoded))
        self.assertEquals('eggs', result['spam'])

        result = decode.decode(DecoderContext(StringIO(encoded)))
        self.assertEquals('eggs', result['spam'])

    def testMixedArray(self):
        encoded = '\x08\x00\x00\x00\x00' # mixed array header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator

        result = decode.decode(DecoderContext(encoded))
        self.assertEquals('eggs', result['spam'])

        result = decode.decode(DecoderContext(StringIO(encoded)))
        self.assertEquals('eggs', result['spam'])

    def testArray(self):
        decoded = [0, 1, 1.23456789]
        encoded = '\x0A\x00\x00\x00\x03' # 3 element array header
        encoded += '\x00\x00\x00\x00\x00\x00\x00\x00\x00' # element 1
        encoded += '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00' #element 2
        encoded += '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b' #element 3

        result = decode.decode(DecoderContext(encoded))
        for i, obj in enumerate(decoded):
            self.assertEquals(obj, result[i])

        result = decode.decode(DecoderContext(StringIO(encoded)))

# Path: amfast/decoder.py
# class Decoder(object):
#     """A wrapper class for convenient access to amfast.decode.decode.
# 
#     Decoder
#     ========
#      * amf3 - bool - True to decode as AMF3.
#      * class_def_mapper - amfast.class_def.ClassDefMapper - The object that retrieves ClassDef objects.
#     """ 
# 
#     def __init__(self, amf3=False, class_def_mapper=None):
# 
#         self.amf3 = amf3
# 
#         if class_def_mapper is None:
#             class_def_mapper = ClassDefMapper()
#         self.class_def_mapper = class_def_mapper
# 
#     def _getContext(self, input, amf3=None):
#         if amf3 is None:
#             amf3 = self.amf3
#         return DecoderContext(input, amf3=amf3, class_def_mapper=self.class_def_mapper)
# 
#     def decode(self, val, amf3=None):
#         """Decode a string or file-like-object from AMF."""
#         return decode(self._getContext(val, amf3))
# 
#     def decode_packet(self, val, amf3=None):
#         """Decode a string or file-like-object representing an AMF packet."""
#         return decode_packet(self._getContext(val, amf3))


# Path: tests/amf0_decoder_test.py
import unittest
import amfast.decode as decode
import amfast.class_def as class_def
        import datetime
        import xml.dom.minidom
from StringIO import StringIO
from amfast.context import DecoderContext
from amfast.decoder import Decoder

        encoded += '\x00\x00\t' # terminator
        result = decode.decode(DecoderContext(encoded))
        self.assertEquals('eggs', result['spam'])

        result = decode.decode(DecoderContext(StringIO(encoded)))
        self.assertEquals('eggs', result['spam'])

    def testMixedArray(self):
        encoded = '\x08\x00\x00\x00\x00' # mixed array header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator

        result = decode.decode(DecoderContext(encoded))
        self.assertEquals('eggs', result['spam'])

        result = decode.decode(DecoderContext(StringIO(encoded)))
        self.assertEquals('eggs', result['spam'])

    def testArray(self):
        decoded = [0, 1, 1.23456789]
        encoded = '\x0A\x00\x00\x00\x03' # 3 element array header
        encoded += '\x00\x00\x00\x00\x00\x00\x00\x00\x00' # element 1
        encoded += '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00' #element 2
        encoded += '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b' #element 3

        result = decode.decode(DecoderContext(encoded))
        for i, obj in enumerate(decoded):
            self.assertEquals(obj, result[i])

        result = decode.decode(DecoderContext(StringIO(encoded)))

        for i, obj in enumerate(decoded):