本文整理汇总了Python中pyamf.register_alias_type函数的典型用法代码示例。如果您正苦于以下问题:Python register_alias_type函数的具体用法?Python register_alias_type怎么用?Python register_alias_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_alias_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple
def test_simple(self):
class A(object):
pass
pyamf.register_alias_type(DummyAlias, A)
self.assertEqual(util.get_class_alias(A), DummyAlias)
示例2: test_duplicate
def test_duplicate(self):
class A(object):
pass
pyamf.register_alias_type(DummyAlias, A)
self.assertRaises(RuntimeError, pyamf.register_alias_type, DummyAlias, A)
示例3: test_single
def test_single(self):
class A(object):
pass
pyamf.register_alias_type(DummyAlias, A)
self.assertTrue(DummyAlias in pyamf.ALIAS_TYPES.keys())
self.assertEqual(pyamf.ALIAS_TYPES[DummyAlias], (A,))
示例4: 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)
示例5: test_multiple
def test_multiple(self):
class A(object):
pass
class B(object):
pass
self.assertRaises(TypeError, pyamf.register_alias_type, DummyAlias, A, 'hello')
pyamf.register_alias_type(DummyAlias, A, B)
self.assertTrue(DummyAlias in pyamf.ALIAS_TYPES)
self.assertEqual(pyamf.ALIAS_TYPES[DummyAlias], (A, B))
示例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)
示例7: test_registered_deep
def test_registered_deep(self):
class A:
pass
class B(A):
pass
pyamf.register_alias_type(DummyAlias, A)
self.addCleanup(pyamf.unregister_alias_type, DummyAlias)
alias = self.context.getClassAlias(B)
self.assertTrue(isinstance(alias, DummyAlias))
self.assertIdentical(alias.klass, B)
示例8: test_unregister
def test_unregister(self):
"""
Tests for L{pyamf.unregister_alias_type}
"""
class A(object):
pass
self.assertFalse(DummyAlias in pyamf.ALIAS_TYPES)
self.assertEqual(pyamf.unregister_alias_type(A), None)
pyamf.register_alias_type(DummyAlias, A)
self.assertTrue(DummyAlias in pyamf.ALIAS_TYPES.keys())
self.assertEqual(pyamf.unregister_alias_type(DummyAlias), (A,))
示例9: test_registered_deep
def test_registered_deep(self):
x = pyamf.BaseContext()
self.assertEquals(x.class_aliases, {})
class A:
pass
class B(A):
pass
pyamf.register_alias_type(DummyAlias, A)
alias = x.getClassAlias(B)
self.assertTrue(isinstance(alias, pyamf.ClassAlias))
self.assertEquals(alias.__class__, DummyAlias)
self.assertEquals(alias.klass, B)
示例10: 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)
示例11: applyAttributes
return attrs
def applyAttributes(self, obj, attrs, **kwargs):
"""
Applies C{attrs} to C{obj}. Since C{blobstore.BlobInfo} objects are
read-only entities, we only care about the C{key} attribute.
"""
assert type(obj) is BlobInfoStub
key = attrs.pop('key', None)
if not key:
raise pyamf.DecodeError("Unable to build blobstore.BlobInfo "
"instance. Missing 'key' attribute.")
try:
key = blobstore.BlobKey(key)
except:
raise pyamf.DecodeError("Unable to build a valid blobstore.BlobKey "
"instance. Key supplied was %r" % (key,))
obj.__class__ = blobstore.BlobInfo
obj.__init__(key)
pyamf.register_alias_type(BlobInfoClassAlias, bi)
pyamf.register_class(bi, '.'.join([blobstore.__name__, bi.__name__]))
del bi
示例12: 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)
示例13: test_subclass
def test_subclass(self):
self.assertFalse(issubclass(self.__class__, pyamf.ClassAlias))
with self.assertRaises(ValueError):
pyamf.register_alias_type(self.__class__)
示例14: type
read-only entities, we only care about the C{key} attribute.
"""
assert type(obj) is BlobInfoStub
key = attrs.pop('key', None)
if not key:
raise pyamf.DecodeError(
"Unable to build blobstore.BlobInfo instance. Missing 'key' "
"attribute."
)
try:
key = blobstore.BlobKey(key)
except:
raise pyamf.DecodeError(
"Unable to build a valid blobstore.BlobKey instance. Key "
"supplied was %r" % (key,)
)
obj.__class__ = blobstore.BlobInfo
obj.__init__(key)
pyamf.register_alias_type(BlobInfoClassAlias, blobstore.BlobInfo)
pyamf.register_class(blobstore.BlobInfo, '.'.join([
blobstore.__name__,
blobstore.BlobInfo.__name__
]))
示例15: map_mongoengine_document
fields = obj._fields
for key, value in attrs.items():
if key not in fields.keys():
print "Got unknown key '%s' for %r" % (key, obj)
del attrs[key]
return attrs
def map_mongoengine_document(klass):
if not isinstance(klass, type):
klass = type(klass)
if issubclass(klass, BaseDocument):
return True
return False
def objectIDHack(obj, encoder=None):
"""
For some reason ObjectIDs fuck everything up. I dont know why and when I try to find
out I end up smashing things. So here a little hack!
@param obj:
@param encoder:
@return:
"""
encoder.writeObject({})
pyamf.register_alias_type(MongoEngineDocumentAlias, map_mongoengine_document)
pyamf.add_type(ObjectId, objectIDHack)