• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python getSiteManager.reset函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zope.component.getSiteManager.reset函数的典型用法代码示例。如果您正苦于以下问题:Python reset函数的具体用法?Python reset怎么用?Python reset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reset函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: unhook_zca

 def unhook_zca(self):
     """ Call :func:`zope.component.getSiteManager.reset` to undo
     the action of
     :meth:`pyramid.config.Configurator.hook_zca`.  If
     :mod:`zope.component` cannot be imported, this method will
     raise an :exc:`ImportError`."""
     getSiteManager.reset()
开发者ID:DeanHodgkinson,项目名称:pyramid,代码行数:7,代码来源:zca.py


示例2: tearDown

    def tearDown(self):
        from pyramid.threadlocal import manager

        manager.clear()
        getSiteManager = self._getSM()
        if getSiteManager is not None:
            getSiteManager.reset()
开发者ID:pyramidcn,项目名称:pyramid,代码行数:7,代码来源:test_testing.py


示例3: load_zcml

 def load_zcml(self, zcml_asset_specification):
     def _get_site_manager(context=None):
         return self
     if ':' not in zcml_asset_specification:
         import alpaca
         config_package = alpaca
         config_file = zcml_asset_specification
     else:
         package_name, config_file = zcml_asset_specification.split(':')
         __import__(package_name)
         config_package = sys.modules[package_name]
     context = ConfigurationMachine()
     context.package = config_package
     xmlconfig.registerCommonDirectives(context)
     xmlconfig.file(
         config_file,
         package=config_package,
         context=context,
         execute=False
     )
     getSiteManager.sethook(_get_site_manager)
     try:
         context.execute_actions()
     finally:
         getSiteManager.reset()
开发者ID:msiedlarek,项目名称:alpaca,代码行数:25,代码来源:registry.py


示例4: tearDown

def tearDown(unhook_zca=True):
    """Undo the effects of :func:`pyramid.testing.setUp`.  Use this
    function in the ``tearDown`` method of a unit test that uses
    :func:`pyramid.testing.setUp` in its ``setUp`` method.

    If the ``unhook_zca`` argument is ``True`` (the default), call
    :func:`zope.component.getSiteManager.reset`.  This undoes the
    action of :func:`pyramid.testing.setUp` when called with the
    argument ``hook_zca=True``.  If :mod:`zope.component` cannot be
    imported, ``unhook_zca`` is set to ``False``.
    """
    global have_zca
    if unhook_zca and have_zca:
        try:
            from zope.component import getSiteManager
            getSiteManager.reset()
        except ImportError: # pragma: no cover
            have_zca = False
    info = manager.pop()
    manager.clear()
    if info is not None:
        registry = info['registry']
        if hasattr(registry, '__init__') and hasattr(registry, '__name__'):
            try:
                registry.__init__(registry.__name__)
            except TypeError:
                # calling __init__ is largely for the benefit of
                # people who want to use the global ZCA registry;
                # however maybe somebody's using a registry we don't
                # understand, let's not blow up
                pass
开发者ID:AdrianTeng,项目名称:pyramid,代码行数:31,代码来源:testing.py


示例5: pushGlobalRegistry

def pushGlobalRegistry(new=None):
    """Set a new global component registry that uses the current registry as
    a a base. If you use this, you *must* call ``popGlobalRegistry()`` to
    restore the original state.

    If ``new`` is not given, a new registry is created. If given, you must
    provide a ``zope.component.globalregistry.BaseGlobalComponents`` object.

    Returns the new registry.
    """

    from zope.component import globalregistry

    # Save the current top of the stack in a registry
    current = globalregistry.base

    # The first time we're called, we need to put the default global
    # registry at the bottom of the stack, and then patch the class to use
    # the stack for loading pickles. Otherwise, we end up with POSKey and
    # pickling errors when dealing with persistent registries that have the
    # global registry (globalregistry.base) as a base

    if len(_REGISTRIES) == 0:
        _REGISTRIES.append(current)
        globalregistry.BaseGlobalComponents._old__reduce__ = (
            globalregistry.BaseGlobalComponents.__reduce__)
        globalregistry.BaseGlobalComponents.__reduce__ = (
            lambda self: (loadRegistry, (self.__name__,)))

    if new is None:
        name = 'test-stack-{0}'.format(len(_REGISTRIES))
        new = globalregistry.BaseGlobalComponents(name=name, bases=(current,))
        logger.debug(
            'New component registry: %s based on %s',
            name,
            current.__name__)
    else:
        logger.debug('Push component registry: %s', new.__name__)

    _REGISTRIES.append(new)

    # Monkey patch this into the three (!) places where zope.component
    # references it as a module global variable
    _hookRegistry(new)

    # Reset the site manager hook so that getSiteManager() returns the base
    # again
    from zope.component import getSiteManager
    getSiteManager.reset()

    try:
        from zope.component.hooks import setSite, setHooks
    except ImportError:
        pass
    else:
        setSite()
        setHooks()

    return new
开发者ID:plone,项目名称:plone.testing,代码行数:59,代码来源:zca.py


示例6: test_it_with_settings_passed_implicit_registry

 def test_it_with_settings_passed_implicit_registry(self):
     from zope.component import getSiteManager
     from pyramid.threadlocal import manager
     try:
         config = self._callFUT(hook_zca=False,
                                settings=dict(a=1))
         self.assertEqual(config.registry.settings['a'], 1)
     finally:
         getSiteManager.reset()
         manager.clear()
开发者ID:SMFOSS,项目名称:pyramid,代码行数:10,代码来源:test_testing.py


示例7: test_it_with_hook_zca_false

 def test_it_with_hook_zca_false(self):
     from zope.component import getSiteManager
     from pyramid.threadlocal import manager
     registry = object()
     try:
         self._callFUT(registry=registry, hook_zca=False)
         sm = getSiteManager()
         self.failIf(sm is registry)
     finally:
         getSiteManager.reset()
         manager.clear()
开发者ID:RyoAbe,项目名称:pyramid,代码行数:11,代码来源:test_testing.py


示例8: test_it_with_request

 def test_it_with_request(self):
     from zope.component import getSiteManager
     from pyramid.threadlocal import manager
     request = object()
     try:
         self._callFUT(request=request)
         current = manager.get()
         self.assertEqual(current['request'], request)
     finally:
         getSiteManager.reset()
         manager.clear()
开发者ID:SMFOSS,项目名称:pyramid,代码行数:11,代码来源:test_testing.py


示例9: test_unhook_zc_false

 def test_unhook_zc_false(self):
     from pyramid.threadlocal import manager
     from zope.component import getSiteManager
     hook = lambda *arg: None
     try:
         getSiteManager.sethook(hook)
         self._callFUT(unhook_zca=False)
     finally:
         result = getSiteManager.sethook(None)
         self.assertEqual(result, hook)
         getSiteManager.reset()
         manager.clear()
开发者ID:SMFOSS,项目名称:pyramid,代码行数:12,代码来源:test_testing.py


示例10: test_it_with_registry

 def test_it_with_registry(self):
     from pyramid.registry import Registry
     from zope.component import getSiteManager
     from pyramid.threadlocal import manager
     registry = Registry()
     try:
         self._callFUT(registry=registry)
         current = manager.get()
         self.assertEqual(current['registry'], registry)
     finally:
         getSiteManager.reset()
         manager.clear()
开发者ID:SMFOSS,项目名称:pyramid,代码行数:12,代码来源:test_testing.py


示例11: test_hook_zca

    def test_hook_zca(self):
        from zope.component import getSiteManager

        def foo():
            '123'

        try:
            config = self._makeOne()
            config.hook_zca()
            config.begin()
            sm = getSiteManager()
            self.assertEqual(sm, config.registry)
        finally:
            getSiteManager.reset()
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_init.py


示例12: test_unhook_zca

    def test_unhook_zca(self):
        from zope.component import getSiteManager

        def foo():
            '123'

        try:
            getSiteManager.sethook(foo)
            config = self._makeOne()
            config.unhook_zca()
            sm = getSiteManager()
            self.assertNotEqual(sm, '123')
        finally:
            getSiteManager.reset()
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_init.py


示例13: test_uses_configured_site_manager

    def test_uses_configured_site_manager(self):
        from zope.interface.registry import Components
        from zope.component import getSiteManager
        from zope.component.testfiles.components import comp, IApp

        registry = Components()
        def dummy(context=None):
            return registry
        getSiteManager.sethook(dummy)

        try:
            self._callFUT('registerUtility', comp, IApp, u'')
            self.assertTrue(registry.getUtility(IApp) is comp)
        finally:
            getSiteManager.reset()
开发者ID:zopefoundation,项目名称:zope.component,代码行数:15,代码来源:test_zcml.py


示例14: test_defaults

 def test_defaults(self):
     from pyramid.threadlocal import manager
     from zope.component import getSiteManager
     registry = DummyRegistry()
     old = {'registry':registry}
     hook = lambda *arg: None
     try:
         getSiteManager.sethook(hook)
         manager.push(old)
         self._callFUT()
         current = manager.get()
         self.assertNotEqual(current, old)
         self.assertEqual(registry.inited, 2)
     finally:
         result = getSiteManager.sethook(None)
         self.assertNotEqual(result, hook)
         getSiteManager.reset()
         manager.clear()
开发者ID:SMFOSS,项目名称:pyramid,代码行数:18,代码来源:test_testing.py


示例15: test_it_defaults

 def test_it_defaults(self):
     from pyramid.threadlocal import manager
     from pyramid.threadlocal import get_current_registry
     from pyramid.registry import Registry
     from zope.component import getSiteManager
     old = True
     manager.push(old)
     try:
         config = self._callFUT()
         current = manager.get()
         self.failIf(current is old)
         self.assertEqual(config.registry, current['registry'])
         self.assertEqual(current['registry'].__class__, Registry)
         self.assertEqual(current['request'], None)
     finally:
         result = getSiteManager.sethook(None)
         self.assertEqual(result, get_current_registry)
         getSiteManager.reset()
         manager.clear()
开发者ID:SMFOSS,项目名称:pyramid,代码行数:19,代码来源:test_testing.py


示例16: tearDown

def tearDown(unhook_zca=True):
    """Undo the effects :func:`pyramid.testing.setUp`.  Use this
    function in the ``tearDown`` method of a unit test that uses
    :func:`pyramid.testing.setUp` in its ``setUp`` method.

    If the ``unhook_zca`` argument is ``True`` (the default), call
    :func:`zope.component.getSiteManager.reset`.  This undoes the
    action of :func:`pyramid.testing.setUp` called with the
    argument ``hook_zca=True``.  If :mod:`zope.component` cannot be
    imported, ignore the argument.

    .. warning:: Although this method of tearing a test setup down
                 will never disappear, after :app:`Pyramid` 1.0,
                 using the ``begin`` and ``end`` methods of a
                 ``Configurator`` are preferred to using
                 ``pyramid.testing.setUp`` and
                 ``pyramid.testing.tearDown``.  See
                 :ref:`unittesting_chapter` for more information.

    """
    if unhook_zca:
        try:
            from zope.component import getSiteManager

            getSiteManager.reset()
        except ImportError:  # pragma: no cover
            pass
    info = manager.pop()
    manager.clear()
    if info is not None:
        registry = info["registry"]
        if hasattr(registry, "__init__") and hasattr(registry, "__name__"):
            try:
                registry.__init__(registry.__name__)
            except TypeError:
                # calling __init__ is largely for the benefit of
                # people who want to use the global ZCA registry;
                # however maybe somebody's using a registry we don't
                # understand, let's not blow up
                pass
    _clearContext()  # XXX why?
开发者ID:blaflamme,项目名称:pyramid,代码行数:41,代码来源:testing.py


示例17: popGlobalRegistry

def popGlobalRegistry():
    """Restore the global component registry form the top of the stack, as
    set with ``pushGlobalRegistry()``.
    """

    from zope.component import globalregistry

    if not _REGISTRIES or not _REGISTRIES[-1] is globalregistry.base:
        msg = ('popGlobalRegistry() called out of sync with '
               'pushGlobalRegistry()')
        raise ValueError(msg)

    current = _REGISTRIES.pop()
    previous = current.__bases__[0]

    # If we only have the default registry on the stack, return it to its
    # original state and empty the stack
    if len(_REGISTRIES) == 1:
        assert _REGISTRIES[0] is previous
        _REGISTRIES.pop()
        globalregistry.BaseGlobalComponents.__reduce__ = (
            globalregistry.BaseGlobalComponents._old__reduce__)

    _hookRegistry(previous)

    # Reset the site manager hook so that getSiteManager() returns the base
    # again
    from zope.component import getSiteManager
    getSiteManager.reset()

    try:
        from zope.component.hooks import setSite, setHooks
    except ImportError:
        pass
    else:
        setSite()
        setHooks()

    return previous
开发者ID:plone,项目名称:plone.testing,代码行数:39,代码来源:zca.py


示例18: tearDown

 def tearDown(self):
     getSiteManager.reset()
开发者ID:andreypopp,项目名称:statics,代码行数:2,代码来源:util.py


示例19: unhook_zca

 def unhook_zca(self):
     """ Call :func:`zope.component.getSiteManager.reset` to undo the
     action of :meth:`pyramid.config.Configurator.hook_zca`."""
     from zope.component import getSiteManager
     getSiteManager.reset()
开发者ID:7924102,项目名称:pyramid,代码行数:5,代码来源:zca.py


示例20: tearDown

 def tearDown(self):
     from zope.component import getSiteManager
     getSiteManager.reset()
开发者ID:andreypopp,项目名称:contentlet,代码行数:3,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python getSiteManager.sethook函数代码示例发布时间:2022-05-26
下一篇:
Python eventtesting.setUp函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap