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


Python request.apply_request_extensions函数代码示例

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


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


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