Undocumented
Class | COEP |
Cross Origin Embedder Policies |
Class | COOP |
Cross Origin Opener Policies |
Function | cookie_date |
Format a datetime object or timestamp into an RFC 2822 date string for Set-Cookie expires. |
Function | dump_age |
Formats the duration as a base-10 integer. |
Function | dump_cookie |
Create a Set-Cookie header without the Set-Cookie prefix. |
Function | dump_csp_header |
Dump a Content Security Policy header. |
Function | dump_header |
No summary |
Function | dump_options_header |
The reverse function to parse_options_header . |
Function | generate_etag |
Generate an etag for some data. |
Function | http_date |
Format a datetime object or timestamp into an RFC 2822 date string. |
Function | is_byte_range_valid |
Checks if a given byte content range is valid for the given length. |
Function | is_entity_header |
Check if a header is an entity header. |
Function | is_hop_by_hop_header |
Check if a header is an HTTP/1.1 "Hop-by-Hop" header. |
Function | is_resource_modified |
Convenience method for conditional requests. |
Function | parse_accept_header |
Parses an HTTP Accept-* header. This does not implement a complete valid algorithm but one that supports at least value and quality extraction. |
Function | parse_age |
Parses a base-10 integer count of seconds into a timedelta. |
Function | parse_authorization_header |
No summary |
Function | parse_cache_control_header |
Parse a cache control header. The RFC differs between response and request cache control, this method does not. It's your responsibility to not use the wrong control statements. |
Function | parse_content_range_header |
Parses a range header into a ~werkzeug.datastructures.ContentRange object or None if parsing is not possible. |
Function | parse_cookie |
Parse a cookie from a string or WSGI environ. |
Function | parse_csp_header |
Parse a Content Security Policy header. |
Function | parse_date |
Parse an RFC 2822 date into a timezone-aware datetime.datetime object, or None if parsing fails. |
Function | parse_dict_header |
Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict (or any other mapping object created from the type with a dict like interface provided by the cls argument): |
Function | parse_etags |
Parse an etag header. |
Function | parse_if_range_header |
Parses an if-range header which can be an etag or a date. Returns a ~werkzeug.datastructures.IfRange object. |
Function | parse_list_header |
Parse lists as described by RFC 2068 Section 2. |
Function | parse_options_header |
Parse a Content-Type like header into a tuple with the content type and the options: |
Function | parse_range_header |
No summary |
Function | parse_set_header |
Parse a set-like header and return a ~werkzeug.datastructures.HeaderSet object: |
Function | parse_www_authenticate_header |
Parse an HTTP WWW-Authenticate header into a ~werkzeug.datastructures.WWWAuthenticate object. |
Function | quote_etag |
Quote an etag. |
Function | quote_header_value |
Quote a header value if necessary. |
Function | remove_entity_headers |
No summary |
Function | remove_hop_by_hop_headers |
Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or Headers object. This operation works in-place. |
Function | unquote_etag |
Unquote a single etag: |
Function | unquote_header_value |
Unquotes a header value. (Reversal of quote_header_value ). This does not use the real unquoting but what browsers are actually using for quoting. |
Constant | HTTP_STATUS_CODES |
Undocumented |
Variable | _accept_re |
Undocumented |
Variable | _entity_headers |
Undocumented |
Variable | _etag_re |
Undocumented |
Variable | _hop_by_hop_headers |
Undocumented |
Variable | _option_header_piece_re |
Undocumented |
Variable | _option_header_start_mime_type |
Undocumented |
Variable | _t_cc_update |
Undocumented |
Variable | _t_csp_update |
Undocumented |
Variable | _TAnyAccept |
Undocumented |
Variable | _TAnyCC |
Undocumented |
Variable | _TAnyCSP |
Undocumented |
Variable | _token_chars |
Undocumented |
Parameters | |
age:t.Optional[ | should be an integer number of seconds,
a datetime.timedelta object, or,
if the age is unknown, None (default). |
Returns | |
t.Optional[ | Undocumented |
Create a Set-Cookie header without the Set-Cookie prefix.
The return value is usually restricted to ascii as the vast majority of values are properly escaped, but that is no guarantee. It's tunneled through latin1 as required by PEP 3333.
The return value is not ASCII safe if the key contains unicode characters. This is technically against the specification but happens in the wild. It's strongly recommended to not use non-ASCII values for the keys.
Parameters | |
key:str | Undocumented |
value:t.Union[ | Undocumented |
max_age:t.Optional[ | should be a number of seconds, or None (default) if
the cookie should last only as long as the client's
browser session. Additionally timedelta objects
are accepted, too. |
expires:t.Optional[ | should be a datetime object or unix timestamp. |
path:t.Optional[ | limits the cookie to a given path, per default it will span the whole domain. |
domain:t.Optional[ | Use this if you want to set a cross-domain cookie. For example, domain=".example.com" will set a cookie that is readable by the domain www.example.com, foo.example.com etc. Otherwise, a cookie will only be readable by the domain that set it. |
secure:bool | The cookie will only be available via HTTPS |
httponly:bool | disallow JavaScript to access the cookie. This is an extension to the cookie standard and probably not supported by all browsers. |
charset:str | the encoding for string values. |
sync_expires:bool | automatically set expires if max_age is defined but expires not. |
max_size:int | Warn if the final header value exceeds this size. The default, 4093, should be safely supported by most browsers. Set to 0 to disable this check. |
samesite:t.Optional[ | Limits the scope of the cookie such that it will only be attached to requests if those requests are same-site. |
Returns | |
str | Undocumented |
Dump a Content Security Policy header.
These are structured into policies such as "default-src 'self'; script-src 'self'".
Parameters | |
header:ds.ContentSecurityPolicy | Undocumented |
Returns | |
str | Undocumented |
Dump an HTTP header again. This is the reversal of
parse_list_header
, parse_set_header
and
parse_dict_header
. This also quotes strings that include an
equals sign unless you pass it as dict of key, value pairs.
>>> dump_header({'foo': 'bar baz'}) 'foo="bar baz"' >>> dump_header(('foo', 'bar baz')) 'foo, "bar baz"'
Parameters | |
iterable:t.Union[ | the iterable or dict of values to quote. |
allow_token:bool | if set to False tokens as values are disallowed.
See quote_header_value for more details. |
Returns | |
str | Undocumented |
parse_options_header
.Parameters | |
header:t.Optional[ | the header to dump |
options:t.Mapping[ | a dict of options to append. |
Returns | |
str | Undocumented |
Generate an etag for some data.
Parameters | |
data:bytes | Undocumented |
Returns | |
str | Undocumented |
Format a datetime object or timestamp into an RFC 2822 date string.
This is a wrapper for email.utils.format_datetime
. It
assumes naive datetime objects are in UTC instead of raising an
exception.
Parameters | |
timestamp:t.Optional[ | The datetime or timestamp to format. Defaults to the current time. |
Returns | |
str | Undocumented |
Checks if a given byte content range is valid for the given length.
Parameters | |
start:t.Optional[ | Undocumented |
stop:t.Optional[ | Undocumented |
length:t.Optional[ | Undocumented |
Returns | |
bool | Undocumented |
Check if a header is an entity header.
Parameters | |
header:str | the header to test. |
Returns | |
bool | True if it's an entity header, False otherwise. |
Check if a header is an HTTP/1.1 "Hop-by-Hop" header.
Parameters | |
header:str | the header to test. |
Returns | |
bool | True if it's an HTTP/1.1 "Hop-by-Hop" header, False otherwise. |
Convenience method for conditional requests.
Parameters | |
environ:WSGIEnvironment | the WSGI environment of the request to be checked. |
etag:t.Optional[ | the etag for the response for comparison. |
data:t.Optional[ | or alternatively the data of the response to automatically
generate an etag using generate_etag . |
last_modified:t.Optional[ | an optional date of the last modification. |
ignore_if_range:bool | If False , If-Range header will be taken into
account. |
Returns | |
bool | True if the resource was modified, otherwise False . |
Parses an HTTP Accept-* header. This does not implement a complete valid algorithm but one that supports at least value and quality extraction.
Returns a new Accept
object (basically a list of (value, quality)
tuples sorted by the quality with some additional accessor methods).
The second parameter can be a subclass of Accept
that is created
with the parsed values and returned.
Parameters | |
value:t.Optional[ | the accept header string to be parsed. |
cls:t.Optional[ | the wrapper class for the return value (can be
Accept or a subclass thereof) |
Returns | |
_TAnyAccept | an instance of cls . |
Parses a base-10 integer count of seconds into a timedelta.
If parsing fails, the return value is None
.
Parameters | |
value:t.Optional[ | a string consisting of an integer represented in base-10 |
Returns | |
t.Optional[ | a datetime.timedelta object or None . |
None
if the header was invalid or
not given, otherwise an ~werkzeug.datastructures.Authorization
object.Parameters | |
value:t.Optional[ | the authorization header to parse. |
Returns | |
t.Optional[ | a ~werkzeug.datastructures.Authorization object or None . |
Parse a cache control header. The RFC differs between response and request cache control, this method does not. It's your responsibility to not use the wrong control statements.
cls
was added. If not specified an immutable
~werkzeug.datastructures.RequestCacheControl
is returned.Parameters | |
value:t.Optional[ | a cache control header to be parsed. |
on_update:_t_cc_update | an optional callable that is called every time a value
on the ~werkzeug.datastructures.CacheControl
object is changed. |
cls:t.Optional[ | the class for the returned object. By default
~werkzeug.datastructures.RequestCacheControl is used. |
Returns | |
_TAnyCC | a cls object. |
Parses a range header into a
~werkzeug.datastructures.ContentRange
object or None
if
parsing is not possible.
Parameters | |
value:t.Optional[ | a content range header to be parsed. |
on_update:t.Optional[ | an optional callable that is called every time a value
on the ~werkzeug.datastructures.ContentRange
object is changed. |
Returns | |
t.Optional[ | Undocumented |
Parse a cookie from a string or WSGI environ.
The same key can be provided multiple times, the values are stored
in-order. The default MultiDict
will have the first value
first, and all values can be retrieved with
MultiDict.getlist
.
MultiDict
instead of a
TypeConversionDict.TypeConversionDict
instead of a regular dict.
The cls parameter was added.Parameters | |
header:t.Union[ | The cookie header as a string, or a WSGI environ dict with a HTTP_COOKIE key. |
charset:str | The charset for the cookie values. |
errors:str | The error behavior for the charset decoding. |
cls:t.Optional[ | A dict-like class to store the parsed cookies in.
Defaults to MultiDict . |
Returns | |
ds.MultiDict[ | Undocumented |
Parse a Content Security Policy header.
Parameters | |
value:t.Optional[ | a csp header to be parsed. |
on_update:_t_csp_update | an optional callable that is called every time a value on the object is changed. |
cls:t.Optional[ | the class for the returned object. By default
~werkzeug.datastructures.ContentSecurityPolicy is used. |
Returns | |
_TAnyCSP | a cls object. |
Parse an RFC 2822 date into a timezone-aware
datetime.datetime
object, or None if parsing fails.
This is a wrapper for email.utils.parsedate_to_datetime
. It
returns None if parsing fails instead of raising an exception,
and always returns a timezone-aware datetime object. If the string
doesn't have timezone information, it is assumed to be UTC.
Parameters | |
value:t.Optional[ | A string with a supported date format. |
Returns | |
t.Optional[ | Undocumented |
Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict (or any other mapping object created from
the type with a dict like interface provided by the cls
argument):
>>> d = parse_dict_header('foo="is a fish", bar="as well"') >>> type(d) is dict True >>> sorted(d.items()) [('bar', 'as well'), ('foo', 'is a fish')]
If there is no value for a key it will be None
:
>>> parse_dict_header('key_without_value') {'key_without_value': None}
To create a header from the dict
again, use the
dump_header
function.
cls
argument.Parameters | |
value:str | a string with a dict header. |
cls:t.Type[ | callable to use for storage of parsed results. |
Returns | |
t.Dict[ | an instance of cls |
Parameters | |
value:t.Optional[ | the tag header to parse |
Returns | |
ds.ETags | an ~werkzeug.datastructures.ETags object. |
Parses an if-range header which can be an etag or a date. Returns
a ~werkzeug.datastructures.IfRange
object.
Parameters | |
value:t.Optional[ | Undocumented |
Returns | |
ds.IfRange | Undocumented |
Parse lists as described by RFC 2068 Section 2.
In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Quotes are removed automatically after parsing.
It basically works like parse_set_header
just that items
may appear multiple times and case sensitivity is preserved.
The return value is a standard list
:
>>> parse_list_header('token, "quoted value"') ['token', 'quoted value']
To create a header from the list
again, use the
dump_header
function.
Parameters | |
value:str | a string with a list header. |
Returns | |
t.List[ | list |
Parse a Content-Type like header into a tuple with the content type and the options:
>>> parse_options_header('text/html; charset=utf8') ('text/html', {'charset': 'utf8'})
This should not be used to parse Cache-Control like headers that use
a slightly different format. For these headers use the
parse_dict_header
function.
Parameters | |
value:t.Optional[ | the header to parse. |
multiple:bool | Whether try to parse and return multiple MIME types |
Returns | |
t.Union[ | (mimetype, options) or (mimetype, options, mimetype, options, …) if multiple=True |
Parses a range header into a ~werkzeug.datastructures.Range
object. If the header is missing or malformed None
is returned.
ranges
is a list of (start, stop) tuples where the ranges are
non-inclusive.
Parameters | |
value:t.Optional[ | Undocumented |
make_inclusive:bool | Undocumented |
Returns | |
t.Optional[ | Undocumented |
Parse a set-like header and return a
~werkzeug.datastructures.HeaderSet
object:
>>> hs = parse_set_header('token, "quoted value"')
The return value is an object that treats the items case-insensitively and keeps the order of the items:
>>> 'TOKEN' in hs True >>> hs.index('quoted value') 1 >>> hs HeaderSet(['token', 'quoted value'])
To create a header from the HeaderSet
again, use the
dump_header
function.
Parameters | |
value:t.Optional[ | a set header to be parsed. |
on_update:t.Optional[ | an optional callable that is called every time a
value on the ~werkzeug.datastructures.HeaderSet
object is changed. |
Returns | |
ds.HeaderSet | a ~werkzeug.datastructures.HeaderSet |
~werkzeug.datastructures.WWWAuthenticate
object.Parameters | |
value:t.Optional[ | a WWW-Authenticate header to parse. |
on_update:t.Optional[ | an optional callable that is called every time a value
on the ~werkzeug.datastructures.WWWAuthenticate
object is changed. |
Returns | |
ds.WWWAuthenticate | a ~werkzeug.datastructures.WWWAuthenticate object. |
Parameters | |
etag:str | the etag to quote. |
weak:bool | set to True to tag it "weak". |
Returns | |
str | Undocumented |
Quote a header value if necessary.
Parameters | |
value:t.Union[ | the value to quote. |
extra_chars:str | a list of extra characters to skip quoting. |
allow_token:bool | if this is enabled token values are returned unchanged. |
Returns | |
str | Undocumented |
Remove all entity headers from a list or Headers
object. This
operation works in-place. Expires
and Content-Location
headers are
by default not removed. The reason for this is RFC 2616 section
10.3.5 which specifies some entity headers that should be sent.
allowed
parameter.Parameters | |
headers:t.Union[ | a list or Headers object. |
allowed:t.Iterable[ | a list of headers that should still be allowed even though they are entity headers. |
Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or
Headers
object. This operation works in-place.
Parameters | |
headers:t.Union[ | a list or Headers object. |
Unquote a single etag:
>>> unquote_etag('W/"bar"') ('bar', True) >>> unquote_etag('"bar"') ('bar', False)
Parameters | |
etag:t.Optional[ | the etag identifier to unquote. |
Returns | |
t.Union[ | a (etag, weak) tuple. |
Unquotes a header value. (Reversal of quote_header_value
).
This does not use the real unquoting but what browsers are actually
using for quoting.
Parameters | |
value:str | the header value to unquote. |
is_filename:bool | The value represents a filename or path. |
Returns | |
str | Undocumented |