# Path: amfast/encoder.py
# class Encoder(object):
#     """A wrapper class for convenient access to amfast.encode.encode.
# 
#     Encoder
#     ========
#      * amf3 - bool - True to encode as AMF3.
#      * use_collections - bool - True to encode lists and tuples as ArrayCollections.
#      * use_proxies - bool - True to encode dicts as ObjectProxies.
#      * use_references - bool - True to encode multiply occuring objects by reference.
#      * use_legacy_xml - bool - True to XML as XMLDocument instead of e4x.
#      * include_private - bool - True to encode attributes starting with '_'.
#      * class_def_mapper - amfast.class_def.ClassDefMapper - The object that retrieves ClassDef objects.
#      * buffer - file-like-object - Output buffer. Set to None to output to a string.
# 
#     """ 
# 
#     def __init__(self, amf3=False, use_collections=False, use_proxies=False,
#         use_references=True, use_legacy_xml=False, include_private=False,
#         class_def_mapper=None, buffer=None):
# 
#         self.amf3 = amf3
#         self.use_collections = use_collections
#         self.use_proxies = use_proxies
#         self.use_references = use_references
#         self.use_legacy_xml = use_legacy_xml
#         self.include_private = include_private
# 
#         if class_def_mapper is None:
#             class_def_mapper = ClassDefMapper()
#         self.class_def_mapper = class_def_mapper
# 
#         self.buffer = buffer
# 
#     def _getContext(self, amf3=None):
#         if amf3 is None:
#             amf3 = self.amf3
# 
#         kwargs = {
#             'amf3': amf3,
#             'use_collections': self.use_collections,
#             'use_proxies': self.use_proxies,
#             'use_references': self.use_references,
#             'use_legacy_xml': self.use_legacy_xml,
#             'include_private': self.include_private,
#             'class_def_mapper': self.class_def_mapper
#         }
#  
#         if self.buffer is not None:
#             kwargs['buffer'] = self.buffer
# 
#         return EncoderContext(**kwargs);
# 
#     def encode(self, val, amf3=None):
#         """Encode a value to AMF."""
#         return encode(val, self._getContext(amf3))
# 
#     def encode_packet(self, val, amf3=None):
#         """Encode an AMF packet."""
#         return encode_packet(val, self._getContext(amf3))


import unittest
import amfast.encode as encode
import amfast.class_def as class_def
        import datetime
        import xml.dom.minidom
from amfast.context import EncoderContext
from amfast.encoder import Encoder
        from amfast.class_def.as_types import AsProxy
        from amfast.class_def.as_types import AsNoProxy
        from amfast.class_def.as_types import AsProxy
        from amfast.class_def.as_types import AsProxy
        from amfast.class_def.as_types import AsNoProxy
            self.assertEquals(encoding, encode.encode(string))

    def testLongString(self):
        decoded = 's' * 65537
        encoded = '\x0C\x00\x01\x00\x01' + decoded

        self.assertEquals('\x0C\x00\x01\x00\x01', encode.encode(decoded)[0:5])
        self.assertEquals(65537 + 5, len(encode.encode(decoded)))

    def testNull(self):
        self.assertEquals('\x05', encode.encode(None))

    def testTuple(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

        self.assertEquals(encoded, encode.encode(decoded))

    def testList(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

        self.assertEquals(encoded, encode.encode(decoded))


# Path: amfast/encoder.py
# class Encoder(object):
#     """A wrapper class for convenient access to amfast.encode.encode.
# 
#     Encoder
#     ========
#      * amf3 - bool - True to encode as AMF3.
#      * use_collections - bool - True to encode lists and tuples as ArrayCollections.
#      * use_proxies - bool - True to encode dicts as ObjectProxies.
#      * use_references - bool - True to encode multiply occuring objects by reference.
#      * use_legacy_xml - bool - True to XML as XMLDocument instead of e4x.
#      * include_private - bool - True to encode attributes starting with '_'.
#      * class_def_mapper - amfast.class_def.ClassDefMapper - The object that retrieves ClassDef objects.
#      * buffer - file-like-object - Output buffer. Set to None to output to a string.
# 
#     """ 
# 
#     def __init__(self, amf3=False, use_collections=False, use_proxies=False,
#         use_references=True, use_legacy_xml=False, include_private=False,
#         class_def_mapper=None, buffer=None):
# 
#         self.amf3 = amf3
#         self.use_collections = use_collections
#         self.use_proxies = use_proxies
#         self.use_references = use_references
#         self.use_legacy_xml = use_legacy_xml
#         self.include_private = include_private
# 
#         if class_def_mapper is None:
#             class_def_mapper = ClassDefMapper()
#         self.class_def_mapper = class_def_mapper
# 
#         self.buffer = buffer
# 
#     def _getContext(self, amf3=None):
#         if amf3 is None:
#             amf3 = self.amf3
# 
#         kwargs = {
#             'amf3': amf3,
#             'use_collections': self.use_collections,
#             'use_proxies': self.use_proxies,
#             'use_references': self.use_references,
#             'use_legacy_xml': self.use_legacy_xml,
#             'include_private': self.include_private,
#             'class_def_mapper': self.class_def_mapper
#         }
#  
#         if self.buffer is not None:
#             kwargs['buffer'] = self.buffer
# 
#         return EncoderContext(**kwargs);
# 
#     def encode(self, val, amf3=None):
#         """Encode a value to AMF."""
#         return encode(val, self._getContext(amf3))
# 
#     def encode_packet(self, val, amf3=None):
#         """Encode an AMF packet."""
#         return encode_packet(val, self._getContext(amf3))


# Path: tests/amf0_encoder_test.py
import unittest
import amfast.encode as encode
import amfast.class_def as class_def
        import datetime
        import xml.dom.minidom
from amfast.context import EncoderContext
from amfast.encoder import Encoder
        from amfast.class_def.as_types import AsProxy
        from amfast.class_def.as_types import AsNoProxy
        from amfast.class_def.as_types import AsProxy
        from amfast.class_def.as_types import AsProxy
        from amfast.class_def.as_types import AsNoProxy

            self.assertEquals(encoding, encode.encode(string))

    def testLongString(self):
        decoded = 's' * 65537
        encoded = '\x0C\x00\x01\x00\x01' + decoded

        self.assertEquals('\x0C\x00\x01\x00\x01', encode.encode(decoded)[0:5])
        self.assertEquals(65537 + 5, len(encode.encode(decoded)))

    def testNull(self):
        self.assertEquals('\x05', encode.encode(None))

    def testTuple(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

        self.assertEquals(encoded, encode.encode(decoded))

    def testList(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

        self.assertEquals(encoded, encode.encode(decoded))


    def testCollection(self):