本文整理汇总了Python中pyramid.threadlocal.manager.pop函数的典型用法代码示例。如果您正苦于以下问题:Python pop函数的具体用法?Python pop怎么用?Python pop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, environ, start_response):
"""
Accept ``environ`` and ``start_response``; create a
:term:`request` and route the request to a :app:`Pyramid`
view based on introspection of :term:`view configuration`
within the application registry; call ``start_response`` and
return an iterable.
"""
registry = self.registry
has_listeners = self.registry.has_listeners
notify = self.registry.notify
request = self.request_factory(environ)
threadlocals = {"registry": registry, "request": request}
manager = self.threadlocal_manager
manager.push(threadlocals)
request.registry = registry
try:
try:
response = self.handle_request(request)
has_listeners and notify(NewResponse(request, response))
if request.response_callbacks:
request._process_response_callbacks(response)
return response(request.environ, start_response)
finally:
if request.finished_callbacks:
request._process_finished_callbacks()
finally:
manager.pop()
开发者ID:sundisee,项目名称:appsync-vendor,代码行数:33,代码来源:router.py
示例2: __call__
def __call__(self, environ, start_response):
"""
Accept ``environ`` and ``start_response``; create a
:term:`request` and route the request to a :app:`Pyramid`
view based on introspection of :term:`view configuration`
within the application registry; call ``start_response`` and
return an iterable.
"""
registry = self.registry
manager = self.threadlocal_manager
request = None
threadlocals = {'registry':registry, 'request':request}
manager.push(threadlocals)
try:
try:
request = self.request_factory(environ)
threadlocals['request'] = request
request.registry = registry
response = self.handle_request(request)
finally:
if request is not None and request.finished_callbacks:
request._process_finished_callbacks()
return response(request.environ, start_response)
finally:
manager.pop()
开发者ID:malthe,项目名称:pyramid,代码行数:27,代码来源:router.py
示例3: test_it
def test_it(self):
from pyramid.threadlocal import manager
try:
manager.push({'registry':123})
self.assertEqual(self._callFUT(), 123)
finally:
manager.pop()
开发者ID:7924102,项目名称:pyramid,代码行数:7,代码来源:test_threadlocal.py
示例4: clear_snapshot
def clear_snapshot(signum=None, frame=None):
global current_xmin_snapshot_id
if current_xmin_snapshot_id is None:
return
transaction.abort()
manager.pop()
current_xmin_snapshot_id = None
开发者ID:ENCODE-DCC,项目名称:snovault,代码行数:7,代码来源:mpindexer.py
示例5: invoke_request
def invoke_request(self, request,
_use_tweens=True, _apply_extensions=False):
registry = self.registry
has_listeners = self.registry.has_listeners
notify = self.registry.notify
threadlocals = {'registry': registry, 'request': request}
manager = self.threadlocal_manager
manager.push(threadlocals)
if _use_tweens:
handle_request = self.handle_request
else:
handle_request = self.orig_handle_request
try:
try:
extensions = self.request_extensions
if _apply_extensions and extensions is not None:
apply_request_extensions(request, extensions=extensions)
response = handle_request(request)
if request.response_callbacks:
request._process_response_callbacks(response)
has_listeners and notify(NewResponse(request, response))
return response
finally:
if request.finished_callbacks:
request._process_finished_callbacks()
finally:
manager.pop()
开发者ID:goodwillcoding,项目名称:pyramid,代码行数:35,代码来源:router.py
示例6: execute_callback
def execute_callback(app, callback, login):
# set site and interaction that will be memorized in job
request = DummyRequest()
request.root = app
registry = get_current_registry()
manager.push({'registry': registry, 'request': request})
user = get_user_by_login(login, request)
request.user = user
callback()
manager.pop()
开发者ID:ecreall,项目名称:dace,代码行数:10,代码来源:util.py
示例7: test_add_translation_dirs_registers_chameleon_translate
def test_add_translation_dirs_registers_chameleon_translate(self):
from pyramid.interfaces import IChameleonTranslate
from pyramid.threadlocal import manager
request = DummyRequest()
config = self._makeOne(autocommit=True)
manager.push({'request':request, 'registry':config.registry})
try:
config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale')
translate = config.registry.getUtility(IChameleonTranslate)
self.assertEqual(translate('Approve'), u'Approve')
finally:
manager.pop()
开发者ID:MattBurgess,项目名称:pyramid,代码行数:12,代码来源:test_i18n.py
示例8: _threadContext
def _threadContext(self):
# IMPORTANT: this assumes that APScheduler invokes jobs in a separate
# thread per job (as documented)...
# TODO: this needs confirmation!
if self.appreg is None:
yield
else:
from pyramid.threadlocal import manager
reg = dict(manager.get())
reg['registry'] = self.appreg
manager.push(reg)
try:
yield
finally:
manager.pop()
开发者ID:cadithealth,项目名称:pyramid_scheduler,代码行数:15,代码来源:scheduler.py
示例9: test_it_raises_if_no_registry
def test_it_raises_if_no_registry(self):
request = self._makeOne()
del request.registry
from pyramid.threadlocal import manager
manager.push({'registry': None, 'request': request})
try:
raise RuntimeError
except RuntimeError:
try:
request.invoke_exception_view()
except RuntimeError as e:
self.assertEqual(e.args[0], "Unable to retrieve registry")
else: # pragma: no cover
self.fail()
finally:
manager.pop()
开发者ID:invisibleroads,项目名称:pyramid,代码行数:16,代码来源:test_view.py
示例10: 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
示例11: invoke_subrequest
def invoke_subrequest(self, request, use_tweens=False):
"""Obtain a response object from the Pyramid application based on
information in the ``request`` object provided. The ``request``
object must be an object that implements the Pyramid request
interface (such as a :class:`pyramid.request.Request` instance). If
``use_tweens`` is ``True``, the request will be sent to the
:term:`tween` in the tween stack closest to the request ingress. If
``use_tweens`` is ``False``, the request will be sent to the main
router handler, and no tweens will be invoked.
See the API for pyramid.request for complete documentation.
"""
registry = self.registry
has_listeners = self.registry.has_listeners
notify = self.registry.notify
threadlocals = {'registry':registry, 'request':request}
manager = self.threadlocal_manager
manager.push(threadlocals)
request.registry = registry
request.invoke_subrequest = self.invoke_subrequest
if use_tweens:
handle_request = self.handle_request
else:
handle_request = self.orig_handle_request
try:
try:
extensions = self.request_extensions
if extensions is not None:
apply_request_extensions(request, extensions=extensions)
response = handle_request(request)
if request.response_callbacks:
request._process_response_callbacks(response)
has_listeners and notify(NewResponse(request, response))
return response
finally:
if request.finished_callbacks:
request._process_finished_callbacks()
finally:
manager.pop()
开发者ID:AlanMachado,项目名称:pyramid,代码行数:47,代码来源:router.py
示例12: execute
def execute(self, p_steps=None, request=None):
registry = self.registry
if request is None:
request_factory = registry.queryUtility(
IRequestFactory, default=Request)
request = request_factory.blank('/')
request.registry = registry
threadlocals = {'registry':registry, 'request':request}
threadlocal_manager.push(threadlocals)
steps = self.list_steps(p_steps)
log = logging.getLogger('ptah')
for step in steps:
log.info('Executing populate step: %s', step['name'])
step['factory'](registry)
transaction.commit()
threadlocal_manager.pop()
开发者ID:carlicos,项目名称:ptah,代码行数:21,代码来源:populate.py
示例13: add_services_definitions
def add_services_definitions(event):
app = event.object
registry = app.registry
settings = getattr(registry, 'settings', {})
request = Request.blank('/application_created') # path is meaningless
request.registry = registry
manager.push({'registry': registry, 'request': request})
root = app.root_factory(request)
request.root = root
# use same env variable as substanced catalog to determine
# if we want to upgrade definitions
autosync = asbool(
os.environ.get(
'SUBSTANCED_CATALOGS_AUTOSYNC',
settings.get(
'substanced.catalogs.autosync',
settings.get('substanced.autosync_catalogs', False) # bc
)))
existing_definitions = root.get_services_definition()
if autosync:
for definition in existing_definitions.values():
if hasattr(definition, '_broken_object'):
root.delfromproperty('services_definition', definition)
for definition in core.SERVICES_DEFINITION.values():
old_def = existing_definitions.get(definition.service_id, None)
if old_def is None:
root.addtoproperty('services_definition', definition)
core.SERVICES_DEFINITION.clear()
# other init functions
init_site_folders(root)
init_contents(registry)
init_sites_social_login(root)
transaction.commit()
manager.pop()
开发者ID:ecreall,项目名称:lagendacommun,代码行数:39,代码来源:subscribers.py
示例14: 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
示例15: invoke_exception_view
def invoke_exception_view(
self, exc_info=None, request=None, secure=True, reraise=False
):
""" Executes an exception view related to the request it's called upon.
The arguments it takes are these:
``exc_info``
If provided, should be a 3-tuple in the form provided by
``sys.exc_info()``. If not provided,
``sys.exc_info()`` will be called to obtain the current
interpreter exception information. Default: ``None``.
``request``
If the request to be used is not the same one as the instance that
this method is called upon, it may be passed here. Default:
``None``.
``secure``
If the exception view should not be rendered if the current user
does not have the appropriate permission, this should be ``True``.
Default: ``True``.
``reraise``
A boolean indicating whether the original error should be reraised
if a :term:`response` object could not be created. If ``False``
then an :class:`pyramid.httpexceptions.HTTPNotFound`` exception
will be raised. Default: ``False``.
If a response is generated then ``request.exception`` and
``request.exc_info`` will be left at the values used to render the
response. Otherwise the previous values for ``request.exception`` and
``request.exc_info`` will be restored.
.. versionadded:: 1.7
.. versionchanged:: 1.9
The ``request.exception`` and ``request.exc_info`` properties will
reflect the exception used to render the response where previously
they were reset to the values prior to invoking the method.
Also added the ``reraise`` argument.
"""
if request is None:
request = self
registry = getattr(request, 'registry', None)
if registry is None:
registry = get_current_registry()
if registry is None:
raise RuntimeError("Unable to retrieve registry")
if exc_info is None:
exc_info = sys.exc_info()
exc = exc_info[1]
attrs = request.__dict__
context_iface = providedBy(exc)
# clear old generated request.response, if any; it may
# have been mutated by the view, and its state is not
# sane (e.g. caching headers)
with hide_attrs(request, 'response', 'exc_info', 'exception'):
attrs['exception'] = exc
attrs['exc_info'] = exc_info
# we use .get instead of .__getitem__ below due to
# https://github.com/Pylons/pyramid/issues/700
request_iface = attrs.get('request_iface', IRequest)
manager.push({'request': request, 'registry': registry})
try:
response = _call_view(
registry,
request,
exc,
context_iface,
'',
view_types=None,
view_classifier=IExceptionViewClassifier,
secure=secure,
request_iface=request_iface.combined,
)
except Exception:
if reraise:
reraise_(*exc_info)
raise
finally:
manager.pop()
if response is None:
if reraise:
reraise_(*exc_info)
raise HTTPNotFound
# successful response, overwrite exception/exc_info
#.........这里部分代码省略.........
开发者ID:Pylons,项目名称:pyramid,代码行数:101,代码来源:view.py
示例16: add_process_definitions
def add_process_definitions(event):
app = event.object
registry = app.registry
settings = getattr(registry, 'settings', {})
request = Request.blank('/application_created') # path is meaningless
request.registry = registry
manager.push({'registry': registry, 'request': request})
root = app.root_factory(request)
request.root = root
# use same env variable as substanced catalog to determine
# if we want to recreate process definitions.
# autosync is True only in development mode.
autosync = asbool(
os.environ.get(
'SUBSTANCED_CATALOGS_AUTOSYNC',
settings.get(
'substanced.catalogs.autosync',
settings.get('substanced.autosync_catalogs', False) # bc
)))
try:
# This code block must be in sync with what we do in
# process_definitions_evolve minus the autosync conditions
def_container = root['process_definition_container']
if autosync:
for definition in def_container.definitions:
if hasattr(definition, '_broken_object'):
name = definition.__name__
def_container.remove(name, send_events=False)
def_container._definitions_value.remove(name)
for definition in processdef_container.DEFINITIONS.values():
old_def = def_container.get(definition.id, None)
if old_def is None:
# We add the definition at startup when creating the application
# the first time where we normally have one worker.
# If we have more that one worker, the other workers will do
# a ConflictError here.
if getattr(def_container, '_initializing', False) or autosync:
def_container.add_definition(definition)
else:
if autosync:
def_container.delfromproperty('definitions', old_def)
def_container.add_definition(definition)
if autosync:
# if not autosync, we still need this global constant for the
# process_definitions_evolve step
processdef_container.DEFINITIONS.clear()
if getattr(def_container, '_initializing', False):
del def_container._initializing
transaction.commit()
except ConflictError:
# The first worker did the changes, simply abort to get the changes.
transaction.abort()
# After the restart of the application, we always need to resync
# the node_definition attributes to be the node definition instances
# currently in ZODB.
for definition in def_container.definitions:
for node in definition.nodes:
for context in getattr(node, 'contexts', []):
# context here is a class, we set the class attribute
# node_definition to the current node definition in ZODB
context.node_definition = node
registry.notify(DatabaseOpenedWithRoot(root._p_jar.db()))
manager.pop()
开发者ID:ecreall,项目名称:dace,代码行数:70,代码来源:subscribers.py
示例17: tearDown
def tearDown(self, app):
manager.pop()
app._p_jar.close()
开发者ID:ecreall,项目名称:dace,代码行数:3,代码来源:util.py
示例18: closer
def closer():
threadlocal_manager.pop()
开发者ID:7924102,项目名称:pyramid,代码行数:2,代码来源:scripting.py
示例19: view_callable
msg = why[0]
except:
msg = ''
# repoze.bfg.message docs-deprecated in Pyramid 1.0
environ['repoze.bfg.message'] = msg
result = view_callable(why, request)
# process the response
response = registry.queryAdapterOrSelf(result, IResponse)
if response is None:
raise ValueError(
'Could not convert view return value "%s" into a '
'response object' % (result,))
has_listeners and registry.notify(NewResponse(request,response))
if request.response_callbacks:
request._process_response_callbacks(response)
finally:
if request is not None and request.finished_callbacks:
request._process_finished_callbacks()
return response(request.environ, start_response)
finally:
manager.pop()
开发者ID:cjw296,项目名称:pyramid,代码行数:29,代码来源:router.py
示例20: clear_manager
def clear_manager(signum=None, frame=None):
manager.pop()
开发者ID:j1z0,项目名称:snovault,代码行数:2,代码来源:mpindexer.py
注:本文中的pyramid.threadlocal.manager.pop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论