OpenQuizz
Une application de gestion des contenus pédagogiques
EnvironBuilder Class Reference
Inheritance diagram for EnvironBuilder:
Collaboration diagram for EnvironBuilder:

Public Member Functions

def __init__ (self, path="/", base_url=None, query_string=None, method="GET", input_stream=None, content_type=None, content_length=None, errors_stream=None, multithread=False, multiprocess=False, run_once=False, headers=None, data=None, environ_base=None, environ_overrides=None, charset="utf-8", mimetype=None, json=None)
 
def from_environ (cls, environ, **kwargs)
 
def base_url (self)
 
def base_url (self, value)
 
def content_type (self)
 
def content_type (self, value)
 
def mimetype (self)
 
def mimetype (self, value)
 
def mimetype_params (self)
 
def content_length (self)
 
def content_length (self, value)
 
def form (self)
 
def form (self, value)
 
def files (self)
 
def files (self, value)
 
def input_stream (self)
 
def input_stream (self, value)
 
def query_string (self)
 
def query_string (self, value)
 
def args (self)
 
def args (self, value)
 
def server_name (self)
 
def server_port (self)
 
def __del__ (self)
 
def close (self)
 
def get_environ (self)
 
def get_request (self, cls=None)
 

Data Fields

 charset
 
 path
 
 base_url
 
 query_string
 
 args
 
 method
 
 headers
 
 content_type
 
 errors_stream
 
 multithread
 
 multiprocess
 
 run_once
 
 environ_base
 
 environ_overrides
 
 input_stream
 
 content_length
 
 closed
 
 mimetype
 
 script_root
 
 host
 
 url_scheme
 

Static Public Attributes

 server_protocol
 
 wsgi_version
 
 request_class
 
 json_dumps
 

Detailed Description

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 (:func:`create_environ`, :meth:`BaseResponse.from_values`,
:meth:`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 :attr:`form` and :attr:`files` attributes, but are
passed with the same argument to the constructor: `data`.

`data` can be any of these values:

-   a `str` or `bytes` object: The object is converted into an
    :attr:`input_stream`, the :attr:`content_length` is set and you have to
    provide a :attr:`content_type`.
-   a `dict` or :class:`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:

    -   a :class:`file`-like object:  These are converted into
        :class:`FileStorage` objects automatically.
    -   a `tuple`:  The :meth:`~FileMultiDict.add_file` method is called
        with the key and the unpacked `tuple` items as positional
        arguments.
    -   a `str`:  The string is set as form data for the associated key.
-   a file-like object: The object content is loaded in memory and then
    handled like a regular `str` or a `bytes`.

:param 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.
:param 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`).
:param query_string: an optional string or dict with URL parameters.
:param method: the HTTP method to use, defaults to `GET`.
:param input_stream: an optional input stream.  Do not specify this and
                     `data`.  As soon as an input stream is set you can't
                     modify :attr:`args` and :attr:`files` unless you
                     set the :attr:`input_stream` to `None` again.
:param 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`.
:param content_length: The content length for the request.  You don't
                       have to specify this when providing data via
                       `data`.
:param errors_stream: an optional error stream that is used for
                      `wsgi.errors`.  Defaults to :data:`stderr`.
:param multithread: controls `wsgi.multithread`.  Defaults to `False`.
:param multiprocess: controls `wsgi.multiprocess`.  Defaults to `False`.
:param run_once: controls `wsgi.run_once`.  Defaults to `False`.
:param headers: an optional list or :class:`Headers` object of headers.
:param data: a string or dict of form data or a file-object.
             See explanation above.
:param json: An object to be serialized and assigned to ``data``.
    Defaults the content type to ``"application/json"``.
    Serialized with the function assigned to :attr:`json_dumps`.
:param environ_base: an optional dict of environment defaults.
:param environ_overrides: an optional dict of environment overrides.
:param charset: the charset used to encode unicode data.

.. versionadded:: 0.15
    The ``json`` param and :meth:`json_dumps` method.

.. versionadded:: 0.15
    The environ has keys ``REQUEST_URI`` and ``RAW_URI`` containing
    the path before perecent-decoding. This is not part of the WSGI
    PEP, but many WSGI servers include it.

.. versionchanged:: 0.6
   ``path`` and ``base_url`` can now be unicode strings that are
   encoded with :func:`iri_to_uri`.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  path = "/",
  base_url = None,
  query_string = None,
  method = "GET",
  input_stream = None,
  content_type = None,
  content_length = None,
  errors_stream = None,
  multithread = False,
  multiprocess = False,
  run_once = False,
  headers = None,
  data = None,
  environ_base = None,
  environ_overrides = None,
  charset = "utf-8",
  mimetype = None,
  json = None 
)

◆ __del__()

def __del__ (   self)

Member Function Documentation

◆ args() [1/2]

def args (   self)
The URL arguments as :class:`MultiDict`.

◆ args() [2/2]

def args (   self,
  value 
)

◆ base_url() [1/2]

def base_url (   self)
The base URL is used to extract the URL scheme, host name,
port, and root path.

◆ base_url() [2/2]

def base_url (   self,
  value 
)

◆ close()

def close (   self)
Closes all files.  If you put real :class:`file` objects into the
:attr:`files` dict you can call this method to automatically close
them all in one go.

◆ content_length() [1/2]

def content_length (   self)
The content length as integer.  Reflected from and to the
:attr:`headers`.  Do not set if you set :attr:`files` or
:attr:`form` for auto detection.

◆ content_length() [2/2]

def content_length (   self,
  value 
)

◆ content_type() [1/2]

def content_type (   self)
The content type for the request.  Reflected from and to
the :attr:`headers`.  Do not set if you set :attr:`files` or
:attr:`form` for auto detection.

◆ content_type() [2/2]

def content_type (   self,
  value 
)

◆ files() [1/2]

def files (   self)
A :class:`FileMultiDict` of uploaded files. Use
:meth:`~FileMultiDict.add_file` to add new files.

◆ files() [2/2]

def files (   self,
  value 
)

◆ form() [1/2]

def form (   self)
A :class:`MultiDict` of form values.

◆ form() [2/2]

def form (   self,
  value 
)

◆ from_environ()

def from_environ (   cls,
  environ,
**  kwargs 
)
Turn an environ dict back into a builder. Any extra kwargs
override the args extracted from the environ.

.. versionadded:: 0.15

◆ get_environ()

def get_environ (   self)
Return the built environ.

.. versionchanged:: 0.15
    The content type and length headers are set based on
    input stream detection. Previously this only set the WSGI
    keys.

◆ get_request()

def get_request (   self,
  cls = None 
)
Returns a request with the data.  If the request class is not
specified :attr:`request_class` is used.

:param cls: The request wrapper to use.

◆ input_stream() [1/2]

def input_stream (   self)
An optional input stream.  If you set this it will clear
:attr:`form` and :attr:`files`.

◆ input_stream() [2/2]

def input_stream (   self,
  value 
)

◆ mimetype() [1/2]

def mimetype (   self)
The mimetype (content type without charset etc.)

.. versionadded:: 0.14

◆ mimetype() [2/2]

def mimetype (   self,
  value 
)

◆ mimetype_params()

def mimetype_params (   self)
The mimetype parameters as dict.  For example if the
content type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.

.. versionadded:: 0.14

◆ query_string() [1/2]

def query_string (   self)
The query string.  If you set this to a string
:attr:`args` will no longer be available.

◆ query_string() [2/2]

def query_string (   self,
  value 
)

◆ server_name()

def server_name (   self)
The server name (read-only, use :attr:`host` to set)

◆ server_port()

def server_port (   self)
The server port as integer (read-only, use :attr:`host` to set)

Field Documentation

◆ args

args

◆ base_url

base_url

◆ charset

charset

◆ closed

closed

◆ content_length

content_length

◆ content_type

content_type

◆ environ_base

environ_base

◆ environ_overrides

environ_overrides

◆ errors_stream

errors_stream

◆ headers

headers

◆ host

host

◆ input_stream

input_stream

◆ json_dumps

json_dumps
static

◆ method

method

◆ mimetype

mimetype

◆ multiprocess

multiprocess

◆ multithread

multithread

◆ path

path

◆ query_string

query_string

◆ request_class

request_class
static

◆ run_once

run_once

◆ script_root

script_root

◆ server_protocol

server_protocol
static

◆ url_scheme

url_scheme

◆ wsgi_version

wsgi_version
static

The documentation for this class was generated from the following file: