本文整理汇总了Python中pyamf.get_class_alias函数的典型用法代码示例。如果您正苦于以下问题:Python get_class_alias函数的具体用法?Python get_class_alias怎么用?Python get_class_alias使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_class_alias函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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"], []))
示例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'])
示例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
示例5: test_class_alias
def test_class_alias(self):
alias_klass = pyamf.get_class_alias(blobstore.BlobInfo)
self.assertIdentical(
alias_klass.__class__,
adapter.BlobInfoClassAlias
)
示例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__,))
示例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',))
示例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")
示例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)
示例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 {})
示例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
示例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)
示例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
示例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'
示例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():
#.........这里部分代码省略.........