Ejemplo n.º 1
0
    def testDate(self):
        import datetime

        test = datetime.datetime(2005, 3, 18, 1, 58, 31)
        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals('\x08\x01Bp+6!\x15\x80\x00', buf)

        test = datetime.date(2003, 12, 1)
        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals('\x08\x01Bo%\xe2\xb2\x80\x00\x00', buf)
Ejemplo n.º 2
0
    def encode(self, obj, amf3):
        context = EncoderContext(use_collections=True,
                                 amf3=amf3,
                                 use_proxies=False,
                                 class_def_mapper=self.class_mapper)

        return encode.encode(obj, context)
Ejemplo n.º 3
0
 def testComplexDict(self):
     complex = {'element': 'ignore', 'objects': self.buildComplex()}
     enc_context = EncoderContext(use_collections=False, use_proxies=False,
         class_def_mapper=self.class_mapper, amf3=True)
     encoded = encode(complex, enc_context)
     decoded = decode(DecoderContext(encoded, class_def_mapper=self.class_mapper, amf3=True))
     self.resultTest(decoded['objects'])
Ejemplo n.º 4
0
    def amfastEncode(self, obj, amf3=False, use_proxies=False):
        enc_context = EncoderContext(use_collections=use_proxies,
                                     use_proxies=use_proxies,
                                     class_def_mapper=self.class_mapper,
                                     amf3=amf3)

        return encode.encode(obj, enc_context)
Ejemplo n.º 5
0
    def testDict(self):
        result = '\x0A\x0B\x01'  # Object header
        result += '\x09spam'  # key
        result += '\x06\x09eggs'  #value
        result += '\x01'  # empty string terminator

        buf = encode.encode({'spam': 'eggs'}, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 6
0
    def testLongStringAmf3(self):
        decoded = 's' * 65537
	encoded = encode(decoded, EncoderContext(amf3=True))
        result = decode(DecoderContext(encoded, amf3=True))

        self.assertEquals(len(decoded), len(result))
        for char in result:
            self.assertEquals('s', char)
Ejemplo n.º 7
0
    def testLongListAmf3(self):
        decoded = [None] * 65537
        encoded = encode(decoded, EncoderContext(amf3=True))
        result = decode(DecoderContext(encoded, amf3=True))

        self.assertEquals(len(decoded), len(result))
        for val in result:
            self.assertEquals(None, val)
Ejemplo n.º 8
0
    def testFloat(self):
        tests = {
            0.1: '\x05\x3f\xb9\x99\x99\x99\x99\x99\x9a',
            0.123456789: '\x05\x3f\xbf\x9a\xdd\x37\x39\x63\x5f'
        }

        for number, encoding in tests.iteritems():
            buf = encode.encode(number, EncoderContext(amf3=True))
            self.assertEquals(encoding, buf)
Ejemplo n.º 9
0
    def testTupleRefs(self):
        test_tuple = (0, 1, 2, 3)
        test = [test_tuple, test_tuple]

        result = '\x09\x05\x01'  # array header
        result += '\x09\x09\x01\x04\x00\x04\x01\x04\x02\x04\x03'  # array element 1 (test_tuple encoded)
        result += '\x09\x02'  # array element 2 (reference to test_tuple)

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 10
0
    def testListRefs(self):
        test_list = [0, 1, 2, 3]
        test = (test_list, test_list)

        result = '\x09\x05\x01'  # array header
        result += '\x09\x09\x01\x04\x00\x04\x01\x04\x02\x04\x03'  # array element 1 (test_list encoded)
        result += '\x09\x02'  # array element 2 (reference to test_list)

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 11
0
    def testDictAsObjectProxy(self):
        result = '\x0A\x07\x3Bflex.messaging.io.ObjectProxy'  # Object header
        result += '\x0A\x0B\x01'  # Object header
        result += '\x09spam'  # key
        result += '\x06\x09eggs'  #value
        result += '\x01'  # empty string terminator

        buf = encode.encode({'spam': 'eggs'},
                            EncoderContext(use_proxies=True, amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 12
0
    def testUnicode(self):
        tests = {
            u'': '\x06\x01',
            u'hello': '\x06\x0bhello',
            u'ᚠᛇᚻ': '\x06\x13\xe1\x9a\xa0\xe1\x9b\x87\xe1\x9a\xbb'
        }

        for string, encoding in tests.iteritems():
            buf = encode.encode(string, EncoderContext(amf3=True))
            self.assertEquals(encoding, buf)
Ejemplo n.º 13
0
    def testAnonObjRef(self):
        test_obj = self.Spam()
        test = (test_obj, test_obj)

        result = '\x09\x05\x01'  #array header
        result += '\x0A\x0B\x01\x09spam\x06\x09eggs\x01'  #array element 1 (test_obj encoded)
        result += '\x0A\x02'  # array element 2 (reference to test_obj)

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 14
0
    def testObjectProxyRef(self):
        test_dict = {'spam': 'eggs'}
        test = (test_dict, test_dict)

        result = '\x09\x05\x01'  #array header
        result += '\x0A\x07\x3Bflex.messaging.io.ObjectProxy\x0A\x0B\x01\x09spam\x06\x09eggs\x01'  #array element 1 (test_dict encoded)
        result += '\x0A\x02'  # array element 2 (reference to test_dict)

        buf = encode.encode(test, EncoderContext(use_proxies=True, amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 15
0
    def testAnonObj(self):
        test = self.Spam()

        result = '\x0A\x0B\x01'  # Object header
        result += '\x09spam'  # key
        result += '\x06\x09eggs'  #value
        result += '\x01'  # empty string terminator

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 16
0
    def testLong(self):
        tests = {
            0x10000000: '\x05\x41\xb0\x00\x00\x00\x00\x00\x00',
            -0x10000001: '\x05\xc1\xb0\x00\x00\x01\x00\x00\x00',
            -0x10000000: '\x04\xc0\x80\x80\x00'
        }

        for number, encoding in tests.iteritems():
            buf = encode.encode(number, EncoderContext(amf3=True))
            self.assertEquals(encoding, buf)
Ejemplo n.º 17
0
    def testList(self):
        test = [0, 1, 2, 3]

        result = '\x09\x09\x01'  #array header
        result += '\x04\x00'  #array element 1
        result += '\x04\x01'  #array element 2
        result += '\x04\x02'  #array element 3
        result += '\x04\x03'  #array element

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 18
0
    def testArrayCollectionRef(self):
        test_tuple = (0, 1, 2, 3)
        test = [test_tuple, test_tuple]

        result = '\x0A\x07\x43flex.messaging.io.ArrayCollection\x09\x05\x01'  # array header
        result += '\x0A\x01\x09\x09\x01\x04\x00\x04\x01\x04\x02\x04\x03'  # array element 1 (test_tuple encoded)
        result += '\x0A\x04'  # array element 2 (reference to test_tuple)

        buf = encode.encode(test,
                            EncoderContext(use_collections=True, amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 19
0
    def testDictForceNoProxy(self):
        from amfast.class_def.as_types import AsNoProxy

        result = '\x0A\x0B\x01'  # Object header
        result += '\x09spam'  # key
        result += '\x06\x09eggs'  #value
        result += '\x01'  # empty string terminator

        buf = encode.encode(AsNoProxy({'spam': 'eggs'}),
                            EncoderContext(amf3=True, use_proxies=True))
        self.assertEquals(result, buf)
Ejemplo n.º 20
0
    def testDateReferences(self):
        import datetime

        test_date = datetime.datetime(2005, 3, 18, 1, 58, 31)
        test = [test_date, test_date]

        result = '\x09\x05\x01'  #array header
        result += '\x08\x01Bp+6!\x15\x80\x00'  #array element 1 (test_date encoded)
        result += '\x08\x02'  # array element 2 (reference to test_date)

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 21
0
    def testUnicodeRefs(self):
        hello = u'hello'
        test = [hello, hello, '', hello]

        result = '\x09\x09\x01'  # array header
        result += '\x06\x0bhello'  # array element 1 (hello encoded)
        result += '\x06\x00'  #array element 2 (reference to hello)
        result += '\x06\x01'  #array element 3 (empty string)
        result += '\x06\x00'  #array element 4 (reference to hello)

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 22
0
    def testDictRef(self):
        test_dict = {
            'spam': 'eggs'
        }
        test = (test_dict, test_dict)

        result = '\x09\x05\x01'  #array header
        result += '\x0A\x0B\x01\x09spam\x06\x09eggs\x01'  #array element 1 (test_dict encoded)
        result += '\x0A\x02'  # array element 2 (reference to test_dict)

        buf = encode.encode(test, EncoderContext(amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 23
0
    def testTupleForceNoProxy(self):
        from amfast.class_def.as_types import AsNoProxy
        test = (0, 1, 2, 3)

        result = '\x09\x09\x01'  #array header
        result += '\x04\x00'  #array element 1
        result += '\x04\x01'  #array element 2
        result += '\x04\x02'  #array element 3
        result += '\x04\x03'  #array element 4

        buf = encode.encode(AsNoProxy(test),
                            EncoderContext(amf3=True, use_collections=True))
        self.assertEquals(result, buf)
Ejemplo n.º 24
0
    def testDynamicObj(self):
        self.class_mapper.mapClass(
            class_def.DynamicClassDef(self.Spam, 'alias.spam', ()))
        test = self.Spam()

        result = '\x0A\x0B\x15alias.spam'
        result += '\x09spam\x06\x09eggs\x01'  # dynamic attrs

        buf = encode.encode(test, EncoderContext(\
            class_def_mapper=self.class_mapper, amf3=True))
        self.class_mapper.unmapClass(self.Spam)

        self.assertEquals(result, buf)
Ejemplo n.º 25
0
    def testStaticObj(self):
        self.class_mapper.mapClass(class_def.ClassDef(self.Spam, alias='alias.spam',
            static_attrs=('spam', ), amf3=False))

        decoded = self.Spam()
        decoded.spam = 'eggs'

        encoded = '\x10\x00\x0Aalias.spam'
        encoded += '\x00\x04spam\x02\x00\x04eggs\x00\x00\x09' # dynamic attrs

        context = EncoderContext(class_def_mapper=self.class_mapper)
        self.assertEquals(encoded, encode.encode(decoded, context))
        self.class_mapper.unmapClass(self.Spam)
Ejemplo n.º 26
0
    def testListAsCollection(self):
        test = [0, 1, 2, 3]

        result = '\x0A\x07\x43flex.messaging.io.ArrayCollection'  # Object header
        result += '\x09\x09\x01'  #array header
        result += '\x04\x00'  #array element 1
        result += '\x04\x01'  #array element 2
        result += '\x04\x02'  #array element 3
        result += '\x04\x03'  #array element 4

        buf = encode.encode(test,
                            EncoderContext(use_collections=True, amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 27
0
    def testRefsOff(self):
        hello = u'hello'
        test = [hello, hello, '', hello]

        result = '\x09\x09\x01'  # array header
        result += '\x06\x0bhello'  # array element 1 (hello encoded)
        result += '\x06\x0bhello'  #array element 2 (hello encoded)
        result += '\x06\x01'  #array element 3 (empty string)
        result += '\x06\x0bhello'  #array element 4 (hello encoded)

        buf = encode.encode(test,
                            EncoderContext(use_references=False, amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 28
0
    def testStaticObj(self):
        self.class_mapper.mapClass(
            class_def.ClassDef(self.Spam, 'alias.spam', ('spam', )))
        test = self.Spam()

        result = '\x0A\x13\x15alias.spam'
        result += '\x09spam'  # static attr definition
        result += '\x06\x09eggs'  # static attrs

        buf = encode.encode(test, EncoderContext(\
            class_def_mapper=self.class_mapper, amf3=True))
        self.class_mapper.unmapClass(self.Spam)

        self.assertEquals(result, buf)
Ejemplo n.º 29
0
    def testTupleAsForcedCollection(self):
        from amfast.class_def.as_types import AsProxy
        test = (0, 1, 2, 3)

        result = '\x0A\x07\x43flex.messaging.io.ArrayCollection'  # Object header
        result += '\x09\x09\x01'  #array header
        result += '\x04\x00'  #array element 1
        result += '\x04\x01'  #array element 2
        result += '\x04\x02'  #array element 3
        result += '\x04\x03'  #array element 4

        buf = encode.encode(AsProxy(test),
                            EncoderContext(use_collections=False, amf3=True))
        self.assertEquals(result, buf)
Ejemplo n.º 30
0
    def testTypedObjectRef(self):
        self.class_mapper.mapClass(
            class_def.ClassDef(self.Spam, 'alias.spam', ('spam', )))
        test_obj = self.Spam()
        test = (test_obj, test_obj)

        result = '\x09\x05\x01'  #array header
        result += '\x0A\x13\x15alias.spam\x09spam\x06\x09eggs'  # test_obj_encoded
        result += '\x0A\x02'  # array element 2 (reference to test_obj)

        buf = encode.encode(test, EncoderContext(\
            class_def_mapper=self.class_mapper, amf3=True))
        self.class_mapper.unmapClass(self.Spam)

        self.assertEquals(result, buf)
Ejemplo n.º 31
0
 def testCopyEncoderContext(self):
     con = EncoderContext(amf3=True)
     con_2 = con.copy()
     self._testEncoderContext(con_2)