• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pyamf.add_type函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Copyright

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

"""
Django model adapter module.

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

@see: U{Django Project<http://www.djangoproject.com>}
@author: U{Nick Joyce<mailto:[email protected]>}
@since: 0.1b
"""

from django.db.models import query

import pyamf

def write_queryset(qs):
    return list(qs)

pyamf.add_type(query.QuerySet, write_queryset)
开发者ID:weimingtom,项目名称:o-healer-projects,代码行数:22,代码来源:_django_db_models_query.py


示例17: Copyright

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

"""
SQLAlchemy adapter module.

@see: U{SQLAlchemy homepage (external)<http://www.sqlalchemy.org>}

@since: 0.4
"""

from sqlalchemy.orm import collections

import pyamf
from pyamf.adapters import util


pyamf.add_type(collections.InstrumentedList, util.to_list)
pyamf.add_type(collections.InstrumentedDict, util.to_dict)
pyamf.add_type(collections.InstrumentedSet, util.to_set)
开发者ID:cardmagic,项目名称:PyAMF,代码行数:20,代码来源:_sqlalchemy_orm_collections.py


示例18: test_add_callable

    def test_add_callable(self):
        td = pyamf.add_type(ord)

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


示例19: post_ndb_process

        datetime.time(0, 0, 0)
    )


def post_ndb_process(payload, context):
    """
    """
    stubs = context.get(NDB_STUB_NAME, None)

    if not stubs:
        return payload

    stubs.transform()

    return payload


# small optimisation to compile the ndb.Model base class
if hasattr(ndb.model, '_NotEqualMixin'):
    not_equal_mixin = pyamf.register_class(ndb.model._NotEqualMixin)
    not_equal_mixin.compile()

    del not_equal_mixin

# initialise the module here: hook into pyamf
pyamf.register_alias_type(NDBClassAlias, ndb.Model, ndb.Expando)
pyamf.add_type(ndb.Query, util.to_list)
pyamf.add_type(ndb.Model, encode_ndb_instance)
pyamf.add_post_decode_processor(post_ndb_process)
pyamf.add_type(ndb.Key, encode_ndb_key)
开发者ID:Khan,项目名称:frankenserver,代码行数:30,代码来源:_google_appengine_ext_ndb.py


示例20: Copyright

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

"""
C{django.db.models.fields} adapter module.

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

from django.db.models import fields

import pyamf

def convert_NOT_PROVIDED(x):
    return pyamf.Undefined

pyamf.add_type(lambda x: x == fields.NOT_PROVIDED, convert_NOT_PROVIDED)
开发者ID:fernandoacorreia,项目名称:flex-and-python-test,代码行数:18,代码来源:_django_db_models_fields.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyamf.decode函数代码示例发布时间:2022-05-25
下一篇:
Python warninghelpers.deprecation_warning函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap