本文整理匯總了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
示例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')
示例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')
示例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
示例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)
示例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
#
示例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"}'
示例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'}
示例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'
示例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())
示例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')
示例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
示例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
示例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)
示例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'])
)