当前位置: 首页>>代码示例>>Python>>正文


Python event.remove方法代码示例

本文整理汇总了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() 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:20,代码来源:testing.py

示例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) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:26,代码来源:registry.py

示例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) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:25,代码来源:registry.py

示例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) 
开发者ID:google,项目名称:ctfscoreboard,代码行数:20,代码来源:base.py

示例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")]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_events.py

示例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")]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_events.py

示例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) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_events.py

示例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")]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_events.py

示例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")]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_events.py

示例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")]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_events.py

示例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) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_baked.py

示例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() 
开发者ID:jpush,项目名称:jbox,代码行数:8,代码来源:fixtures.py

示例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) 
开发者ID:jpush,项目名称:jbox,代码行数:11,代码来源:__init__.py

示例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() 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:5,代码来源:util.py

示例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) 
开发者ID:xeBuz,项目名称:Flask-Validator,代码行数:7,代码来源:validator.py


注:本文中的sqlalchemy.event.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。