本文整理汇总了Python中pyramid.request.apply_request_extensions函数的典型用法代码示例。如果您正苦于以下问题:Python apply_request_extensions函数的具体用法?Python apply_request_extensions怎么用?Python apply_request_extensions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apply_request_extensions函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: pyramid_config
def pyramid_config(self, pyramid_config, pyramid_request):
from pyramid.request import apply_request_extensions
pyramid_config.add_request_method(FeatureRequestProperty,
name='feature',
reify=True)
apply_request_extensions(pyramid_request)
return pyramid_config
开发者ID:chinmaygghag,项目名称:h,代码行数:7,代码来源:feature_test.py
示例2: test_log
def test_log(self):
# Logger
logger = logging.getLogger(__name__)
logger.level = logging.INFO
stream = StringIO()
stream_handler = logging.StreamHandler(stream)
logger.addHandler(stream_handler)
# Actual test
request = testing.DummyRequest()
apply_request_extensions(request)
self.assertTrue(request.authenticated_userid, 'jane')
obj = self._cut(request)
# Patch logger
obj.logger = logger
obj.add('uid', 'darth', [ROLE_VIEWER], [ROLE_OWNER])
payload = obj.prepare()
formatted = obj.format(payload)
try:
obj.log(formatted)
stream.seek(0)
output = stream.read()
finally:
logger.removeHandler(stream_handler)
self.assertIn('"+": ["role:Viewer"]', output)
self.assertIn('"-": ["role:Owner"]', output)
self.assertIn('"jane"', output)
# Make sure json can read this
json_row = loads(output)
self.assertIn('contexts', json_row)
开发者ID:ArcheProject,项目名称:Arche,代码行数:29,代码来源:test_roles.py
示例3: set_snapshot
def set_snapshot(xmin, snapshot_id):
global current_xmin_snapshot_id
if current_xmin_snapshot_id == (xmin, snapshot_id):
return
clear_snapshot()
current_xmin_snapshot_id = (xmin, snapshot_id)
while True:
txn = transaction.begin()
txn.doom()
if snapshot_id is not None:
txn.setExtendedInfo('snapshot_id', snapshot_id)
session = app.registry[DBSESSION]()
connection = session.connection()
db_xmin = connection.execute(
"SELECT txid_snapshot_xmin(txid_current_snapshot());").scalar()
if db_xmin >= xmin:
break
transaction.abort()
log.info('Waiting for xmin %r to reach %r', db_xmin, xmin)
time.sleep(0.1)
registry = app.registry
request = app.request_factory.blank('/_indexing_pool')
request.registry = registry
request.datastore = 'database'
apply_request_extensions(request)
request.invoke_subrequest = app.invoke_subrequest
request.root = app.root_factory(request)
request._stats = {}
manager.push({'request': request, 'registry': registry})
开发者ID:ENCODE-DCC,项目名称:snovault,代码行数:31,代码来源:mpindexer.py
示例4: request_context
def request_context(self, environ):
"""
Create a new request context from a WSGI environ.
The request context is used to push/pop the threadlocals required
when processing the request. It also contains an initialized
:class:`pyramid.interfaces.IRequest` instance using the registered
:class:`pyramid.interfaces.IRequestFactory`. The context may be
used as a context manager to control the threadlocal lifecycle:
.. code-block:: python
with router.request_context(environ) as request:
...
Alternatively, the context may be used without the ``with`` statement
by manually invoking its ``begin()`` and ``end()`` methods.
.. code-block:: python
ctx = router.request_context(environ)
request = ctx.begin()
try:
...
finally:
ctx.end()
"""
request = self.request_factory(environ)
request.registry = self.registry
request.invoke_subrequest = self.invoke_subrequest
extensions = self.request_extensions
if extensions is not None:
apply_request_extensions(request, extensions=extensions)
return RequestContext(request)
开发者ID:Pylons,项目名称:pyramid,代码行数:35,代码来源:router.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: make_faux_request
def make_faux_request(self):
"""In the case we can't use real request object, make a new request from registry given to Celery."""
# Real request has been already committed in this point,
# so create a faux request to satisfy the presence of dbsession et. al.
registry = self.app.registry
request = _make_request("/", registry)
apply_request_extensions(request)
return request
开发者ID:frispete,项目名称:websauna,代码行数:8,代码来源:tasks.py
示例7: make_request
def make_request(self, environ):
request = self.request_factory(environ)
request.registry = self.registry
request.invoke_subrequest = self.invoke_subrequest
extensions = self.request_extensions
if extensions is not None:
apply_request_extensions(request, extensions=extensions)
return request
开发者ID:goodwillcoding,项目名称:pyramid,代码行数:8,代码来源:router.py
示例8: _fixture
def _fixture(self):
from arche.api import Root
request = testing.DummyRequest()
apply_request_extensions(request)
request.root = root = Root()
self.config.begin(request)
return {'closer': object, 'root': root,
'registry': self.config.registry, 'request': request}
开发者ID:ArcheProject,项目名称:Arche,代码行数:8,代码来源:test_catalog.py
示例9: setUp
def setUp(self):
self.config = testing.setUp()
self.config.include('arche.testing')
self.config.include('voteit.debate.schemas')
self.config.include('voteit.debate.models')
self.request = testing.DummyRequest()
apply_request_extensions(self.request)
self.config.begin(self.request)
开发者ID:VoteIT,项目名称:voteit.debate,代码行数:8,代码来源:test_speaker_lists.py
示例10: __init__
def __init__(self, client_id):
self.client_id = client_id
self.terminated = False
self.filter = mock.MagicMock()
self.send = mock.MagicMock()
# Each fake socket needs its own request, so can't use the
# pyramid_request fixture.
self.request = DummyRequest(db=mock.sentinel.db_session)
apply_request_extensions(self.request)
开发者ID:djcun95,项目名称:h,代码行数:9,代码来源:messages_test.py
示例11: test_prepare_was_not_really_removed
def test_prepare_was_not_really_removed(self):
request = testing.DummyRequest()
apply_request_extensions(request)
self.assertTrue(request.authenticated_userid, 'jane')
obj = self._cut(request)
# Removing and adding (which shouldn't happen...) should not generate an entry.
obj.add('uid', 'darth', [ROLE_VIEWER], [])
obj.add('uid', 'darth', [], [ROLE_VIEWER])
self.assertEqual(obj.prepare(), {})
开发者ID:ArcheProject,项目名称:Arche,代码行数:9,代码来源:test_roles.py
示例12: dummy_request
def dummy_request(root, registry, app):
from pyramid.request import apply_request_extensions
request = app.request_factory.blank('/dummy')
request.root = root
request.registry = registry
request._stats = {}
request.invoke_subrequest = app.invoke_subrequest
apply_request_extensions(request)
return request
开发者ID:kidaa,项目名称:encoded,代码行数:9,代码来源:conftest.py
示例13: _fixture
def _fixture(self):
from arche.resources import User
root = barebone_fixture(self.config)
root['users']['jane'] = User(email = '[email protected]')
request = testing.DummyRequest()
apply_request_extensions(request)
self.config.begin(request)
request.root = root
return root, request
开发者ID:ArcheProject,项目名称:Arche,代码行数:9,代码来源:test_reference_guard.py
示例14: test_format
def test_format(self):
request = testing.DummyRequest()
apply_request_extensions(request)
self.assertTrue(request.authenticated_userid, 'jane')
obj = self._cut(request)
obj.add('uid', 'darth', ['Sith', 'Dark', ROLE_VIEWER], ['Puppies'])
payload = obj.prepare()
formatted = obj.format(payload)
self.assertIn('{"+": ["Sith", "Dark", "role:Viewer"]', formatted)
开发者ID:ArcheProject,项目名称:Arche,代码行数:9,代码来源:test_roles.py
示例15: pyramid_config
def pyramid_config(pyramid_settings, pyramid_request):
"""Pyramid configurator object."""
with testing.testConfig(request=pyramid_request,
settings=pyramid_settings) as config:
# Include pyramid_services so it's easy to set up fake services in tests
config.include('pyramid_services')
apply_request_extensions(pyramid_request)
yield config
开发者ID:nlisgo,项目名称:h,代码行数:9,代码来源:conftest.py
示例16: test_get_read_count
def test_get_read_count(self):
request = testing.DummyRequest()
self.config.include('voteit.core.helpers')
apply_request_extensions(request)
obj = self._cut(testing.DummyModel(uid='hi'), request)
obj.change('Dummy', 1, 'robin')
self.assertEqual(obj.get_read_count('Dummy', 'robin'), 1)
obj.change('Dummy', -2, 'robin')
self.assertEqual(obj.get_read_count('Dummy', 'robin'), -1)
obj.change('Dummy', +3, 'robin')
self.assertEqual(obj.get_read_count('Dummy', 'robin'), 2)
开发者ID:VoteIT,项目名称:voteit.core,代码行数:11,代码来源:test_read_names.py
示例17: prepare
def prepare(request=None, registry=None):
""" This function pushes data onto the Pyramid threadlocal stack
(request and registry), making those objects 'current'. It
returns a dictionary useful for bootstrapping a Pyramid
application in a scripting environment.
``request`` is passed to the :app:`Pyramid` application root
factory to compute the root. If ``request`` is None, a default
will be constructed using the registry's :term:`Request Factory`
via the :meth:`pyramid.interfaces.IRequestFactory.blank` method.
If ``registry`` is not supplied, the last registry loaded from
:attr:`pyramid.config.global_registries` will be used. If you
have loaded more than one :app:`Pyramid` application in the
current process, you may not want to use the last registry
loaded, thus you can search the ``global_registries`` and supply
the appropriate one based on your own criteria.
The function returns a dictionary composed of ``root``,
``closer``, ``registry``, ``request`` and ``root_factory``. The
``root`` returned is the application's root resource object. The
``closer`` returned is a callable (accepting no arguments) that
should be called when your scripting application is finished
using the root. ``registry`` is the registry object passed or
the last registry loaded into
:attr:`pyramid.config.global_registries` if no registry is passed.
``request`` is the request object passed or the constructed request
if no request is passed. ``root_factory`` is the root factory used
to construct the root.
"""
if registry is None:
registry = getattr(request, 'registry', global_registries.last)
if registry is None:
raise ConfigurationError('No valid Pyramid applications could be '
'found, make sure one has been created '
'before trying to activate it.')
if request is None:
request = _make_request('/', registry)
# NB: even though _make_request might have already set registry on
# request, we reset it in case someone has passed in their own
# request.
request.registry = registry
threadlocals = {'registry':registry, 'request':request}
threadlocal_manager.push(threadlocals)
apply_request_extensions(request)
def closer():
threadlocal_manager.pop()
root_factory = registry.queryUtility(IRootFactory,
default=DefaultRootFactory)
root = root_factory(request)
if getattr(request, 'context', None) is None:
request.context = root
return {'root':root, 'closer':closer, 'registry':registry,
'request':request, 'root_factory':root_factory}
开发者ID:7924102,项目名称:pyramid,代码行数:54,代码来源:scripting.py
示例18: _fixture
def _fixture(self):
from arche.resources import Document
root = barebone_fixture(self.config)
root['source'] = source = Document()
source['a'] = Document()
source['a']['b'] = Document()
root['target'] = Document()
request = testing.DummyRequest()
request.root = root
apply_request_extensions(request)
self.config.begin(request)
return root, request
开发者ID:ArcheProject,项目名称:Arche,代码行数:12,代码来源:test_utils.py
示例19: dummy_request
def dummy_request(dbsession):
from webob.multidict import MultiDict
from pyramid.request import apply_request_extensions
req = testing.DummyRequest(base_url="http://testscaffold.com", dbsession=dbsession)
req.route_url = mock.Mock(return_value="/")
req.POST = MultiDict()
req.GET = MultiDict()
req.params = MultiDict()
req.session = mock.Mock()
apply_request_extensions(req)
return req
开发者ID:ergo,项目名称:testscaffold,代码行数:12,代码来源:tests_integration.py
示例20: test_add
def test_add(self):
request = testing.DummyRequest()
apply_request_extensions(request)
self.assertTrue(request.authenticated_userid, 'jane')
obj = self._cut(request)
obj.add('uid', 'darth', ['Sith', 'Dark', ROLE_VIEWER], ['Puppies'])
expected = {
'uid': {
'darth': {'new': frozenset(['Dark', 'Sith', 'role:Viewer']),
'old': frozenset(['Puppies'])},
}
}
self.assertEqual(obj.entries, expected)
开发者ID:ArcheProject,项目名称:Arche,代码行数:13,代码来源:test_roles.py
注:本文中的pyramid.request.apply_request_extensions函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论