コード例 #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)
コード例 #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)
コード例 #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'])
コード例 #4
0
ファイル: speed_test.py プロジェクト: rwarren/amfast
    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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #25
0
ファイル: amf0_encoder_test.py プロジェクト: rwarren/amfast
    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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #31
0
ファイル: context_test.py プロジェクト: NGFieldScope/amfast
 def testCopyEncoderContext(self):
     con = EncoderContext(amf3=True)
     con_2 = con.copy()
     self._testEncoderContext(con_2)