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


Python Request.blank方法代码示例

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


在下文中一共展示了Request.blank方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: filemonitoring

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
    def filemonitoring(self):
        log = logging.getLogger(__name__)
        if self._request.params:
            # TODO: add this information to the file
            md5_enabled = True if 'withmd5' in self._request.params and self._request.params['withmd5'] == '0' else False
            all_files = self._request.params.getall('file')

            complete_file, filenames, folders = self._get_monitored_files(self._request.params['folder'] + '/')

            with transaction.manager:
                for f in all_files:
                    if f in complete_file:
                        log.debug('Skipping file {0}, because it is already monitored'.format(f))
                        continue
                    (path, filename) = os.path.split(f)
                    dbobj = MonitoredFile(path, filename, f)
                    DBSession.add(dbobj)
                DBSession.commit()
            files_not_mentioned = [c for c in complete_file if c not in all_files]
            # TODO: decide on this
            log.info('TODO: Still have to decide whether files which are not selected should be deleted or not.'
                     'Affected files would be: {0}'.format(files_not_mentioned))
        else:
            log.info('Got an empty request, going to redirect to start page')
            subreq = Request.blank('/')
            return self._request.invoke_subrequest(subreq)

        subreq = Request.blank(self._request.route_path('filebrowser'),
                               POST=dict(folder=self._request.params['folder'],
                                         currentfolder=self._request.params['currentfolder'],
                                         pathdescription='abs'))
        return self._request.invoke_subrequest(subreq)
开发者ID:meyerjo,项目名称:ClusterJobMonitor,代码行数:34,代码来源:fileviews.py

示例2: worker

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
 def worker(self, sem, q):
     log.info('Entering chapmand worker thread')
     while not self._shutdown:
         try:
             msg, state = q.get(timeout=0.25)
         except Empty:
             continue
         try:
             log.info('Received %r', msg)
             task = Task.from_state(state)
             # task.handle(msg, 25)
             if task.path:
                 req = Request.blank(task.path, method='CHAPMAN')
             else:
                 req = Request.blank(self._chapman_path, method='CHAPMAN')
             req.registry = self._registry
             req.environ['chapmand.task'] = task
             req.environ['chapmand.message'] = msg
             for x in self._app(req.environ, lambda *a,**kw:None):
                 pass
         except Exception as err:
             exc_log.exception('Unexpected error in worker thread: %r', err)
             time.sleep(self._sleep)
         finally:
             self._num_active_messages -= 1
             sem.release()
     log.info('Exiting chapmand worker thread')
开发者ID:synappio,项目名称:chapman,代码行数:29,代码来源:worker.py

示例3: test_it_intercept_redirect_nonredirect_code

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
 def test_it_intercept_redirect_nonredirect_code(self):
     request = Request.blank('/')
     request.remote_addr = '127.0.0.1'
     self.config.registry.settings['debugtoolbar.intercept_redirects'] = True
     request.registry = self.config.registry
     result = self._callFUT(request)
     self.assertTrue(result is self.response)
开发者ID:kashifpk,项目名称:pyramid_debugtoolbar,代码行数:9,代码来源:test_toolbar.py

示例4: test_call_view_exception_propagating

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
 def test_call_view_exception_propagating(self):
     from zope.interface import Interface
     from zope.interface import directlyProvides
     class IContext(Interface):
         pass
     from pyramid.interfaces import IRequest
     from pyramid.interfaces import IViewClassifier
     from pyramid.interfaces import IRequestFactory
     def rfactory(environ):
         return request
     self.registry.registerUtility(rfactory, IRequestFactory)
     from pyramid.request import Request
     request = Request.blank('/')
     context = DummyContext()
     directlyProvides(context, IContext)
     self._registerTraverserFactory(context, subpath=[''])
     response = DummyResponse()
     view = DummyView(response, raise_exception=RuntimeError)
     environ = self._makeEnviron()
     self._registerView(view, '', IViewClassifier, IRequest, IContext)
     router = self._makeOne()
     start_response = DummyStartResponse()
     self.assertRaises(RuntimeError, router, environ, start_response)
     # ``exception`` must be attached to request even if a suitable
     # exception view cannot be found
     self.assertEqual(request.exception.__class__, RuntimeError)
开发者ID:RyoAbe,项目名称:pyramid,代码行数:28,代码来源:test_router.py

示例5: test_hide_capabilities_set_get_capabilities_request

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
 def test_hide_capabilities_set_get_capabilities_request(self):
     request = Request.blank("/test?REQUEST=GetCapabilities")
     request.registry = get_current_registry()
     request.registry.settings = {
         "hide_capabilities": True
     }
     self.assertFalse(self.predicate(None, request))
开发者ID:yjacolin,项目名称:c2cgeoportal,代码行数:9,代码来源:test_mapserverproxy_route_predicate.py

示例6: test_attributes_are_none_with_blank_requests

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
 def test_attributes_are_none_with_blank_requests(self):
     request = Request.blank(path='/')
     context = RouteFactory(request)
     self.assertIsNone(context.object_id)
     self.assertIsNone(context.required_permission)
     self.assertIsNone(context.resource_name)
     self.assertIsNone(context.check_permission)
开发者ID:leplatrem,项目名称:cliquet,代码行数:9,代码来源:test_authorization.py

示例7: makeRequest

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
 def makeRequest(self, path):
     from pyramid.request import Request
     request = Request.blank(path)
     request.registry = self.registry
     subpath = filter(None, path.split('/'))
     request.matchdict = {'subpath': subpath}
     return request
开发者ID:chrisrossi,项目名称:jove,代码行数:9,代码来源:test_application.py

示例8: assert_cache_enabled

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
    def assert_cache_enabled(self, cache_factory):
        settings = {
            "boto3.sessions": "default",
            "boto3.clients": "s3",
            "boto3.client.s3.session": "default",
            "boto3.client.s3.service_name": "s3",
            "boto3.resources": "s3",
            "boto3.resource.s3.session": "default",
            "boto3.resource.s3.service_name": "s3",
            "boto3.cache_factory": cache_factory,
        }
        config = Configurator(settings=settings)
        config.include("pyramid_boto3")

        def aview(request):
            session = request.find_service(name="boto3.session.default")
            self.assertIsNotNone(session)
            s3cli = request.find_service(name="boto3.client.s3")
            self.assertIsNotNone(s3cli)
            s3res = request.find_service(name="boto3.resource.s3")
            self.assertIsNotNone(s3res)
            return "OK"

        config.add_view(aview, route_name="root", renderer="json")
        config.add_route("root", pattern="/")
        app = config.make_wsgi_app()
        request = Request.blank("/")
        response = request.get_response(app)
        self.assertEqual(response.json_body, "OK")
        del app
开发者ID:gjo,项目名称:pyramid_boto3,代码行数:32,代码来源:test_functional.py

示例9: test_cors_sets_allow_credentials_for_preflight_when_set

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
def test_cors_sets_allow_credentials_for_preflight_when_set(headers):
    request = Request.blank("/", method="OPTIONS", headers=headers)

    resp = request.get_response(wsgi_testapp)
    resp = set_cors_headers(request, resp, allow_credentials=True)

    assert resp.headers["Access-Control-Allow-Credentials"] == "true"
开发者ID:chrber,项目名称:h,代码行数:9,代码来源:cors_test.py

示例10: easy_link

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
def easy_link(request):
    for x in DBSession.query(EasyLinks).filter_by(name=request.matchdict['link']):
        subreq = Request.blank(x.path)
        subreq.cookies = request.cookies #pass authentication data
        response = request.invoke_subrequest(subreq)
        return response
    return HTTPNotFound()
开发者ID:,项目名称:,代码行数:9,代码来源:

示例11: _render_view_on_slot_event

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
def _render_view_on_slot_event(view_name, event, params):
    context = event.object
    request = event.request

    view_request = Request.blank(
        "{0}/{1}".format(request.path.rstrip('/'), view_name),
        base_url=request.application_url,
        POST=_encode(params),
        )

    post_items = request.POST.items()
    if post_items:
        view_request.POST.extend(post_items)

    # This is quite brittle:
    for name in REQUEST_ATTRS_TO_COPY:
        setattr(view_request, name, getattr(request, name))

    try:
        result = render_view(
            context,
            view_request,
            view_name,
            )
    except PredicateMismatch:
        return None
    else:
        return result.decode('utf-8')
开发者ID:mindreframer,项目名称:python-pyramid-stuff,代码行数:30,代码来源:slots.py

示例12: view_five

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
def view_five(request):
    subreq = Request.blank('/view_four')
    try:
        return request.invoke_subrequest(subreq, use_tweens=False)
    except ValueError:
        request.response.body = b'Value error raised'
        return request.response
开发者ID:JDeuce,项目名称:pyramid,代码行数:9,代码来源:__init__.py

示例13: view_three

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
def view_three(request):
    subreq = Request.blank('/view_four')
    try:
        return request.invoke_subrequest(subreq, use_tweens=True)
    except: # pragma: no cover
        request.response.body = b'Value error raised'
        return request.response
开发者ID:JDeuce,项目名称:pyramid,代码行数:9,代码来源:__init__.py

示例14: __init__

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
    def __init__(self, base_url, registry):
        """
        Create a new links service.

        :param base_url: the base URL for link construction
        :param registry: the registry in which to look up routes
        :type registry: pyramid.registry.Registry
        """
        self.base_url = base_url
        self.registry = registry

        # It would be absolutely fair if at this point you asked yourself any
        # of the following questions:
        #
        # - Why are we constructing a fake request here?
        # - Didn't we have a request and then discard it in the service
        #   factory?
        # - This looks really janky!
        #
        # Well, apart from the fact that the last one there isn't a question,
        # those are good questions. The reason for doing this is that we need
        # to be able to generate links to annotations in situations where we
        # don't necessarily have a request object around, such as in the
        # WebSocket server, or in a CLI command.
        #
        # In these situations, it should suffice to have an application
        # registry (for the routing table) and a base URL. The reason we
        # generate a request object is that this is the simplest and least
        # error-prone way to get access to the route_url function, which can
        # be used by link generators.
        self._request = Request.blank('/', base_url=base_url)
        self._request.registry = registry
开发者ID:gnott,项目名称:h,代码行数:34,代码来源:links.py

示例15: getDiscussionUrl

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import blank [as 别名]
 def getDiscussionUrl(self):
     from pyramid.request import Request
     req = Request.blank('/', base_url=self.discussion.get_base_url())
     #Celery didn't like this.  To revisit once we have virtual hosts
     #return req.route_url('home', discussion_slug=self.discussion.slug)
     return urljoin(
         self.discussion.get_base_url(), self.discussion.slug+'/')
开发者ID:iilab,项目名称:assembl,代码行数:9,代码来源:frontend_urls.py


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