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

Python pyamf.get_class_alias函数代码示例

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

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



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

示例1: setUp

    def setUp(self):
        import pyamf

        try:
            pyamf.get_class_alias(status.Status)
        except pyamf.UnknownClassAlias:
            self._old_alias = None
        else:
            raise RuntimeError(
                'Unexpected status.Status class registered in PyAMF')

        self.alias = pyamf.register_class(status.Status)
开发者ID:Arlex,项目名称:rtmpy,代码行数:12,代码来源:test_status.py


示例2: test_get_attrs

    def test_get_attrs(self):
        pyamf.register_class(Spam)
        alias = pyamf.get_class_alias(Spam)

        x = Spam()
        self.assertEquals(alias.getAttrs(x), (None, None))

        pyamf.unregister_class(Spam)

        pyamf.register_class(Spam, attrs=["foo"])
        alias = pyamf.get_class_alias(Spam)

        x = Spam()
        self.assertEquals(alias.getAttrs(x), (["foo"], []))

        pyamf.unregister_class(Spam)

        pyamf.register_class(Spam, metadata=["dynamic"])
        alias = pyamf.get_class_alias(Spam)

        x = Spam()
        self.assertEquals(alias.getAttrs(x), (None, None))

        pyamf.unregister_class(Spam)

        def af(x):
            self.assertEquals(self._obj, x)

            return ["bar"]

        pyamf.register_class(Spam, attr_func=af, metadata=["dynamic"])
        alias = pyamf.get_class_alias(Spam)

        self._obj = Spam()
        self.assertEquals(alias.getAttrs(self._obj), ([], ["bar"]))

        pyamf.unregister_class(Spam)

        def af(x):
            self.assertEquals(self._obj, x)

            return ["bar"]

        pyamf.register_class(Spam, attrs=["foo", "bar"], attr_func=af, metadata=["dynamic"])
        alias = pyamf.get_class_alias(Spam)

        self._obj = Spam()
        self.assertEquals(alias.getAttrs(self._obj), (["foo", "bar"], []))
开发者ID:kruser,项目名称:zualoo,代码行数:48,代码来源:test_basic.py


示例3: test_get_attrs

    def test_get_attrs(self):
        pyamf.register_class(Spam)
        alias = pyamf.get_class_alias(Spam)

        x = Spam()
        self.assertEquals(alias.getAttrs(x), None)

        pyamf.unregister_class(Spam)

        pyamf.register_class(Spam, attrs=['foo'])
        alias = pyamf.get_class_alias(Spam)

        x = Spam()
        self.assertEquals(alias.getAttrs(x), ['foo'])

        pyamf.unregister_class(Spam)

        pyamf.register_class(Spam, metadata=['dynamic'])
        alias = pyamf.get_class_alias(Spam)

        x = Spam()
        self.assertEquals(alias.getAttrs(x), None)

        pyamf.unregister_class(Spam)

        def af(x):
            self.assertEquals(self._obj, x)

            return ['bar']

        pyamf.register_class(Spam, attr_func=af, metadata=['dynamic'])
        alias = pyamf.get_class_alias(Spam)

        self._obj = Spam()
        self.assertEquals(alias.getAttrs(self._obj), ['bar'])

        pyamf.unregister_class(Spam)

        def af(x):
            self.assertEquals(self._obj, x)

            return ['bar']

        pyamf.register_class(Spam, attrs=['foo', 'bar'], attr_func=af, metadata=['dynamic'])
        alias = pyamf.get_class_alias(Spam)

        self._obj = Spam()
        self.assertEquals(alias.getAttrs(self._obj), ['foo', 'bar'])
开发者ID:fernandoacorreia,项目名称:flex-and-python-test,代码行数:48,代码来源:test_basic.py


示例4: getClassAlias

    def getClassAlias(self, klass):
        """
        Gets a class alias based on the supplied C{klass}. If one is not found
        in the global context, one is created locally.

        If you supply a string alias and the class is not registered,
        L{pyamf.UnknownClassAlias} will be raised.

        @param klass: A class object or string alias.
        @return: The L{pyamf.ClassAlias} instance that describes C{klass}
        """
        try:
            return self._class_aliases[klass]
        except KeyError:
            pass

        try:
            alias = self._class_aliases[klass] = pyamf.get_class_alias(klass)
        except pyamf.UnknownClassAlias:
            if isinstance(klass, python.str_types):
                raise

            # no alias has been found yet .. check subclasses
            alias = util.get_class_alias(klass) or pyamf.ClassAlias
            meta = util.get_class_meta(klass)
            alias = alias(klass, defer=True, **meta)

            self._class_aliases[klass] = alias

        return alias
开发者ID:Flumotion,项目名称:pyamf,代码行数:30,代码来源:codec.py


示例5: test_class_alias

    def test_class_alias(self):
        alias_klass = pyamf.get_class_alias(blobstore.BlobInfo)

        self.assertIdentical(
            alias_klass.__class__,
            adapter.BlobInfoClassAlias
        )
开发者ID:LiiiQin,项目名称:test,代码行数:7,代码来源:test_blobstore.py


示例6: test_anonymous

    def test_anonymous(self):
        pyamf.register_class(Spam)

        x = pyamf.get_class_alias(Spam)

        self.assertTrue(isinstance(x, pyamf.ClassAlias))
        self.assertEquals(x.klass, Spam)
        self.assertEquals(x.alias, '%s.%s' % (Spam.__module__, Spam.__name__,))
开发者ID:AbsMate,项目名称:bluecop-xbmc-repo,代码行数:8,代码来源:test_basic.py


示例7: test_user

    def test_user(self):
        from django.contrib.auth import models

        alias = pyamf.get_class_alias(models.User)

        self.assertEqual(alias, 'django.contrib.auth.models.User')
        self.assertEqual(alias.exclude_attrs, ('message_set', 'password'))
        self.assertEqual(alias.readonly_attrs, ('username',))
开发者ID:LiiiQin,项目名称:test,代码行数:8,代码来源:test_django.py


示例8: test_get_class_alias

    def test_get_class_alias(self):
        self.assertTrue(Spam not in pyamf.CLASS_CACHE)

        self.assertRaises(pyamf.UnknownClassAlias, pyamf.get_class_alias, "spam.eggs")

        pyamf.register_class(Spam, "spam.eggs")
        x = pyamf.get_class_alias("spam.eggs")

        self.assertTrue(isinstance(x, pyamf.ClassAlias))
        self.assertEquals(x.klass, Spam)
        self.assertEquals(x.alias, "spam.eggs")

        x = pyamf.get_class_alias(Spam)

        self.assertTrue(isinstance(x, pyamf.ClassAlias))
        self.assertEquals(x.klass, Spam)
        self.assertEquals(x.alias, "spam.eggs")
开发者ID:kruser,项目名称:zualoo,代码行数:17,代码来源:test_basic.py


示例9: test_alias

    def test_alias(self):
        alias = pyamf.get_class_alias(self.cls)

        alias.compile()

        self.assertTrue(alias.sealed)
        self.assertFalse(alias.dynamic)
        self.assertEquals(alias.alias, 'DSA')
        self.assertTrue(alias.external)
开发者ID:hydralabs,项目名称:plasma,代码行数:9,代码来源:test_small_messages.py


示例10: _compile_base_class

    def _compile_base_class(self, klass):
        if klass is object:
            return

        try:
            alias = pyamf.get_class_alias(klass)
        except UnknownClassAlias:
            alias = pyamf.register_class(klass)

        alias.compile()

        self.bases.append((klass, alias))

        if alias.exclude_attrs:
            self.exclude_attrs.update(alias.exclude_attrs)

        if alias.readonly_attrs:
            self.readonly_attrs.update(alias.readonly_attrs)

        if alias.static_attrs:
            self.static_attrs_set.update(alias.static_attrs)

            for a in alias.static_attrs:
                if a not in self.static_attrs:
                    self.static_attrs.insert(0, a)

        if alias.proxy_attrs:
            self.proxy_attrs.update(alias.proxy_attrs)

        if alias.encodable_properties:
            self.encodable_properties.update(alias.encodable_properties)

        if alias.decodable_properties:
            self.decodable_properties.update(alias.decodable_properties)

        if self.amf3 is None and alias.amf3:
            self.amf3 = alias.amf3

        if self.dynamic is None and alias.dynamic is not None:
            self.inherited_dynamic = alias.dynamic

        if alias.sealed is not None:
            self.inherited_sealed = alias.sealed

        if alias.synonym_attrs:
            # Note that self.synonym_attrs might be None, even if
            # alias.synonym_attrs is defined
            self.synonym_attrs, x = alias.synonym_attrs.copy(), self.synonym_attrs
            self.synonym_attrs.update(x or {})
开发者ID:HiddenData,项目名称:pyamf,代码行数:49,代码来源:alias.py


示例11: _getClassDefinition

    def _getClassDefinition(self, ref):
        """
        Reads class definition from the stream.
        """
        is_ref = ref & REFERENCE_BIT == 0
        ref >>= 1

        if is_ref:
            class_def = self.context.getClassByReference(ref)

            return class_def

        name = self.readBytes()
        alias = None

        if name == '':
            name = pyamf.ASObject

        try:
            alias = pyamf.get_class_alias(name)
        except pyamf.UnknownClassAlias:
            if self.strict:
                raise

            alias = pyamf.TypedObjectClassAlias(name)

        class_def = ClassDefinition(alias)

        class_def.encoding = ref & 0x03
        class_def.attr_len = ref >> 2
        class_def.static_properties = []

        if class_def.attr_len > 0:
            for i in xrange(class_def.attr_len):
                key = self.readBytes()

                class_def.static_properties.append(key)

        self.context.addClass(class_def, alias.klass)

        return class_def
开发者ID:nervatura,项目名称:nerva2py,代码行数:41,代码来源:amf3.py


示例12: test_create

    def test_create(self):
        x = amf3.ClassDefinition('')

        self.assertEquals(x.alias, None)
        self.assertEquals(x.encoding, 2)
        self.assertEquals(x.static_attrs, [])
        self.assertEquals(len(x.static_attrs), 0)

        x = amf3.ClassDefinition(None)

        self.assertEquals(x.alias, None)
        self.assertEquals(x.encoding, 2)
        self.assertEquals(x.static_attrs, [])
        self.assertEquals(len(x.static_attrs), 0)

        pyamf.register_class(Spam, 'spam.eggs')

        x = amf3.ClassDefinition('spam.eggs')
        self.assertTrue(isinstance(x.alias, pyamf.ClassAlias))
        self.assertEquals(x.alias, pyamf.get_class_alias('spam.eggs'))
        self.assertEquals(x.encoding, 2)
        self.assertEquals(x.static_attrs, [])
        self.assertEquals(len(x.static_attrs), 0)
开发者ID:wayne-abarquez,项目名称:vizzuality,代码行数:23,代码来源:test_amf3.py


示例13: readTypedObject

    def readTypedObject(self):
        """
        Reads an ActionScript object from the stream and attempts to
        'cast' it.

        @see: L{load_class<pyamf.load_class>}
        """
        classname = self.readString()
        alias = None

        try:
            alias = pyamf.get_class_alias(classname)

            ret = alias.createInstance(codec=self)
        except pyamf.UnknownClassAlias:
            if self.strict:
                raise

            ret = pyamf.TypedObject(classname)

        self.context.addObject(ret)
        self._readObject(ret, alias)

        return ret
开发者ID:georgehedfors,项目名称:AMFShell,代码行数:24,代码来源:amf0.py


示例14: BaseServiceError

"""
Remoting server implementations.

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

@since: 0.1.0
"""

import types

import pyamf
from pyamf import remoting, logging, util

fault_alias = pyamf.get_class_alias(remoting.ErrorFault)

class BaseServiceError(pyamf.BaseError):
    """
    Base service error.
    """

pyamf.register_class(BaseServiceError, attrs=fault_alias.attrs)
del fault_alias

class UnknownServiceError(BaseServiceError):
    """
    Client made a request for an unknown service.
    """

    _amf_code = 'Service.ResourceNotFound'
开发者ID:wayne-abarquez,项目名称:vizzuality,代码行数:30,代码来源:__init__.py


示例15: writeObject

    def writeObject(self, obj, use_proxies=None):
        """
        Writes an object to the stream.

        @param obj: The object data to be encoded to the AMF3 data stream.
        @type obj: object data
        @raise EncodeError: Encoding an object in amf3 tagged as amf0 only.
        """
        if use_proxies is None:
            use_proxies = self.use_proxies

        if use_proxies is True:
            self.writeProxy(obj)

            return

        self.stream.write(TYPE_OBJECT)

        ref = self.context.getObjectReference(obj)

        if ref is not None:
            self._writeInteger(ref << 1)

            return

        self.context.addObject(obj)

        # object is not referenced, serialise it
        kls = obj.__class__
        definition = self.context.getClass(kls)
        alias = None
        class_ref = False # if the class definition is a reference

        if definition:
            class_ref = True
            alias = definition.alias

            if alias.anonymous and definition.reference is not None:
                class_ref = True
        else:
            try:
                alias = pyamf.get_class_alias(kls)
            except pyamf.UnknownClassAlias:
                alias_klass = util.get_class_alias(kls)
                meta = util.get_class_meta(kls)

                alias = alias_klass(kls, defer=True, **meta)

            definition = ClassDefinition(alias)

            self.context.addClass(definition, alias.klass)

        if class_ref:
            self.stream.write(definition.reference)
        else:
            ref = 0

            if definition.encoding != ObjectEncoding.EXTERNAL:
                ref += definition.attr_len << 4

            final_reference = encode_int(ref | definition.encoding << 2 |
                REFERENCE_BIT << 1 | REFERENCE_BIT)

            self.stream.write(final_reference)

            definition.reference = encode_int(
                definition.reference << 2 | REFERENCE_BIT)

            if alias.anonymous:
                self.stream.write_uchar(0x01)
            else:
                self._writeString(alias.alias)

            # work out what the final reference for the class will be.
            # this is okay because the next time an object of the same
            # class is encoded, class_ref will be True and never get here
            # again.

        if alias.external:
            obj.__writeamf__(DataOutput(self))

            return

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

        if alias.static_attrs:
            if not class_ref:
                [self._writeString(attr) for attr in alias.static_attrs]

            for attr in alias.static_attrs:
                value = attrs.pop(attr)

                self.writeElement(value)

            if definition.encoding == ObjectEncoding.STATIC:
                return

        if definition.encoding == ObjectEncoding.DYNAMIC:
            if attrs:
                for attr, value in attrs.iteritems():
#.........这里部分代码省略.........
开发者ID:cardmagic,项目名称:PyAMF,代码行数:101,代码来源:amf3.py


示例16: BaseServerError

"""
AMF3 RemoteObject support.

@see: U{RemoteObject on LiveDocs
<http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/RemoteObject.html>}

@since: 0.1.0
"""

import calendar, time, uuid, sys

import pyamf
from pyamf import remoting
from pyamf.flex import messaging

error_alias = pyamf.get_class_alias(messaging.ErrorMessage)

class BaseServerError(pyamf.BaseError):
    """
    Base server error.
    """

class ServerCallFailed(BaseServerError):
    """
    A catchall error.
    """
    _amf_code = 'Server.Call.Failed'

pyamf.register_class(ServerCallFailed, attrs=error_alias.attrs)

del error_alias
开发者ID:AbsMate,项目名称:bluecop-xbmc-repo,代码行数:31,代码来源:amf3.py


示例17: BaseServerError

@see: U{RemoteObject on LiveDocs
<http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/RemoteObject.html>}

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

@since: 0.1.0
"""

import calendar, time, uuid, sys

import pyamf
from pyamf import remoting
from pyamf.flex.messaging import *

error_alias = pyamf.get_class_alias(ErrorMessage)

class BaseServerError(pyamf.BaseError):
    """
    Base server errror
    """

class ServerCallFailed(BaseServerError):
    """
    A catchall error.
    """

    _amf_code = 'Server.Call.Failed'

pyamf.register_class(ServerCallFailed, attrs=error_alias.attrs)
开发者ID:weimingtom,项目名称:o-healer-projects,代码行数:29,代码来源:amf3.py


示例18: test_alias

    def test_alias(self):
        alias = pyamf.get_class_alias(self.alias)

        self.assertIdentical(alias.klass, graphics.ImageSnapshot)
开发者ID:hydralabs,项目名称:plasma,代码行数:4,代码来源:test_graphics.py


示例19: test_aliased

    def test_aliased(self):
        alias = pyamf.get_class_alias('flex.messaging.messages.RemotingMessage')

        self.assertTrue(alias.klass.__module__.startswith(plasma.__name__))
开发者ID:hydralabs,项目名称:plasma,代码行数:4,代码来源:test_loaders.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pyamf.get_decoder函数代码示例发布时间:2022-05-25
下一篇:
Python pyamf.encode函数代码示例发布时间: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