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


Python getSiteManager.reset函数代码示例

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


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


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