本文整理汇总了Python中sqlalchemy.event.remove方法的典型用法代码示例。如果您正苦于以下问题:Python event.remove方法的具体用法?Python event.remove怎么用?Python event.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.event
的用法示例。
在下文中一共展示了event.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drop_database
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def drop_database(url):
url = copy(sqlalchemy.engine.url.make_url(url))
database = url.database
if url.drivername.startswith('postgresql'):
url.database = 'postgres'
elif not url.drivername.startswith('sqlite'):
url.database = None
engine = sqlalchemy.create_engine(url)
if engine.dialect.name == 'sqlite' and url.database != ':memory:':
os.remove(url.database)
else:
text = 'DROP DATABASE {0}'.format(orm.quote(engine, database))
cnx = engine.connect()
cnx.execute("ROLLBACK")
cnx.execute(text)
cnx.execute("commit")
cnx.close()
示例2: precommit_hook
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def precommit_hook(self, registryname, method, *args, **kwargs):
""" Add a method in the precommit_hook list
a precommit hook is a method called just before the commit, it is used
to call this method once, because a hook is saved only once
:param registryname: namespace of the model
:param method: method to call on the registryname
:param put_at_the_end_if_exist: if true and hook allready exist then the
hook are moved at the end
"""
put_at_the_end_if_exist = kwargs.pop('put_at_the_end_if_exist', False)
entry = (registryname, method, args, kwargs)
_precommit_hook = EnvironmentManager.get('_precommit_hook', [])
if entry in _precommit_hook:
if put_at_the_end_if_exist:
_precommit_hook.remove(entry)
_precommit_hook.append(entry)
else:
_precommit_hook.append(entry)
EnvironmentManager.set('_precommit_hook', _precommit_hook)
示例3: apply_postcommit_hook
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def apply_postcommit_hook(self, withexception=False):
hooks = []
_postcommit_hook = EnvironmentManager.get('_postcommit_hook')
if _postcommit_hook:
hooks.extend(_postcommit_hook)
for hook in hooks:
registryname, method, call_only_if, a, kw = hook
if withexception is False and call_only_if == 'raised':
_postcommit_hook.remove(hook)
continue
if withexception is True and call_only_if == 'commited':
_postcommit_hook.remove(hook)
continue
Model = self.loaded_namespaces[registryname]
try:
getattr(Model, method)(*a, **kw)
except Exception as e:
logger.exception(str(e))
finally:
_postcommit_hook.remove(hook)
示例4: __exit__
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def __exit__(self, exc_type, exc_value, exc_traceback):
event.remove(*self._sql_listen_args)
if exc_type is not None:
return False
if self.test_id:
limit_msg = ((' Limit: %d.' % self.max_count)
if self.max_count is not None else '')
logging.info('%s executed %d queries.%s',
self.test_id, len(self.queries), limit_msg)
if self.max_count is None:
return
if len(self.queries) > self.max_count:
message = ('Maximum query count exceeded: limit %d, executed %d.\n'
'----QUERIES----\n%s\n----END----') % (
self.max_count,
len(self.queries),
'\n'.join(self.queries))
raise AssertionError(message)
示例5: test_clslevel_subclass
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def test_clslevel_subclass(self):
Target = self._fixture()
class SubTarget(Target):
pass
m1 = Mock()
event.listen(Target, "event_two", m1)
t1 = SubTarget()
t1.dispatch.event_two("x")
event.remove(Target, "event_two", m1)
t1.dispatch.event_two("y")
eq_(m1.mock_calls, [call("x")])
示例6: test_instance
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def test_instance(self):
Target = self._fixture()
class Foo(object):
def __init__(self):
self.mock = Mock()
def evt(self, arg):
self.mock(arg)
f1 = Foo()
f2 = Foo()
event.listen(Target, "event_one", f1.evt)
event.listen(Target, "event_one", f2.evt)
t1 = Target()
t1.dispatch.event_one("x")
event.remove(Target, "event_one", f1.evt)
t1.dispatch.event_one("y")
eq_(f1.mock.mock_calls, [call("x")])
eq_(f2.mock.mock_calls, [call("x"), call("y")])
示例7: test_remove_not_listened
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def test_remove_not_listened(self):
Target = self._fixture()
m1 = Mock()
t1 = Target()
event.listen(t1, "event_one", m1, propagate=True)
event.listen(t1, "event_three", m1)
event.remove(t1, "event_one", m1)
assert_raises_message(
exc.InvalidRequestError,
r"No listeners found for event <.*Target.*> / "
r"'event_two' / <Mock.*> ",
event.remove,
t1,
"event_two",
m1,
)
event.remove(t1, "event_three", m1)
示例8: test_double_event_nonwrapped
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def test_double_event_nonwrapped(self):
Target = self._fixture()
listen_one = Mock()
t1 = Target()
event.listen(t1, "event_one", listen_one)
event.listen(t1, "event_one", listen_one)
t1.dispatch.event_one("t1")
# doubles are eliminated
eq_(listen_one.mock_calls, [call("t1")])
# only one remove needed
event.remove(t1, "event_one", listen_one)
t1.dispatch.event_one("t2")
eq_(listen_one.mock_calls, [call("t1")])
示例9: test_double_event_wrapped
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def test_double_event_wrapped(self):
# this is issue #3199
Target = self._wrapped_fixture()
listen_one = Mock()
t1 = Target()
event.listen(t1, "event_one", listen_one)
event.listen(t1, "event_one", listen_one)
t1.dispatch.event_one("t1")
# doubles are eliminated
eq_(listen_one.mock_calls, [call("adapted t1")])
# only one remove needed
event.remove(t1, "event_one", listen_one)
t1.dispatch.event_one("t2")
eq_(listen_one.mock_calls, [call("adapted t1")])
示例10: test_instance_event_listen_on_cls_before_map
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def test_instance_event_listen_on_cls_before_map(self):
users = self.tables.users
fn = Mock()
class User(object):
pass
event.listen(User, "load", fn)
m = mapper(User, users)
u1 = User()
m.class_manager.dispatch.load(u1._sa_instance_state, "u1")
event.remove(User, "load", fn)
m.class_manager.dispatch.load(u1._sa_instance_state, "u2")
eq_(fn.mock_calls, [call(u1, "u1")])
示例11: modify_query_fixture
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def modify_query_fixture(self):
def set_event(bake_ok):
event.listen(
Query,
"before_compile",
_modify_query,
retval=True,
bake_ok=bake_ok,
)
return m1
m1 = mock.Mock()
def _modify_query(query):
m1(query.column_descriptions[0]["entity"])
query = query.enable_assertions(False).filter(
literal_column("1") == 1
)
return query
yield set_event
event.remove(Query, "before_compile", _modify_query)
示例12: teardown
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def teardown(self):
for key in self._event_fns:
event.remove(*key)
super_ = super(RemovesEvents, self)
if hasattr(super_, "teardown"):
super_.teardown()
示例13: unregister
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def unregister(cls, session):
if hasattr(session, '_model_changes'):
del session._model_changes
event.remove(session, 'before_flush', cls.record_ops)
event.remove(session, 'before_commit', cls.record_ops)
event.remove(session, 'before_commit', cls.before_commit)
event.remove(session, 'after_commit', cls.after_commit)
event.remove(session, 'after_rollback', cls.after_rollback)
示例14: stop_logging
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def stop_logging(self):
event.remove(self.engine, "after_cursor_execute", self._after_cursor_execute_event_handler)
self._done()
示例15: stop
# 需要导入模块: from sqlalchemy import event [as 别名]
# 或者: from sqlalchemy.event import remove [as 别名]
def stop(self):
""" Remove the listener to stop the validation
"""
if event.contains(self.field, 'set', self.__validate):
event.remove(self.field, 'set', self.__validate)