当前位置: 首页>>代码示例>>Python>>正文


Python ClassAlias.getEncodableAttributes方法代码示例

本文整理汇总了Python中pyamf.ClassAlias.getEncodableAttributes方法的典型用法代码示例。如果您正苦于以下问题:Python ClassAlias.getEncodableAttributes方法的具体用法?Python ClassAlias.getEncodableAttributes怎么用?Python ClassAlias.getEncodableAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyamf.ClassAlias的用法示例。


在下文中一共展示了ClassAlias.getEncodableAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GetEncodableAttributesTestCase

# 需要导入模块: from pyamf import ClassAlias [as 别名]
# 或者: from pyamf.ClassAlias import getEncodableAttributes [as 别名]
class GetEncodableAttributesTestCase(unittest.TestCase):
    """
    Tests for L{ClassAlias.getEncodableAttributes}
    """

    def setUp(self):
        self.alias = ClassAlias(Spam, 'foo', defer=True)
        self.obj = Spam()

    def test_empty(self):
        attrs = self.alias.getEncodableAttributes(self.obj)

        self.assertEqual(attrs, {})

    def test_static(self):
        self.alias.static_attrs = ['foo', 'bar']
        self.alias.compile()

        self.obj.foo = 'bar'
        # leave self.obj.bar
        self.assertFalse(hasattr(self.obj, 'bar'))

        attrs = self.alias.getEncodableAttributes(self.obj)

        self.assertEqual(attrs, {'foo': 'bar', 'bar': pyamf.Undefined})

    def test_not_dynamic(self):
        self.alias.compile()
        self.alias.dynamic = False

        self.assertEqual(self.alias.getEncodableAttributes(self.obj), {})

    def test_dynamic(self):
        self.alias.compile()

        self.assertEqual(self.alias.encodable_properties, None)
        self.obj.foo = 'bar'
        self.obj.bar = 'foo'

        attrs = self.alias.getEncodableAttributes(self.obj)
        self.assertEqual(attrs, {'foo': 'bar', 'bar': 'foo'})

    def test_proxy(self):
        from pyamf import flex

        c = pyamf.get_encoder(pyamf.AMF3)

        self.alias.proxy_attrs = ('foo', 'bar')
        self.alias.compile()

        self.assertEqual(self.alias.proxy_attrs, ['bar', 'foo'])

        self.obj.foo = ['bar', 'baz']
        self.obj.bar = {'foo': 'gak'}

        attrs = self.alias.getEncodableAttributes(self.obj, c)

        k = attrs.keys()

        k.sort()

        self.assertEqual(k, ['bar', 'foo'])

        self.assertTrue(isinstance(attrs['foo'], flex.ArrayCollection))
        self.assertEqual(attrs['foo'], ['bar', 'baz'])

        self.assertTrue(isinstance(attrs['bar'], flex.ObjectProxy))
        self.assertEqual(attrs['bar']._amf_object, {'foo': 'gak'})

    def test_synonym(self):
        self.alias.synonym_attrs = {'foo': 'bar'}
        self.alias.compile()

        self.assertFalse(self.alias.shortcut_encode)
        self.assertFalse(self.alias.shortcut_decode)

        self.obj.foo = 'bar'
        self.obj.spam = 'eggs'

        ret = self.alias.getEncodableAttributes(self.obj)

        self.assertEquals(ret, {'bar': 'bar', 'spam': 'eggs'})
开发者ID:notnola,项目名称:pinychat,代码行数:84,代码来源:test_alias.py

示例2: GetEncodableAttributesTestCase

# 需要导入模块: from pyamf import ClassAlias [as 别名]
# 或者: from pyamf.ClassAlias import getEncodableAttributes [as 别名]
class GetEncodableAttributesTestCase(unittest.TestCase):
    """
    Tests for L{ClassAlias.getEncodableAttributes}
    """

    def setUp(self):
        self.alias = ClassAlias(Spam, 'foo', defer=True)
        self.obj = Spam()

    def test_empty(self):
        sa, da = self.alias.getEncodableAttributes(self.obj)

        self.assertEquals(sa, da, None)

    def test_static(self):
        self.alias.static_attrs = ['foo', 'bar']
        self.alias.compile()

        self.obj.foo = 'bar'
        # leave self.obj.bar
        self.assertFalse(hasattr(self.obj, 'bar'))

        sa, da = self.alias.getEncodableAttributes(self.obj)

        self.assertEquals(sa, {'foo': 'bar', 'bar': pyamf.Undefined})
        self.assertEquals(da, None)

    def test_not_dynamic(self):
        self.alias.compile()
        self.alias.dynamic = False

        self.assertEquals(self.alias.getEncodableAttributes(self.obj), (None, None))

    def test_dynamic(self):
        self.alias.compile()

        self.assertEquals(self.alias.encodable_properties, None)
        self.obj.foo = 'bar'
        self.obj.bar = 'foo'

        sa, da = self.alias.getEncodableAttributes(self.obj)
        self.assertEquals(sa, None)
        self.assertEquals(da, {'foo': 'bar', 'bar': 'foo'})

    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'])

        self.obj.foo = ['bar', 'baz']
        self.obj.bar = {'foo': 'gak'}

        sa, da = self.alias.getEncodableAttributes(self.obj)
        self.assertEquals(sa, None)
        self.assertEquals(da.keys(), ['foo', 'bar'])

        self.assertTrue(isinstance(da['foo'], flex.ArrayCollection))
        self.assertEquals(da['foo'], ['bar', 'baz'])

        self.assertTrue(isinstance(da['bar'], flex.ObjectProxy))
        self.assertEquals(da['bar']._amf_object, {'foo': 'gak'})
开发者ID:danielor,项目名称:TowerSaint,代码行数:67,代码来源:test_alias.py


注:本文中的pyamf.ClassAlias.getEncodableAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。