本文整理汇总了Python中sqlalchemy.orm.instrumentation.register_class函数的典型用法代码示例。如果您正苦于以下问题:Python register_class函数的具体用法?Python register_class怎么用?Python register_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_class函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_defaulted_init
def test_defaulted_init(self):
class X(object):
def __init__(self_, a, b=123, c='abc'):
self_.a = a
self_.b = b
self_.c = c
instrumentation.register_class(X)
o = X('foo')
eq_(o.a, 'foo')
eq_(o.b, 123)
eq_(o.c, 'abc')
class Y(object):
unique = object()
class OutOfScopeForEval(object):
def __repr__(self_):
# misleading repr
return '123'
outofscope = OutOfScopeForEval()
def __init__(self_, u=unique, o=outofscope):
self_.u = u
self_.o = o
instrumentation.register_class(Y)
o = Y()
assert o.u is Y.unique
assert o.o is Y.outofscope
开发者ID:onetera,项目名称:scandatatransfer,代码行数:32,代码来源:test_instrumentation.py
示例2: test_nativeext_submanager
def test_nativeext_submanager(self):
class Mine(instrumentation.ClassManager): pass
class A(object):
__sa_instrumentation_manager__ = Mine
instrumentation.register_class(A)
eq_(type(instrumentation.manager_of_class(A)), Mine)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:7,代码来源:test_instrumentation.py
示例3: test_standard
def test_standard(self):
class A(object):
pass
register_class(A)
eq_(type(manager_of_class(A)), instrumentation.ClassManager)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:7,代码来源:test_extendedattr.py
示例4: test_inheritance
def test_inheritance(self):
"""tests that attributes are polymorphic"""
for base in (object, MyBaseClass, MyClass):
class Foo(base):pass
class Bar(Foo):pass
instrumentation.register_class(Foo)
instrumentation.register_class(Bar)
def func1(state, passive):
return "this is the foo attr"
def func2(state, passive):
return "this is the bar attr"
def func3(state, passive):
return "this is the shared attr"
attributes.register_attribute(Foo, 'element',
uselist=False, callable_=func1,
useobject=True)
attributes.register_attribute(Foo, 'element2',
uselist=False, callable_=func3,
useobject=True)
attributes.register_attribute(Bar, 'element',
uselist=False, callable_=func2,
useobject=True)
x = Foo()
y = Bar()
assert x.element == 'this is the foo attr'
assert y.element == 'this is the bar attr', y.element
assert x.element2 == 'this is the shared attr'
assert y.element2 == 'this is the shared attr'
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:32,代码来源:test_extendedattr.py
示例5: test_basic
def test_basic(self):
for base in (object, MyBaseClass, MyClass):
class User(base):
pass
register_class(User)
attributes.register_attribute(
User, 'user_id', uselist=False, useobject=False)
attributes.register_attribute(
User, 'user_name', uselist=False, useobject=False)
attributes.register_attribute(
User, 'email_address', uselist=False, useobject=False)
u = User()
u.user_id = 7
u.user_name = 'john'
u.email_address = '[email protected]'
eq_(u.user_id, 7)
eq_(u.user_name, "john")
eq_(u.email_address, "[email protected]")
attributes.instance_state(u)._commit_all(
attributes.instance_dict(u))
eq_(u.user_id, 7)
eq_(u.user_name, "john")
eq_(u.email_address, "[email protected]")
u.user_name = 'heythere'
u.email_address = '[email protected]'
eq_(u.user_id, 7)
eq_(u.user_name, "heythere")
eq_(u.email_address, "[email protected]")
开发者ID:anti-social,项目名称:sqlalchemy,代码行数:32,代码来源:test_extendedattr.py
示例6: test_collection_with_backref
def test_collection_with_backref(self):
for base in (object, MyBaseClass, MyClass):
class Post(base):pass
class Blog(base):pass
instrumentation.register_class(Post)
instrumentation.register_class(Blog)
attributes.register_attribute(Post, 'blog', uselist=False,
backref='posts', trackparent=True, useobject=True)
attributes.register_attribute(Blog, 'posts', uselist=True,
backref='blog', trackparent=True, useobject=True)
b = Blog()
(p1, p2, p3) = (Post(), Post(), Post())
b.posts.append(p1)
b.posts.append(p2)
b.posts.append(p3)
self.assert_(b.posts == [p1, p2, p3])
self.assert_(p2.blog is b)
p3.blog = None
self.assert_(b.posts == [p1, p2])
p4 = Post()
p4.blog = b
self.assert_(b.posts == [p1, p2, p4])
p4.blog = b
p4.blog = b
self.assert_(b.posts == [p1, p2, p4])
# assert no failure removing None
p5 = Post()
p5.blog = None
del p5.blog
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:33,代码来源:test_extendedattr.py
示例7: test_instance_dict
def test_instance_dict(self):
class User(MyClass):
pass
register_class(User)
attributes.register_attribute(
User, "user_id", uselist=False, useobject=False
)
attributes.register_attribute(
User, "user_name", uselist=False, useobject=False
)
attributes.register_attribute(
User, "email_address", uselist=False, useobject=False
)
u = User()
u.user_id = 7
u.user_name = "john"
u.email_address = "[email protected]"
eq_(
u.__dict__,
{
"_my_state": u._my_state,
"_goofy_dict": {
"user_id": 7,
"user_name": "john",
"email_address": "[email protected]",
},
},
)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:30,代码来源:test_extendedattr.py
示例8: register
def register(self, cls, canary):
original_init = cls.__init__
instrumentation.register_class(cls)
ne_(cls.__init__, original_init)
manager = instrumentation.manager_of_class(cls)
def init(state, args, kwargs):
canary.append((cls, 'init', state.class_))
event.listen(manager, 'init', init, raw=True)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:8,代码来源:test_instrumentation.py
示例9: test_customfinder_pass
def test_customfinder_pass(self):
class A(object): pass
def find(cls):
return None
instrumentation.instrumentation_finders.insert(0, find)
instrumentation.register_class(A)
eq_(type(instrumentation.manager_of_class(A)), instrumentation.ClassManager)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:8,代码来源:test_instrumentation.py
示例10: test_nativeext_interfaceexact
def test_nativeext_interfaceexact(self):
class A(object):
__sa_instrumentation_manager__ = (
instrumentation.InstrumentationManager
)
register_class(A)
ne_(type(manager_of_class(A)), instrumentation.ClassManager)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:8,代码来源:test_extendedattr.py
示例11: test_customfinder_greedy
def test_customfinder_greedy(self):
class Mine(instrumentation.ClassManager): pass
class A(object): pass
def find(cls):
return Mine
instrumentation.instrumentation_finders.insert(0, find)
register_class(A)
eq_(type(instrumentation.manager_of_class(A)), Mine)
开发者ID:ajtowns,项目名称:sqlalchemy,代码行数:9,代码来源:test_extendedattr.py
示例12: test_single_down
def test_single_down(self):
class A(object): pass
instrumentation.register_class(A)
mgr_factory = lambda cls: instrumentation.ClassManager(cls)
class B(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
assert_raises_message(TypeError, "multiple instrumentation implementations", instrumentation.register_class, B)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:9,代码来源:test_instrumentation.py
示例13: test_null_instrumentation
def test_null_instrumentation(self):
class Foo(MyBaseClass):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "name", uselist=False, useobject=False)
attributes.register_attribute(Foo, "bars", uselist=True, trackparent=True, useobject=True)
assert Foo.name == attributes.manager_of_class(Foo)['name']
assert Foo.bars == attributes.manager_of_class(Foo)['bars']
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:9,代码来源:test_extendedattr.py
示例14: test_diamond_b2
def test_diamond_b2(self):
mgr_factory = lambda cls: instrumentation.ClassManager(cls)
class A(object): pass
class B1(A): pass
class B2(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
class C(object): pass
instrumentation.register_class(B2)
assert_raises_message(TypeError, "multiple instrumentation implementations", instrumentation.register_class, B1)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:11,代码来源:test_instrumentation.py
示例15: test_subclassed
def test_subclassed(self):
class MyEvents(events.InstanceEvents):
pass
class MyClassManager(instrumentation.ClassManager):
dispatch = event.dispatcher(MyEvents)
instrumentation.instrumentation_finders.insert(0, lambda cls: MyClassManager)
class A(object): pass
instrumentation.register_class(A)
manager = instrumentation.manager_of_class(A)
assert issubclass(manager.dispatch._parent_cls.__dict__['dispatch'].events, MyEvents)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:13,代码来源:test_instrumentation.py
示例16: test_instance_dict
def test_instance_dict(self):
class User(MyClass):
pass
instrumentation.register_class(User)
attributes.register_attribute(User, 'user_id', uselist = False, useobject=False)
attributes.register_attribute(User, 'user_name', uselist = False, useobject=False)
attributes.register_attribute(User, 'email_address', uselist = False, useobject=False)
u = User()
u.user_id = 7
u.user_name = 'john'
u.email_address = '[email protected]'
self.assert_(u.__dict__ == {'_my_state':u._my_state, '_goofy_dict':{'user_id':7, 'user_name':'john', 'email_address':'[email protected]'}}, u.__dict__)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:14,代码来源:test_extendedattr.py
示例17: test_single_up
def test_single_up(self):
class A(object):
pass
# delay registration
def mgr_factory(cls): return instrumentation.ClassManager(cls)
class B(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
register_class(B)
assert_raises_message(
TypeError, "multiple instrumentation implementations",
register_class, A)
开发者ID:anti-social,项目名称:sqlalchemy,代码行数:15,代码来源:test_extendedattr.py
示例18: _instrument
def _instrument(self, cls):
manager = instrumentation.register_class(cls)
canary = []
def check(target, args, kwargs):
canary.append((args, kwargs))
event.listen(manager, "init", check)
return cls, canary
开发者ID:afeide,项目名称:LuoYunCloud,代码行数:7,代码来源:test_instrumentation.py
示例19: __init__
def __init__(self, cls_, classname, dict_):
self.cls = cls_
# dict_ will be a dictproxy, which we can't write to, and we need to!
self.dict_ = dict(dict_)
self.classname = classname
self.mapped_table = None
self.properties = util.OrderedDict()
self.declared_columns = set()
self.column_copies = {}
self._setup_declared_events()
# register up front, so that @declared_attr can memoize
# function evaluations in .info
manager = instrumentation.register_class(self.cls)
manager.info['declared_attr_reg'] = {}
self._scan_attributes()
clsregistry.add_class(self.classname, self.cls)
self._extract_mappable_attributes()
self._extract_declared_columns()
self._setup_table()
self._setup_inheritance()
self._early_mapping()
开发者ID:AnuNarayan,项目名称:blog,代码行数:31,代码来源:base.py
示例20: test_register_reserved_attribute
def test_register_reserved_attribute(self):
class T(object): pass
instrumentation.register_class(T)
manager = instrumentation.manager_of_class(T)
sa = instrumentation.ClassManager.STATE_ATTR
ma = instrumentation.ClassManager.MANAGER_ATTR
fails = lambda method, attr: assert_raises(
KeyError, getattr(manager, method), attr, property())
fails('install_member', sa)
fails('install_member', ma)
fails('install_descriptor', sa)
fails('install_descriptor', ma)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:16,代码来源:test_instrumentation.py
注:本文中的sqlalchemy.orm.instrumentation.register_class函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论