class EnvironBuilder:
This class can be used to conveniently create a WSGI environment for testing purposes. It can be used to quickly create WSGI environments or request objects from arbitrary data.
The signature of this class is also used in some other places as of
Werkzeug 0.5 (create_environ
, Response.from_values
,
Client.open
). Because of this most of the functionality is
available through the constructor alone.
Files and regular form data can be manipulated independently of each
other with the form
and files
attributes, but are
passed with the same argument to the constructor: data
.
data
can be any of these values:
str
or bytes
object: The object is converted into an
input_stream
, the content_length
is set and you have to
provide a content_type
.dict
or MultiDict
: The keys have to be strings. The values
have to be either any of the following objects, or a list of any of the
following objects:file
-like object: These are converted into
FileStorage
objects automatically.tuple
: The ~FileMultiDict.add_file
method is called
with the key and the unpacked tuple
items as positional
arguments.str
: The string is set as form data for the associated key.str
or a bytes
.request_class
is Request instead of
BaseRequest.json_dumps
method.iri_to_uri
.Parameters | |
path | the path of the request. In the WSGI environment this will
end up as PATH_INFO . If the query_string is not defined
and there is a question mark in the path everything after
it is used as query string. |
base_url | the base URL is a URL that is used to extract the WSGI
URL scheme, host (server name + server port) and the
script root (SCRIPT_NAME ). |
query_string | an optional string or dict with URL parameters. |
method | the HTTP method to use, defaults to GET . |
input_stream | an optional input stream. Do not specify this and
data . As soon as an input stream is set you can't
modify args and files unless you
set the input_stream to None again. |
content_type | The content type for the request. As of 0.5 you
don't have to provide this when specifying files
and form data via data . |
content_length | The content length for the request. You don't
have to specify this when providing data via
data . |
errors_stream | an optional error stream that is used for
wsgi.errors . Defaults to stderr . |
multithread | controls wsgi.multithread . Defaults to False . |
multiprocess | controls wsgi.multiprocess . Defaults to False . |
run_once | controls wsgi.run_once . Defaults to False . |
headers | an optional list or Headers object of headers. |
data | a string or dict of form data or a file-object. See explanation above. |
json | An object to be serialized and assigned to data.
Defaults the content type to "application/json".
Serialized with the function assigned to json_dumps . |
environ_base | an optional dict of environment defaults. |
environ_overrides | an optional dict of environment overrides. |
charset | the charset used to encode string data. |
auth | An authorization object to use for the Authorization header value. A (username, password) tuple is a shortcut for Basic authorization. |
Class Method | from_environ |
Turn an environ dict back into a builder. Any extra kwargs override the args extracted from the environ. |
Method | __del__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | args.setter |
Undocumented |
Method | base_url.setter |
Undocumented |
Method | close |
Closes all files. If you put real file objects into the files dict you can call this method to automatically close them all in one go. |
Method | content_length.setter |
Undocumented |
Method | content_type.setter |
Undocumented |
Method | files.setter |
Undocumented |
Method | form.setter |
Undocumented |
Method | get_environ |
Return the built environ. |
Method | get_request |
Returns a request with the data. If the request class is not specified request_class is used. |
Method | input_stream.setter |
Undocumented |
Method | mimetype.setter |
Undocumented |
Method | query_string.setter |
Undocumented |
Class Variable | json_dumps |
Undocumented |
Class Variable | server_protocol |
Undocumented |
Class Variable | wsgi_version |
Undocumented |
Instance Variable | charset |
Undocumented |
Instance Variable | closed |
Undocumented |
Instance Variable | content_type |
The content type for the request. Reflected from and to the headers . Do not set if you set files or form for auto detection. |
Instance Variable | environ_base |
Undocumented |
Instance Variable | environ_overrides |
Undocumented |
Instance Variable | errors_stream |
Undocumented |
Instance Variable | headers |
Undocumented |
Instance Variable | host |
Undocumented |
Instance Variable | method |
Undocumented |
Instance Variable | multiprocess |
Undocumented |
Instance Variable | multithread |
Undocumented |
Instance Variable | path |
Undocumented |
Instance Variable | request_uri |
Undocumented |
Instance Variable | run_once |
Undocumented |
Instance Variable | script_root |
Undocumented |
Instance Variable | url_scheme |
Undocumented |
Property | args |
The URL arguments as MultiDict . |
Property | base_url |
The base URL is used to extract the URL scheme, host name, port, and root path. |
Property | content_length |
The content length as integer. Reflected from and to the headers . Do not set if you set files or form for auto detection. |
Property | files |
A FileMultiDict of uploaded files. Use ~FileMultiDict.add_file to add new files. |
Property | form |
A MultiDict of form values. |
Property | input_stream |
No summary |
Property | mimetype |
The mimetype (content type without charset etc.) |
Property | mimetype_params |
The mimetype parameters as dict. For example if the content type is text/html; charset=utf-8 the params would be {'charset': 'utf-8'}. |
Property | query_string |
The query string. If you set this to a string args will no longer be available. |
Property | server_name |
The server name (read-only, use host to set) |
Property | server_port |
The server port as integer (read-only, use host to set) |
Static Method | _make_base_url |
Undocumented |
Method | _add_file_from_data |
Called in the EnvironBuilder to add files from the data dict. |
Method | _get_form |
Common behavior for getting the form and files properties. |
Method | _set_form |
Common behavior for setting the form and files properties. |
Instance Variable | _args |
Undocumented |
Instance Variable | _files |
Undocumented |
Instance Variable | _form |
Undocumented |
Instance Variable | _input_stream |
Undocumented |
Instance Variable | _query_string |
Undocumented |
Turn an environ dict back into a builder. Any extra kwargs override the args extracted from the environ.
Parameters | |
environ:WSGIEnvironment | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
EnvironBuilder | Undocumented |
Undocumented
Parameters | |
path:str | Undocumented |
base_url:t.Optional[ | Undocumented |
query_string:t.Optional[ | Undocumented |
method:str | Undocumented |
input_stream:t.Optional[ | Undocumented |
content_type:t.Optional[ | Undocumented |
content_length:t.Optional[ | Undocumented |
errors_stream:t.Optional[ | Undocumented |
multithread:bool | Undocumented |
multiprocess:bool | Undocumented |
run_once:bool | Undocumented |
headers:t.Optional[ | Undocumented |
data:t.Optional[ | Undocumented |
environ_base:t.Optional[ | Undocumented |
environ_overrides:t.Optional[ | Undocumented |
charset:str | Undocumented |
mimetype:t.Optional[ | Undocumented |
json:t.Optional[ | Undocumented |
auth:t.Optional[ | Undocumented |
file
objects into the
files
dict you can call this method to automatically close
them all in one go.Return the built environ.
Returns | |
WSGIEnvironment | Undocumented |
request_class
is used.Parameters | |
cls:t.Optional[ | The request wrapper to use. |
Returns | |
Request | Undocumented |
str
=
t.Optional[ str]
=
The mimetype (content type without charset etc.)
t.Mapping[ str, str]
=
The mimetype parameters as dict. For example if the content type is text/html; charset=utf-8 the params would be {'charset': 'utf-8'}.
str
=
args
will no longer be available.Undocumented
Parameters | |
scheme:str | Undocumented |
host:str | Undocumented |
script_root:str | Undocumented |
Returns | |
str | Undocumented |
Parameters | |
key:str | Undocumented |
value:t.Union[ | Undocumented |
form
and
files
properties.Parameters | |
name:str | Name of the internal cached attribute. |
storage:t.Type[ | Storage class used for the data. |
Returns | |
_TAnyMultiDict | Undocumented |