def test_repr(self): x = flex.ObjectProxy() self.assertEqual(repr(x), '<flex.messaging.io.ObjectProxy {}>') x = flex.ObjectProxy(u'ƒøø') self.assertEqual( repr(x), "<flex.messaging.io.ObjectProxy u'\\u0192\\xf8\\xf8'>")
def test_get_attrs(self): x = flex.ObjectProxy() self.assertEqual(x._amf_object, pyamf.ASObject()) x._amf_object = None self.assertEqual(x._amf_object, None)
def test_encode(self): stream = util.BufferedByteStream() encoder = amf3.Encoder(stream) x = flex.ObjectProxy(pyamf.MixedArray(a='spam', b=5)) encoder.writeElement(x) self.assertTrue(check_buffer(stream.getvalue(), ( '\n\x07;flex.messaging.io.ObjectProxy\t\x01', ('\x03a\x06\x09spam', '\x03b\x04\x05'), '\x01')))
def test_encode(self): stream = util.BufferedByteStream() encoder = amf3.Encoder(stream) x = flex.ObjectProxy(pyamf.MixedArray(a='spam', b=5)) encoder.writeElement(x) self.assertEquals( stream.getvalue(), '\x0a\x07;flex.messaging.io.ObjectProxy\x09\x01\x03a\x06\x09spam' '\x03b\x04\x05\x01')
def test_proxy(self): from pyamf import flex self.alias.amf3 = True self.alias.proxy_attrs = ('foo', 'bar') self.alias.compile() self.assertEquals(self.alias.proxy_attrs, ['bar', 'foo']) attrs = { 'foo': flex.ArrayCollection(['bar', 'baz']), 'bar': flex.ObjectProxy({'foo': 'gak'}) } ret = self.alias.getDecodableAttributes(self.obj, attrs) self.assertEquals(ret, {'foo': ['bar', 'baz'], 'bar': {'foo': 'gak'}})
def getProxiedAttribute(self, attr, obj): """ Returns the proxied equivalent for C{obj}. @param attr: The attribute of the proxy request. Useful for class introspection. @type attr: C{str} @param obj: The object to proxy. @return: The proxied object or the original object if it cannot be proxied. """ # the default is to just check basic types from pyamf import flex if type(obj) is list: return flex.ArrayCollection(obj) elif type(obj) is dict: return flex.ObjectProxy(obj) return obj
def test_encode(self): x = flex.ObjectProxy(pyamf.MixedArray(a='spam', b=5)) self.assertEncoded(x, '\n\x07;flex.messaging.io.ObjectProxy\n\x0b\x01', ('\x03a\x06\tspam', '\x03b\x04\x05', '\x01'))