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


Python wrappers.Request方法代码示例

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


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

示例1: request

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def request(self, method: str, url: str, body=None, headers=None,
                **client_options):
        client = self.create_client(**client_options)
        url, headers, body = client.sign(url, method, body, headers)
        request = urllib.request.Request(url, body, headers, method=method)
        try:
            return urllib.request.urlopen(request)
        except urllib.error.HTTPError as e:
            logger = logging.getLogger(__name__ + '.StashTeam.request')
            logger.exception(
                '[%s %s] %s\nrequest headers: %r\nrequest body: %r\n'
                'client_options: %r\nresponse status: %r\n'
                'response headers: %r\nresponse body: %r',
                method, url, e, headers, body, client_options,
                e.code, dict(e.headers), e.read()
            )
            raise 
开发者ID:spoqa,项目名称:geofront,代码行数:19,代码来源:stash.py

示例2: _serve_images

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def _serve_images(self, request):
    """Given a tag and list of runs, serve a list of images.

    Note that the images themselves are not sent; instead, we respond with URLs
    to the images. The frontend should treat these URLs as opaque and should not
    try to parse information about them or generate them itself, as the format
    may change.

    Args:
      request: A werkzeug.wrappers.Request object.

    Returns:
      A werkzeug.Response application.
    """
    tag = request.args.get('tag')
    run = request.args.get('run')

    images = self._multiplexer.Images(run, tag)
    response = self._image_response_for_run(images, run, tag)
    return http_util.Respond(request, response, 'application/json') 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:application.py

示例3: _serve_audio

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def _serve_audio(self, request):
    """Given a tag and list of runs, serve a list of audio.

    Note that the audio clips themselves are not sent; instead, we respond with
    URLs to the audio. The frontend should treat these URLs as opaque and should
    not try to parse information about them or generate them itself, as the
    format may change.

    Args:
      request: A werkzeug.wrappers.Request object.

    Returns:
      A werkzeug.Response application.
    """
    tag = request.args.get('tag')
    run = request.args.get('run')

    audio_list = self._multiplexer.Audio(run, tag)
    response = self._audio_response_for_run(audio_list, run, tag)
    return http_util.Respond(request, response, 'application/json') 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:application.py

示例4: single_serve

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def single_serve(message=None, port=5000):
    import logging
    from werkzeug.wrappers import Request, Response
    from werkzeug.serving import run_simple

    log = logging.getLogger('werkzeug')
    log.setLevel(logging.ERROR)

    captured = {}

    def application(environ, start_response):
        request = Request(environ)
        request.environ.get('werkzeug.server.shutdown')()
        captured.update(dict(request.args.items()))
        if message:
            print(message)
        response = Response(message, mimetype='text/plain')
        return response(environ, start_response)

    run_simple('localhost', port, application)
    return captured 
开发者ID:debrouwere,项目名称:google-analytics,代码行数:23,代码来源:server.py

示例5: pre_process

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def pre_process(self, environ):
        request = Request(environ)
        for prefix in self.excluded_paths:
            if request.path.startswith(prefix):
                return

        cookie = request.cookies.get(self.name)
        if not cookie:
            return

        session = SecureCookie.unserialize(cookie, self.secret)

        if "session_token" not in session:
            return

        if not self.fetch_user:
            user = User()
            user._session_token = session["session_token"]
            user.id = session["uid"]
            User.set_current(user)
        else:
            user = User.become(session["session_token"])
            User.set_current(user) 
开发者ID:leancloud,项目名称:python-sdk,代码行数:25,代码来源:cookie_session.py

示例6: test_python3_urllib_request_normalization

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def test_python3_urllib_request_normalization(httpbin):
    raw_request = urllib.request.Request(
        httpbin.url + '/get',
        headers={'Content-Type': 'application/json'},
    )

    request = normalize_request(raw_request)

    assert request.path == '/get'
    assert request.content_type == 'application/json'
    assert request.url == httpbin.url + '/get'
    assert request.method == 'get'


#
# Test tornado request object
# 
开发者ID:pipermerriam,项目名称:flex,代码行数:19,代码来源:test_request_normalization.py

示例7: test_falcon_request_normalization

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def test_falcon_request_normalization(httpbin):
    import falcon
    from falcon.testing.helpers import create_environ

    env = create_environ(
        path='/put',
        query_string='key=val',
        host=httpbin.host,
        port=httpbin.port,
        headers={'Content-Type': 'application/json'},
        body=b'{"key2": "val2"}',
        method='PUT',
    )
    raw_request = falcon.Request(env)

    request = normalize_request(raw_request)

    assert request.path == '/put'
    assert request.content_type == 'application/json'
    assert request.url == httpbin.url + '/put?key=val'
    assert request.method == 'put'
    assert request.body == '{"key2": "val2"}' 
开发者ID:pipermerriam,项目名称:flex,代码行数:24,代码来源:test_request_normalization.py

示例8: test_werkzeug_request_normalization

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def test_werkzeug_request_normalization(httpbin):
    from werkzeug.test import create_environ
    from werkzeug.wrappers import Request

    env = create_environ(
        path='/put',
        base_url=httpbin.url,
        query_string='key=val',
        headers={'Content-Type': 'application/json'},
        data=b'{"key2": "val2"}',
        method='PUT',
    )
    raw_request = Request(env)
    request = normalize_request(raw_request)

    assert request.path == '/put'
    assert request.content_type == 'application/json'
    assert request.url == httpbin.url + '/put?key=val'
    assert request.method == 'put'
    assert request.data == {'key2': 'val2'} 
开发者ID:pipermerriam,项目名称:flex,代码行数:22,代码来源:test_request_normalization.py

示例9: test_werkzeug_response_normalization

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def test_werkzeug_response_normalization(httpbin):
    from werkzeug.wrappers import Request, Response
    from werkzeug.test import create_environ

    raw_request = Request(create_environ(
        path='/get',
        base_url=httpbin.url,
        query_string='key=val',
        method='GET',
    ))

    raw_response = Response(
        response=b'{"key2": "val2"}',
        content_type='application/json',
    )

    response = normalize_response(raw_response, raw_request)

    assert response.path == '/get'
    assert response.content_type == 'application/json'
    assert response.url == httpbin.url + '/get?key=val'
    assert response.status_code == '200' 
开发者ID:pipermerriam,项目名称:flex,代码行数:24,代码来源:test_response_normalization.py

示例10: test_extracting_filestream_from_request

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def test_extracting_filestream_from_request(self):
        # GIVEN a file to upload.
        with tempfile.NamedTemporaryFile('w+b') as f:
            # GIVEN the file's contents.
            content = b'foo'
            f.write(content)
            f.seek(0)

            # GIVEN a POST request containing the file to upload.
            builder = EnvironBuilder(method='POST', data={'file': f})
            request = Request(builder.get_environ())

            # WHEN we process the request.
            filestream = util.file_from_request(request)

            # THEN the file-stream should correspond to the provided file.
            self.assertEqual(content, filestream.read()) 
开发者ID:rgalanakis,项目名称:hostthedocs,代码行数:19,代码来源:test_util.py

示例11: on_sourceicons

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def on_sourceicons(self, _: Request) -> Response:
        imagecrawlers: Set[Type[BaseImageCrawler]] = {
            type(crawler.imagecrawler)
            for crawler
            in self.imageserver.core.crawlers
        }
        names_icons_list: List[Tuple[str, str]] = [
            (_type_module_name_str(imagecrawler), icon)
            for imagecrawler, icon
            in (
                (imagecrawler, imagecrawler.info().icon_url)
                for imagecrawler
                in imagecrawlers
            )
            if icon
        ]
        # cannot use dict for `names_icons_list` in template. will break the template occasionally :-/
        template = Template(filename=path_join(self._TEMPLATE_FILES, 'css', 'sourceIcons.css'))
        css = template.render(names_icons_list=names_icons_list)
        return Response(css, mimetype='text/css') 
开发者ID:k4cg,项目名称:nichtparasoup,代码行数:22,代码来源:webserver.py

示例12: test_publish_basic

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def test_publish_basic(self, fixture_working_dir, mock_create_labbooks_no_lfs):

        # Mock the request context so a fake authorization header is present
        builder = EnvironBuilder(path='/labbook', method='POST', headers={'Authorization': 'Bearer AJDFHASD'})
        env = builder.get_environ()
        req = Request(environ=env)

        im = InventoryManager(mock_create_labbooks_no_lfs[0])
        test_user_lb = im.load_labbook('default', 'default', 'labbook1')

        publish_query = f"""
        mutation c {{
            publishLabbook(input: {{
                labbookName: "labbook1",
                owner: "default"
            }}) {{
                jobKey
            }}
        }}
        """

        r = mock_create_labbooks_no_lfs[2].execute(publish_query, context_value=req)
        assert 'errors' not in r
        # TODO - Pause and wait for bg job to finish
        #assert r['data']['publishLabbook']['success'] is True 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:27,代码来源:test_mutations_labbooksharing.py

示例13: _init_app

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def _init_app(self, middleware=None):
        """Initialize a WSGI application for handling POST to '/'.

        `middleware` may be provided as WSGI middleware.

        """
        routes = routing.Map([
            routing.Rule('/', endpoint=self._handle_inference),
            routing.Rule('/ping', endpoint=self._handle_ping),
            routing.Rule('/shutdown', endpoint=self._handle_shutdown),
        ])
        def app(env, start_resp):
            """WSGI application to handle server requests.

            """
            urls = routes.bind_to_environ(env)
            try:
                handler, _kw = urls.match()
                req = Request(env)
                if middleware:
                    return middleware(handler, req)(env, start_resp)
                return handler(req)(env, start_resp)
            except HTTPException as e:
                return e(env, start_resp)
        return app 
开发者ID:iitzco,项目名称:tfserve,代码行数:27,代码来源:tfserve.py

示例14: worker_setup

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def worker_setup(self, worker_ctx):
        if self._do_nothing:
            return
        tracked_request = TrackedRequest.instance()
        tracked_request.is_real_request = True

        # Get HTTP details for HTTP handlers
        if isinstance(worker_ctx.entrypoint, HttpRequestHandler):
            try:
                request = worker_ctx.args[0]
            except IndexError:
                pass
            else:
                if isinstance(request, Request):
                    werkzeug_track_request_data(request, tracked_request)

        operation = (
            "Controller/"
            + worker_ctx.service.name
            + "."
            + worker_ctx.entrypoint.method_name
        )
        tracked_request.start_span(operation=operation, should_capture_backtrace=False) 
开发者ID:scoutapp,项目名称:scout_apm_python,代码行数:25,代码来源:nameko.py

示例15: authenticate

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import Request [as 别名]
def authenticate(self,
                     state,
                     requested_redirect_url: str,
                     wsgi_environ: Mapping[str, object]) -> Identity:
        logger = logging.getLogger(__name__ + '.StashTeam.authenticate')
        logger.debug('state = %r', state)
        try:
            oauth_token, oauth_token_secret = state
        except ValueError:
            raise AuthenticationError()
        req = Request(wsgi_environ, populate_request=False, shallow=True)
        args = cast(ImmutableMultiDict, req.args)
        logger.debug('req.args = %r', args)
        if args.get('oauth_token') != oauth_token:
            raise AuthenticationError()
        response = self.request(
            'POST', self.ACCESS_TOKEN_URL.format(self),
            resource_owner_key=oauth_token,
            resource_owner_secret=oauth_token_secret
        )
        access_token = url_decode_stream(response)
        logger.debug('access_token = %r', access_token)
        response.close()
        response = self.request(
            'GET', self.USER_URL.format(self),
            resource_owner_key=access_token['oauth_token'],
            resource_owner_secret=access_token['oauth_token_secret']
        )
        whoami = response.read().decode('utf-8')
        return Identity(
            type(self),
            self.USER_PROFILE_URL.format(self, whoami),
            (access_token['oauth_token'], access_token['oauth_token_secret'])
        ) 
开发者ID:spoqa,项目名称:geofront,代码行数:36,代码来源:stash.py


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