本文整理匯總了Python中werkzeug.wrappers.BaseRequest.environ方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseRequest.environ方法的具體用法?Python BaseRequest.environ怎麽用?Python BaseRequest.environ使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.wrappers.BaseRequest
的用法示例。
在下文中一共展示了BaseRequest.environ方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_app_iter
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def get_app_iter(self, environ):
"""Returns the application iterator for the given environ. Depending
on the request method and the current status code the return value
might be an empty response rather than the one from the response.
If the request method is `HEAD` or the status code is in a range
where the HTTP specification requires an empty response, an empty
iterable is returned.
.. versionadded:: 0.6
:param environ: the WSGI environment of the request.
:return: a response iterable.
"""
status = self.status_code
if environ['REQUEST_METHOD'] == 'HEAD' or \
100 <= status < 200 or status in (204, 304):
iterable = ()
elif self.direct_passthrough:
if __debug__:
_warn_if_string(self.response)
return self.response
else:
iterable = self.iter_encoded()
return ClosingIterator(iterable, self.close)
示例2: get_wsgi_response
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def get_wsgi_response(self, environ):
"""Returns the final WSGI response as tuple. The first item in
the tuple is the application iterator, the second the status and
the third the list of headers. The response returned is created
specially for the given environment. For example if the request
method in the WSGI environment is ``'HEAD'`` the response will
be empty and only the headers and status code will be present.
.. versionadded:: 0.6
:param environ: the WSGI environment of the request.
:return: an ``(app_iter, status, headers)`` tuple.
"""
headers = self.get_wsgi_headers(environ)
app_iter = self.get_app_iter(environ)
return app_iter, self.status, headers.to_wsgi_list()
示例3: is_xhr
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def is_xhr(self):
"""True if the request was triggered via a JavaScript XMLHttpRequest.
This only works with libraries that support the ``X-Requested-With``
header and set it to "XMLHttpRequest". Libraries that do that are
prototype, jQuery and Mochikit and probably some more.
.. deprecated:: 0.13
``X-Requested-With`` is not standard and is unreliable.
"""
warn(DeprecationWarning(
'Request.is_xhr is deprecated. Given that the X-Requested-With '
'header is not a part of any spec, it is not reliable'
), stacklevel=2)
return self.environ.get(
'HTTP_X_REQUESTED_WITH', ''
).lower() == 'xmlhttprequest'
示例4: get_app_iter
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def get_app_iter(self, environ):
"""Returns the application iterator for the given environ. Depending
on the request method and the current status code the return value
might be an empty response rather than the one from the response.
If the request method is `HEAD` or the status code is in a range
where the HTTP specification requires an empty response, an empty
iterable is returned.
.. versionadded:: 0.6
:param environ: the WSGI environment of the request.
:return: a response iterable.
"""
status = self.status_code
if environ['REQUEST_METHOD'] == 'HEAD' or \
100 <= status < 200 or status in (204, 304, 412):
iterable = ()
elif self.direct_passthrough:
if __debug__:
_warn_if_string(self.response)
return self.response
else:
iterable = self.iter_encoded()
return ClosingIterator(iterable, self.close)
示例5: __init__
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def __init__(self, environ, populate_request=True, shallow=False):
self.environ = environ
if populate_request and not shallow:
self.environ['werkzeug.request'] = self
self.shallow = shallow
示例6: __repr__
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def __repr__(self):
# make sure the __repr__ even works if the request was created
# from an invalid WSGI environment. If we display the request
# in a debug session we don't want the repr to blow up.
args = []
try:
args.append("'%s'" % to_native(self.url, self.url_charset))
args.append('[%s]' % self.method)
except Exception:
args.append('(invalid WSGI environ)')
return '<%s %s>' % (
self.__class__.__name__,
' '.join(args)
)
示例7: from_values
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def from_values(cls, *args, **kwargs):
"""Create a new request object based on the values provided. If
environ is given missing values are filled from there. This method is
useful for small scripts when you need to simulate a request from an URL.
Do not use this method for unittesting, there is a full featured client
object (:class:`Client`) that allows to create multipart requests,
support for cookies etc.
This accepts the same options as the
:class:`~werkzeug.test.EnvironBuilder`.
.. versionchanged:: 0.5
This method now accepts the same arguments as
:class:`~werkzeug.test.EnvironBuilder`. Because of this the
`environ` parameter is now called `environ_overrides`.
:return: request object
"""
from werkzeug.test import EnvironBuilder
charset = kwargs.pop('charset', cls.charset)
kwargs['charset'] = charset
builder = EnvironBuilder(*args, **kwargs)
try:
return builder.get_request(cls)
finally:
builder.close()
示例8: want_form_data_parsed
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def want_form_data_parsed(self):
"""Returns True if the request method carries content. As of
Werkzeug 0.9 this will be the case if a content type is transmitted.
.. versionadded:: 0.8
"""
return bool(self.environ.get('CONTENT_TYPE'))
示例9: _load_form_data
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def _load_form_data(self):
"""Method used internally to retrieve submitted data. After calling
this sets `form` and `files` on the request object to multi dicts
filled with the incoming form data. As a matter of fact the input
stream will be empty afterwards. You can also call this method to
force the parsing of the form data.
.. versionadded:: 0.8
"""
# abort early if we have already consumed the stream
if 'form' in self.__dict__:
return
_assert_not_shallow(self)
if self.want_form_data_parsed:
content_type = self.environ.get('CONTENT_TYPE', '')
content_length = get_content_length(self.environ)
mimetype, options = parse_options_header(content_type)
parser = self.make_form_data_parser()
data = parser.parse(self._get_stream_for_parsing(),
mimetype, content_length, options)
else:
data = (self.stream, self.parameter_storage_class(),
self.parameter_storage_class())
# inject the values into the instance dict so that we bypass
# our cached_property non-data descriptor.
d = self.__dict__
d['stream'], d['form'], d['files'] = data
示例10: args
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def args(self):
"""The parsed URL parameters. By default an
:class:`~werkzeug.datastructures.ImmutableMultiDict`
is returned from this function. This can be changed by setting
:attr:`parameter_storage_class` to a different type. This might
be necessary if the order of the form data is important.
"""
return url_decode(wsgi_get_bytes(self.environ.get('QUERY_STRING', '')),
self.url_charset, errors=self.encoding_errors,
cls=self.parameter_storage_class)
示例11: cookies
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def cookies(self):
"""Read only access to the retrieved cookie values as dictionary."""
return parse_cookie(self.environ, self.charset,
self.encoding_errors,
cls=self.dict_storage_class)
示例12: headers
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def headers(self):
"""The headers from the WSGI environ as immutable
:class:`~werkzeug.datastructures.EnvironHeaders`.
"""
return EnvironHeaders(self.environ)
示例13: path
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def path(self):
"""Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed.
"""
raw_path = wsgi_decoding_dance(self.environ.get('PATH_INFO') or '',
self.charset, self.encoding_errors)
return '/' + raw_path.lstrip('/')
示例14: script_root
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def script_root(self):
"""The root path of the script without the trailing slash."""
raw_path = wsgi_decoding_dance(self.environ.get('SCRIPT_NAME') or '',
self.charset, self.encoding_errors)
return raw_path.rstrip('/')
示例15: base_url
# 需要導入模塊: from werkzeug.wrappers import BaseRequest [as 別名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 別名]
def base_url(self):
"""Like :attr:`url` but without the querystring
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ, strip_querystring=True,
trusted_hosts=self.trusted_hosts)