本文整理汇总了Python中pyramid.threadlocal.manager.pop函数的典型用法代码示例。如果您正苦于以下问题:Python pop函数的具体用法?Python pop怎么用?Python pop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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()
示例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()
示例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
示例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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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()
示例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()
示例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()
示例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?
示例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
#.........这里部分代码省略.........