• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python messages.create_request_from_environ函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_child_route_creation

    def test_child_route_creation(self):
        router = Router({
            'home': {
                'path': '/'
            },
            'parent': {
                'path': '/parent',
                'children': {
                    'child_one': {
                        'path': '/child_one',
                        'children': {
                            'sub_child': {
                                'path': '/test'
                            }
                        }
                    },
                    'child_two': {
                        'path': '/child_two'
                    }
                }
            }
        })
        assert len(router) == 5

        request = create_request_from_environ(sample_environ(PATH_INFO='/child_one'))
        matches = router.matches(request)
        assert len(matches) == 0

        request = create_request_from_environ(sample_environ(PATH_INFO='/parent/child_one'))
        matches = router.matches(request)
        assert len(matches) == 1

        assert router.assemble('parent/child_one/sub_child') == '/parent/child_one/test'
开发者ID:strogo,项目名称:watson-framework,代码行数:33,代码来源:test_routing.py


示例2: test_mandatory_segment_match

 def test_mandatory_segment_match(self):
     route = Route("search", path='/search/:keyword')
     invalid_request = create_request_from_environ(sample_environ(PATH_INFO='/searching'))
     valid_request_no_param = create_request_from_environ(sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request).matched
     assert not route.match(valid_request_no_param).matched
     assert route.match(valid_request_with_param).matched
开发者ID:erhuabushuo,项目名称:watson,代码行数:8,代码来源:test_routing.py


示例3: test_accept_method_match

 def test_accept_method_match(self):
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', REQUEST_METHOD='POST'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', REQUEST_METHOD='GET'))
     route = Route(name='test', path='/test', accepts=('POST',))
     assert route.match(valid_request)
     assert not route.match(invalid_request)
开发者ID:enigma,项目名称:watson,代码行数:8,代码来源:test_routing.py


示例4: test_static_match

 def test_static_match(self):
     route = Route(name='home', path='/')
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test'))
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
开发者ID:enigma,项目名称:watson,代码行数:8,代码来源:test_routing.py


示例5: test_subdomain_match

 def test_subdomain_match(self):
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test',
                        SERVER_NAME='clients.test.com'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', SERVER_NAME='clients2.test.com'))
     route = Route(name='test', path='/test', subdomain='clients')
     assert route.match(valid_request)
     assert not route.match(invalid_request)
开发者ID:enigma,项目名称:watson,代码行数:9,代码来源:test_routing.py


示例6: test_format_match

 def test_format_match(self):
     valid_request = create_request_from_environ(sample_environ(PATH_INFO='/dump', HTTP_ACCEPT='application/json'))
     invalid_request = create_request_from_environ(sample_environ(PATH_INFO='/dump', HTTP_ACCEPT='application/xml'))
     valid_request_segment = create_request_from_environ(sample_environ(PATH_INFO='/dump.json'))
     route = Route(name='json', path='/dump', requires={'format': 'json'})
     route_format = Route(name='json', path='/dump.:format', requires={'format': 'json'})
     assert route.match(valid_request).matched
     assert not route.match(invalid_request).matched
     assert route_format.match(valid_request_segment).matched
开发者ID:erhuabushuo,项目名称:watson,代码行数:9,代码来源:test_routing.py


示例7: test_optional_segment_with_defaults

 def test_optional_segment_with_defaults(self):
     route = Route(name="search", path='/search[/:keyword]', defaults={'keyword': 'blah'})
     invalid_request = create_request_from_environ(sample_environ(PATH_INFO='/searching'))
     valid_request = create_request_from_environ(sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(sample_environ(PATH_INFO='/search/test'))
     valid_request_with_default = route.match(valid_request)
     assert not route.match(invalid_request).matched
     assert valid_request_with_default.matched
     assert valid_request_with_default.params == {'keyword': 'blah'}
     assert route.match(valid_request_with_param).matched
开发者ID:erhuabushuo,项目名称:watson,代码行数:10,代码来源:test_routing.py


示例8: test_optional_segment_match

 def test_optional_segment_match(self):
     route = Route(name="search", path='/search[/:keyword]')
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/searching'))
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
     assert route.match(valid_request_with_param)
开发者ID:enigma,项目名称:watson,代码行数:11,代码来源:test_routing.py


示例9: test_optional_segment_with_required

 def test_optional_segment_with_required(self):
     route = Route(
         name="search",
         path='/search[/:keyword]',
         requires={'keyword': 'blah'})
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search/blah'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
开发者ID:enigma,项目名称:watson,代码行数:11,代码来源:test_routing.py


示例10: test_requires_get_variables

    def test_requires_get_variables(self):
        route = Route(name='test', path='/', requires={'test': '.*'})
        request = create_request_from_environ(sample_environ(
            PATH_INFO='/',
            QUERY_STRING='test=blah&something=test'))
        match = route.match(request)
        assert match

        request = create_request_from_environ(sample_environ(
            PATH_INFO='/',
            QUERY_STRING='tesst=blah'))
        match = route.match(request)
        assert not match
开发者ID:strogo,项目名称:watson-framework,代码行数:13,代码来源:test_routing.py


示例11: run

 def run(self, environ, start_response):
     request = create_request_from_environ(environ,
                                           self.config['session']['class'],
                                           self.config['session'].get('options'))
     try:
         route_result = self.dispatcher.trigger(Event(events.ROUTE_MATCH, target=self, params={
             'request': request,
             'router': self.container.get('router')
         }))
         route_match = route_result.first()
     except ApplicationError as exc:
         route_match = None
         response, view_model = self.__raise_exception_event(exception=exc, request=request)
     if route_match:
         try:
             dispatch_event = Event(events.DISPATCH_EXECUTE, target=self, params={
                 'route_match': route_match,
                 'request': request,
                 'container': self.container
             })
             dispatch_result = self.dispatcher.trigger(dispatch_event)
             response = dispatch_event.params['controller_class'].response
             view_model = dispatch_result.first()
         except ApplicationError as exc:
             response, view_model = self.__raise_exception_event(exception=exc, request=request, route_match=route_match)
     if not isinstance(view_model, Response):
         try:
             self.__render(request=request, response=response, view_model=view_model)
         except ApplicationError as exc:
             response, view_model = self.__raise_exception_event(exception=exc, request=request, route_match=route_match)
             self.__render(request=request, response=response, view_model=view_model)
     start_response(*response.start())
     return [response()]
开发者ID:erhuabushuo,项目名称:watson,代码行数:33,代码来源:applications.py


示例12: test_is_secure

 def test_is_secure(self):
     environ = sample_environ(HTTPS='HTTPS')
     environ['wsgi.url_scheme'] = 'https'
     request = create_request_from_environ(environ)
     assert str(
         request) == 'GET https://127.0.0.1:80/ HTTP/1.1\r\nHost: 127.0.0.1\r\nHttps: HTTPS\r\n\r\n'
     assert request.is_secure()
开发者ID:enigma,项目名称:watson,代码行数:7,代码来源:test_messages.py


示例13: test_create_put_from_environ

 def test_create_put_from_environ(self):
     environ = sample_environ(REQUEST_METHOD='POST')
     environ['wsgi.input'] = BufferedReader(
         BytesIO(b'HTTP_REQUEST_METHOD=PUT'))
     request = create_request_from_environ(environ)
     assert request.post['HTTP_REQUEST_METHOD'] == 'PUT'
     assert request.is_method('PUT')
开发者ID:enigma,项目名称:watson,代码行数:7,代码来源:test_messages.py


示例14: execute

 def execute(self):
     try:
         router = self.container.get('router')
         if not router.routes:
             raise ConsoleError('There are no routes associated with the application.')
         if self.parsed_args.url:
             environ = {}
             util.setup_testing_defaults(environ)
             environ.update({
                 'REQUEST_METHOD': self.parsed_args.method or 'GET',
                 'HTTP_ACCEPT': self.parsed_args.format or 'text/html',
                 'PATH_INFO': self.parsed_args.url,
                 'SERVER_NAME': self.parsed_args.server or '127.0.0.1'
             })
             request = create_request_from_environ(environ)
             matches = router.matches(request)
             if matches:
                 sys.stdout.write(colors.header('Displaying {0} matching routes for the application:\n'.format(len(matches))))
                 for match in matches:
                     sys.stdout.write('{0}\t\t\{1}\t\t{2}\n'.format(colors.ok_green(match.route.name), match.route.path, match.route.regex.pattern))
             else:
                 raise ConsoleError('There are no matching routes.')
         else:
             sys.stdout.write(colors.header('Displaying {0} routes for the application:\n'.format(len(router))))
             for name, route in router:
                 sys.stdout.write('{0}\t\t{1}\n'.format(name, route.path))
     except ConsoleError:
         raise
     except:
         _no_application_error()
开发者ID:erhuabushuo,项目名称:watson,代码行数:30,代码来源:application.py


示例15: create_event

 def create_event(self, **kwargs):
     router = Router({"home": {"path": "/"}})
     environ = {}
     util.setup_testing_defaults(environ)
     environ.update(**kwargs)
     event = Event("TestEvent", params={"router": router, "request": create_request_from_environ(environ)})
     return event
开发者ID:erhuabushuo,项目名称:watson,代码行数:7,代码来源:test_listeners.py


示例16: test_session_from_https_request

 def test_session_from_https_request(self):
     environ = sample_environ(HTTPS='HTTPS')
     request = create_request_from_environ(environ)
     assert request.is_secure()
     request.session_to_cookie()
     cookie = request.cookies[sessions.COOKIE_KEY]
     assert cookie['httponly']
     assert cookie['secure']
开发者ID:erhuabushuo,项目名称:watson,代码行数:8,代码来源:test_init.py


示例17: setup

 def setup(self):
     environ = sample_environ(
         HTTP_COOKIE='watson.session=123456;',
         REQUEST_METHOD='POST')
     environ['wsgi.input'] = BufferedReader(
         BytesIO(b'form_csrf_token=123456&test=blah'))
     self.request = create_request_from_environ(
         environ, 'watson.http.sessions.Memory')
开发者ID:enigma,项目名称:watson,代码行数:8,代码来源:test_forms.py


示例18: test_create_mutable

 def test_create_mutable(self):
     environ = sample_environ()
     environ['REQUEST_METHOD'] = 'POST'
     environ['wsgi.input'] = BufferedReader(BytesIO(b'HTTP_REQUEST_METHOD=PUT'))
     request = create_request_from_environ(environ)
     new_request = copy(request)
     assert isinstance(request.post, ImmutableMultiDict)
     assert isinstance(new_request.post, MultiDict)
开发者ID:erhuabushuo,项目名称:watson,代码行数:8,代码来源:test_messages.py


示例19: simple_request_response

def simple_request_response(environ, start_response):
    setup_testing_defaults(environ)

    request = create_request_from_environ(environ)
    response = Response(200, body="Hello World!")

    start_response(*response.start())
    return [response()]
开发者ID:erhuabushuo,项目名称:watson,代码行数:8,代码来源:simple_request_response.py


示例20: create_event

 def create_event(self, **kwargs):
     router = Router({'home': {'path': '/'}})
     environ = {}
     util.setup_testing_defaults(environ)
     environ.update(**kwargs)
     event = Event(
         'TestEvent',
         params={'router': router,
                 'request': create_request_from_environ(environ)})
     return event
开发者ID:enigma,项目名称:watson,代码行数:10,代码来源:test_listeners.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python messages.Request类代码示例发布时间:2022-05-26
下一篇:
Python imports.get_qualified_name函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap