def testDecodeTypes(self): dec_mapper = class_def.ClassDefMapper() dec_mapper.mapClass(class_def.DynamicClassDef(self.TestObject, 'test_complex.test', static_attrs=(), decode_types={ '_float': float, '_int': int, '_str': str})) dec_mapper.mapClass(class_def.DynamicClassDef(self.TestSubObject, 'test_complex.sub', ())) complex = self.buildComplex() enc_context = EncoderContext(class_def_mapper=self.class_mapper, amf3=True, include_private=True) encoded = encode(complex, enc_context) decoded = decode(DecoderContext(encoded, class_def_mapper=dec_mapper, amf3=True)) self.assertEquals('float', decoded[0]._float.__class__.__name__) self.assertEquals('int', decoded[0]._int.__class__.__name__) self.assertEquals('str', decoded[0]._str.__class__.__name__)
def testStaticDynamicObj(self): self.class_mapper.mapClass( class_def.DynamicClassDef(self.Spam, 'alias.spam', ('spam', ))) test = self.Spam() test.ham = 'foo' encoded = '\x0A\x1B\x15alias.spam' # obj header encoded += '\x09spam' # static attr definition encoded += '\x06\x09eggs' # static attrs encoded += '\x07ham\x06\x07foo\x01' #dynamic attrs result = decode.decode( DecoderContext(encoded, class_def_mapper=self.class_mapper, amf3=True)) self.assertEquals('eggs', result.spam) self.assertEquals('foo', result.ham) result = decode.decode( DecoderContext(StringIO(encoded), class_def_mapper=self.class_mapper, amf3=True)) self.assertEquals('eggs', result.spam) self.assertEquals('foo', result.ham) self.class_mapper.unmapClass(self.Spam)
def setUp(self): self.class_mapper = class_def.ClassDefMapper() self.class_mapper.mapClass( class_def.DynamicClassDef(self.TestObject, 'test_complex.test', (), amf3=False)) self.class_mapper.mapClass( class_def.DynamicClassDef(self.TestSubObject, 'test_complex.sub', (), amf3=False)) self.class_mapper.mapClass( class_def.ClassDef(self.TestStaticObject, 'test_complex.static', ('name', 'score', 'rank'), amf3=False)) if use_pyamf is True: pyamf.register_class(self.TestObject, 'test_complex.test') pyamf.register_class(self.TestSubObject, 'test_complex.sub') pyamf.register_class(self.TestStaticObject, 'test_complex.static')
def testDynamicObj(self): self.class_mapper.mapClass( class_def.DynamicClassDef(self.Spam, 'alias.spam', ())) encoded = '\x10\x00\x0Aalias.spam' encoded += '\x00\x04spam\x02\x00\x04eggs\x00\x00\x09' # dynamic attrs result = decode.decode( DecoderContext(encoded, class_def_mapper=self.class_mapper)) self.class_mapper.unmapClass(self.Spam) self.assertEquals('eggs', result.spam)
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)
def testDynamicObj(self): self.class_mapper.mapClass(class_def.DynamicClassDef(self.Spam, alias='alias.spam', static_attrs=(), 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)
def setUp(self): self.class_mapper = class_def.ClassDefMapper() self.class_mapper.mapClass( class_def.DynamicClassDef( builder.SomeClass, builder.aliases[builder.SomeClass], (), # static attrs amf3=False)) self.class_mapper.mapClass( class_def.ClassDef(builder.SomeStaticClass, builder.aliases[builder.SomeStaticClass], ('name', 'score', 'rank'), amf3=False))
def testStaticDynamicObj(self): self.class_mapper.mapClass( class_def.DynamicClassDef(self.Spam, 'alias.spam', ('spam', ))) test = self.Spam() test.ham = 'foo' result = '\x0A\x1B\x15alias.spam' # obj header result += '\x09spam' # static attr definition result += '\x06\x09eggs' # static attrs result += '\x07ham\x06\x07foo\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)
def testDynamicObj(self): self.class_mapper.mapClass( class_def.DynamicClassDef(self.Spam, 'alias.spam', ())) encoded = '\x0A\x0B\x15alias.spam' encoded += '\x09spam\x06\x09eggs\x01' # dynamic attrs result = decode.decode( DecoderContext(encoded, class_def_mapper=self.class_mapper, amf3=True)) self.assertEquals('eggs', result.spam) result = decode.decode( DecoderContext(StringIO(encoded), class_def_mapper=self.class_mapper, amf3=True)) self.assertEquals('eggs', result.spam) self.class_mapper.unmapClass(self.Spam)
def setUp(self): self.class_mapper = class_def.ClassDefMapper() self.class_mapper.mapClass(class_def.DynamicClassDef(self.TestObject, 'test_complex.test', static_attrs=())) self.class_mapper.mapClass(class_def.DynamicClassDef(self.TestSubObject, 'test_complex.sub', ()))