コード例 #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 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)
コード例 #3
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)
コード例 #4
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'])
コード例 #5
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)
コード例 #6
0
    def testLongStringAmf0(self):
        decoded = 's' * 65537
        encoded = encode(decoded)
        result = decode(encoded)

        self.assertEquals(len(decoded), len(result))
        for char in result:
            self.assertEquals('s', char)
コード例 #7
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)
コード例 #8
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)
コード例 #9
0
ファイル: amf0_encoder_test.py プロジェクト: rwarren/amfast
    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))
コード例 #10
0
ファイル: amf0_encoder_test.py プロジェクト: rwarren/amfast
    def testString(self):
        tests = {
            '': '\x02\x00\x00',
            'hello': '\x02\x00\x05hello'
        }

        for string, encoding in tests.iteritems():
            self.assertEquals(encoding, encode.encode(string))
コード例 #11
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)
コード例 #12
0
ファイル: amf0_encoder_test.py プロジェクト: rwarren/amfast
    def testAnonymousObj(self):
        decoded = self.Spam()
        decoded.spam = 'eggs'

        encoded = '\x03' #header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator
        self.assertEquals(encoded, encode.encode(decoded))
コード例 #13
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)
コード例 #14
0
    def testLongListAmf0(self):
        decoded = [None] * 65537
        encoded = encode(decoded)
        result = decode(encoded)

        self.assertEquals(len(decoded), len(result))
        for val in result:
            self.assertEquals(None, val)
コード例 #15
0
ファイル: amf0_encoder_test.py プロジェクト: rwarren/amfast
    def testNoCollection(self):
        from amfast.class_def.as_types import AsNoProxy
        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(AsNoProxy(decoded)))
コード例 #16
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)
コード例 #17
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)
コード例 #18
0
    def testString(self):
        tests = {
            '': '\x06\x01',
            'hello': '\x06\x0bhello'
        }

        for string, encoding in tests.iteritems():
            buf = encode.encode(string, EncoderContext(amf3=True))
            self.assertEquals(encoding, buf)
コード例 #19
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)
コード例 #20
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)
コード例 #21
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)
コード例 #22
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)
コード例 #23
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)
コード例 #24
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)
コード例 #25
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)
コード例 #26
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)
コード例 #27
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)
コード例 #28
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)
コード例 #29
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)
コード例 #30
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)
コード例 #31
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)
コード例 #32
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)
コード例 #33
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)
コード例 #34
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)
コード例 #35
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)
コード例 #36
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)
コード例 #37
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)
コード例 #38
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)
コード例 #39
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);
コード例 #40
0
ファイル: amf0_encoder_test.py プロジェクト: rwarren/amfast
    def testXml(self):
        import xml.dom.minidom
        
        xml_str = '<?xml version="1.0" ?><test>\n            <test_me>tester</test_me>\n           </test>' # encoded XML
        decoded = xml.dom.minidom.parseString(xml_str)

        encoded = '\x0F' # XML header
        encoded += '\x00\x00\x00\x55' # String header
        encoded += xml_str

        self.assertEquals(encoded, encode.encode(decoded))
コード例 #41
0
    def testDictForcedObjectProxy(self):
        from amfast.class_def.as_types import AsProxy

        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(AsProxy({'spam': 'eggs'}), EncoderContext(use_proxies=False, amf3=True))
        self.assertEquals(result, buf)
コード例 #42
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)
コード例 #43
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)
コード例 #44
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)
コード例 #45
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)
コード例 #46
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)
コード例 #47
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)
コード例 #48
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)
コード例 #49
0
ファイル: amf0_encoder_test.py プロジェクト: rwarren/amfast
    def testNumber(self):
        tests = {
            0: '\x00\x00\x00\x00\x00\x00\x00\x00\x00',
            0.2: '\x00\x3f\xc9\x99\x99\x99\x99\x99\x9a',
            1: '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00',
            42: '\x00\x40\x45\x00\x00\x00\x00\x00\x00',
            -123: '\x00\xc0\x5e\xc0\x00\x00\x00\x00\x00',
            1.23456789: '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b'
        }

        for number, encoding in tests.iteritems():
            self.assertEquals(encoding, encode.encode(number))
コード例 #50
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)