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


Python pyamf.add_type函数代码示例

本文整理汇总了Python中pyamf.add_type函数的典型用法代码示例。如果您正苦于以下问题:Python add_type函数的具体用法?Python add_type怎么用?Python add_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_custom_type

    def test_custom_type(self):
        def write_as_list(list_interface_obj, encoder):
            list_interface_obj.ran = True
            self.assertEqual(id(encoder), id(self.encoder))

            return list(list_interface_obj)

        class ListWrapper(object):
            ran = False

            def __iter__(self):
                return iter([1, 2, 3])

        pyamf.add_type(ListWrapper, write_as_list)
        x = ListWrapper()

        self.encoder.writeElement(x)
        self.assertEqual(x.ran, True)

        self.assertEqual(
            self.buf.getvalue(),
            "\n\x00\x00\x00\x03\x00?\xf0"
            "\x00\x00\x00\x00\x00\x00\[email protected]\x00\x00\x00\x00\x00\x00\x00\[email protected]"
            "\x08\x00\x00\x00\x00\x00\x00",
        )
开发者ID:boggob,项目名称:bogs-xbmc-addons,代码行数:25,代码来源:test_amf0.py

示例2: when_imported

def when_imported(mod):
    """
    This function is called immediately after mymodule has been imported.
    It configures PyAMF to encode a list when an instance of mymodule.CustomClass
    is encountered.
    """
    import pyamf

    pyamf.add_type(mod.CustomClass, lambda obj: list(obj))
开发者ID:84322146,项目名称:pyamf,代码行数:9,代码来源:myadapter.py

示例3: setUp

    def setUp(self):
        CollectionsTestCase.setUp(self)

        if not hasattr(collections, 'namedtuple'):
            self.skipTest("'collections.namedtuple' not available")

        user_vo = collections.namedtuple('user_vo', 'id name age')

        pyamf.add_type(user_vo, lambda obj, encoder: obj._asdict())

        self.obj = user_vo(1, 'Hadrien', 30)
        self.orig = self.obj._asdict()
开发者ID:84322146,项目名称:pyamf,代码行数:12,代码来源:test_collections.py

示例4: test_add_class

    def test_add_class(self):
        class A:
            pass

        class B(object):
            pass

        pyamf.add_type(A)
        self.assertTrue(A in pyamf.TYPE_MAP)

        pyamf.add_type(B)
        self.assertTrue(B in pyamf.TYPE_MAP)
开发者ID:0xmilk,项目名称:appscale,代码行数:12,代码来源:test_basic.py

示例5: test_add_multiple

    def test_add_multiple(self):
        td = pyamf.add_type((chr,))

        class A(object):
            pass

        class B(object):
            pass

        class C(object):
            pass

        td = pyamf.add_type([A, B, C])
开发者ID:cardmagic,项目名称:PyAMF,代码行数:13,代码来源:test_basic.py

示例6: test_add_multiple

    def test_add_multiple(self):
        td = pyamf.add_type((chr,))

        class A(object):
            pass

        class B(object):
            pass

        class C(object):
            pass

        td = pyamf.add_type([A, B, C])
        self.assertEqual(td, pyamf.get_type([A, B, C]))
开发者ID:0xmilk,项目名称:appscale,代码行数:14,代码来源:test_basic.py

示例7: test_remove

    def test_remove(self):
        self.assertRaises(KeyError, pyamf.remove_type, chr)
        td = pyamf.add_type((chr,))

        self.assertRaises(KeyError, pyamf.remove_type, chr)
        td2 = pyamf.remove_type((chr,))

        self.assertEqual(td, td2)
开发者ID:0xmilk,项目名称:appscale,代码行数:8,代码来源:test_basic.py

示例8: test_custom_type

    def test_custom_type(self):
        def write_as_list(list_interface_obj, encoder):
            list_interface_obj.ran = True
            self.assertEqual(id(self.encoder), id(encoder))

            return list(list_interface_obj)

        class ListWrapper(object):
            ran = False

            def __iter__(self):
                return iter([1, 2, 3])

        pyamf.add_type(ListWrapper, write_as_list)
        x = ListWrapper()

        self.assertEncoded(x, '\t\x07\x01\x04\x01\x04\x02\x04\x03')
        self.assertTrue(x.ran)
开发者ID:MyaThandarKyaw,项目名称:pyamf,代码行数:18,代码来源:test_amf3.py

示例9: test_get_type

    def test_get_type(self):
        self.assertRaises(KeyError, pyamf.get_type, chr)
        td = pyamf.add_type((chr,))
        self.assertRaises(KeyError, pyamf.get_type, chr)

        td2 = pyamf.get_type((chr,))
        self.assertEqual(td, td2)

        td2 = pyamf.get_type([chr,])
        self.assertEqual(td, td2)
开发者ID:0xmilk,项目名称:appscale,代码行数:10,代码来源:test_basic.py

示例10: test_custom_type

    def test_custom_type(self):
        def write_as_list(list_interface_obj):
            list_interface_obj.ran = True

            return list(list_interface_obj)

        class ListWrapper(object):
            ran = False

            def __iter__(self):
                return iter([1, 2, 3])

        pyamf.add_type(ListWrapper, write_as_list)
        x = ListWrapper()

        self.encoder.writeElement(x)
        self.assertEquals(x.ran, True)

        self.assertEquals(self.buf.getvalue(), '\t\x07\x01\x04\x01\x04\x02\x04\x03')
开发者ID:wayne-abarquez,项目名称:vizzuality,代码行数:19,代码来源:test_amf3.py

示例11: Copyright

# Copyright (c) 2007-2008 The PyAMF Project.
# See LICENSE for details.

"""
Django adapter module.

Sets up basic type mapping and class mappings for a
Django project.

@see: U{Django Project<http://www.djangoproject.com>}

@author: U{Nick Joyce<mailto:[email protected]>}

@since: 0.1b
"""

import pyamf

try:
    from django.db.models.query import QuerySet
except ImportError:
    QuerySet = None

if QuerySet is not None:
    def _write_queryset(qs):
        return list(qs)

    pyamf.add_type(QuerySet, _write_queryset)
开发者ID:wayne-abarquez,项目名称:vizzuality,代码行数:28,代码来源:_django.py

示例12: Copyright

# Copyright (c) The PyAMF Project.
# See LICENSE for details.

"""
Adapter for the stdlib C{sets} module.

@since: 0.4
"""

import sets

import pyamf
from pyamf.adapters import util


if hasattr(sets, 'ImmutableSet'):
    pyamf.add_type(sets.ImmutableSet, util.to_tuple)

if hasattr(sets, 'Set'):
    pyamf.add_type(sets.Set, util.to_tuple)
开发者ID:notnola,项目名称:pinychat,代码行数:20,代码来源:_sets.py

示例13: test_add_same

 def test_add_same(self):
     pyamf.add_type(chr)
     self.assertRaises(KeyError, pyamf.add_type, chr)
开发者ID:0xmilk,项目名称:appscale,代码行数:3,代码来源:test_basic.py

示例14: install_gae_reference_model_hook

    try:
        referenced_object = gae_objects.getClassKey(kls, s)
    except KeyError:
        gae_objects.addClassKey(kls, s, object)
        self.writeNonGAEObject(object, *args, **kwargs)

        return

    self.writeNonGAEObject(referenced_object, *args, **kwargs)

def install_gae_reference_model_hook(mod):
    """
    Called when L{pyamf.amf0} or L{pyamf.amf3} are imported. Attaches the
    L{writeGAEObject} method to the C{Encoder} class in that module.

    @param mod: The module imported.
    @since: 0.4.1
    """
    if not hasattr(mod.Encoder, 'writeNonGAEObject'):
        mod.Encoder.writeNonGAEObject = mod.Encoder.writeObject
        mod.Encoder.writeObject = writeGAEObject

# initialise the module here: hook into pyamf

pyamf.add_type(db.Query, util.to_list)
pyamf.register_alias_type(DataStoreClassAlias, db.Model, db.Expando)

# hook the L{writeGAEObject} method to the Encoder class on import
imports.whenImported('pyamf.amf0', install_gae_reference_model_hook)
imports.whenImported('pyamf.amf3', install_gae_reference_model_hook)
开发者ID:feisley,项目名称:petetweet,代码行数:30,代码来源:_google_appengine_ext_db.py

示例15: getGAEObjects

    C{object.__class__: {key1: object1, key2: object2, .., keyn: objectn}}. We
    use the datastore key to do the reference checking.

    @since: 0.4.1
    """
    if not obj.is_saved():
        encoder.writeObject(obj)

        return

    context = encoder.context
    kls = obj.__class__
    s = obj.key()

    gae_objects = getGAEObjects(context)

    try:
        referenced_object = gae_objects.getClassKey(kls, s)
    except KeyError:
        referenced_object = obj
        gae_objects.addClassKey(kls, s, obj)

    encoder.writeObject(referenced_object)


# initialise the module here: hook into pyamf

pyamf.register_alias_type(DataStoreClassAlias, db.Model)
pyamf.add_type(db.Query, util.to_list)
pyamf.add_type(db.Model, writeGAEObject)
开发者ID:meemeer,项目名称:kayframework-pyamf,代码行数:30,代码来源:_google_appengine_ext_db.py


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