本文整理汇总了Python中pyamf.util.get_class_alias函数的典型用法代码示例。如果您正苦于以下问题:Python get_class_alias函数的具体用法?Python get_class_alias怎么用?Python get_class_alias使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_class_alias函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: test_simple
def test_simple(self):
class A(object):
pass
pyamf.register_alias_type(DummyAlias, A)
self.assertEqual(util.get_class_alias(A), DummyAlias)
开发者ID:nervatura,项目名称:nerva2py,代码行数:7,代码来源:test_util.py
示例3: register_class
def register_class(klass, alias=None):
"""
Registers a class to be used in the data streaming. This is the equivalent
of the C{[RemoteClass(alias="foobar")]} metatag in Adobe Flex, and the
C{flash.net.registerClassAlias} method in Actionscript 3.0.
@return: The registered L{ClassAlias} instance.
@see: L{unregister_class}
@see: U{flash.net.registerClassAlias on Adobe Help (external)
<http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#registerClassAlias%28%29>}
"""
meta = util.get_class_meta(klass)
if alias is not None:
meta["alias"] = alias
alias_klass = util.get_class_alias(klass) or ClassAlias
x = alias_klass(klass, defer=True, **meta)
if not x.anonymous:
CLASS_CACHE[x.alias] = x
CLASS_CACHE[klass] = x
return x
开发者ID:nervatura,项目名称:nerva2py,代码行数:26,代码来源:__init__.py
示例4: test_multiple
def test_multiple(self):
class A(object):
pass
class B(object):
pass
class C(object):
pass
pyamf.register_alias_type(DummyAlias, A)
pyamf.register_alias_type(AnotherDummyAlias, B)
pyamf.register_alias_type(YADummyAlias, C)
self.assertEqual(util.get_class_alias(B), AnotherDummyAlias)
self.assertEqual(util.get_class_alias(C), YADummyAlias)
self.assertEqual(util.get_class_alias(A), DummyAlias)
开发者ID:nervatura,项目名称:nerva2py,代码行数:17,代码来源:test_util.py
示例5: test_subclass
def test_subclass(self):
class A(object):
pass
class B(A):
pass
pyamf.register_alias_type(DummyAlias, A)
self.assertEquals(util.get_class_alias(B), DummyAlias)
开发者ID:AbsMate,项目名称:bluecop-xbmc-repo,代码行数:10,代码来源:test_util.py
示例6: test_nested
def test_nested(self):
class A(object):
pass
class B(object):
pass
class C(object):
pass
pyamf.register_alias_type(DummyAlias, A, B, C)
self.assertEqual(util.get_class_alias(B), DummyAlias)
开发者ID:nervatura,项目名称:nerva2py,代码行数:13,代码来源:test_util.py
示例7: getClassAlias
def getClassAlias(self, klass):
"""
Gets a class alias based on the supplied C{klass}.
"""
if klass not in self.class_aliases.keys():
try:
self.class_aliases[klass] = get_class_alias(klass)
except UnknownClassAlias:
# no alias has been found yet .. check subclasses
alias = util.get_class_alias(klass)
if alias is not None:
self.class_aliases[klass] = alias(klass, None)
else:
self.class_aliases[klass] = None
return self.class_aliases[klass]
开发者ID:feisley,项目名称:petetweet,代码行数:17,代码来源:__init__.py
示例8: getClassAlias
def getClassAlias(self, klass):
"""
Gets a class alias based on the supplied C{klass}.
"""
try:
return self.class_aliases[klass]
except KeyError:
pass
try:
self.class_aliases[klass] = get_class_alias(klass)
except UnknownClassAlias:
# no alias has been found yet .. check subclasses
alias = util.get_class_alias(klass)
self.class_aliases[klass] = alias(klass)
return self.class_aliases[klass]
开发者ID:georgehedfors,项目名称:AMFShell,代码行数:18,代码来源:__init__.py
示例9: getClassAlias
def getClassAlias(self, klass):
"""
Gets a class alias based on the supplied C{klass}.
@param klass: The class object.
@return: The L{ClassAlias} that is linked to C{klass}
"""
try:
return self.class_aliases[klass]
except KeyError:
pass
try:
self.class_aliases[klass] = get_class_alias(klass)
except UnknownClassAlias:
# no alias has been found yet .. check subclasses
alias = util.get_class_alias(klass)
self.class_aliases[klass] = alias(klass)
return self.class_aliases[klass]
开发者ID:cardmagic,项目名称:PyAMF,代码行数:21,代码来源:__init__.py
示例10: register_class
def register_class(klass, alias=None):
"""
Registers a class to be used in the data streaming.
@return: The registered L{ClassAlias}.
"""
meta = util.get_class_meta(klass)
if alias is not None:
meta['alias'] = alias
alias_klass = util.get_class_alias(klass)
x = alias_klass(klass, defer=True, **meta)
if not x.anonymous:
CLASS_CACHE[x.alias] = x
CLASS_CACHE[klass] = x
return x
开发者ID:cardmagic,项目名称:PyAMF,代码行数:21,代码来源:__init__.py
示例11: register_class
def register_class(klass, alias=None, attrs=None, attr_func=None, metadata=[]):
"""
Registers a class to be used in the data streaming.
@type alias: C{str}
@param alias: The alias of klass, i.e. C{org.example.Person}.
@param attrs: A list of attributes that will be encoded for the class.
@type attrs: C{list} or C{None}
@type attr_func:
@param attr_func:
@type metadata:
@param metadata:
@raise TypeError: PyAMF doesn't support required init arguments.
@raise TypeError: The C{klass} is not callable.
@raise ValueError: The C{klass} or C{alias} is already registered.
@return: The registered L{ClassAlias}.
"""
if not callable(klass):
raise TypeError("klass must be callable")
if klass in CLASS_CACHE:
raise ValueError("klass %s already registered" % (klass,))
if alias is not None and alias in CLASS_CACHE.keys():
raise ValueError("alias '%s' already registered" % (alias,))
alias_klass = util.get_class_alias(klass)
if alias_klass is None:
alias_klass = ClassAlias
x = alias_klass(klass, alias, attr_func=attr_func,
attrs=attrs, metadata=metadata)
if alias is None:
alias = "%s.%s" % (klass.__module__, klass.__name__,)
CLASS_CACHE[alias] = x
return x
开发者ID:feisley,项目名称:petetweet,代码行数:40,代码来源:__init__.py
示例12: test_none_existant
def test_none_existant(self):
self.assertEqual(util.get_class_alias(self.__class__), None)
开发者ID:nervatura,项目名称:nerva2py,代码行数:2,代码来源:test_util.py
示例13: test_none_existant
def test_none_existant(self):
self.assertEquals(pyamf.ClassAlias, util.get_class_alias(self.__class__))
开发者ID:danielor,项目名称:TowerSaint,代码行数:2,代码来源:test_util.py
示例14: 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
注:本文中的pyamf.util.get_class_alias函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论