Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Properties
MoinMoin.support.werkzeug.wrappers.Request Class Reference
Inheritance diagram for MoinMoin.support.werkzeug.wrappers.Request:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.werkzeug.wrappers.Request:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def from_values
def application
def stream
def args
def data
def form
def values
def files
def cookies
def headers
def path
def script_root
def url
def base_url
def url_root
def host_url
def host
def access_route
def remote_addr
def accept_mimetypes
def accept_charsets
def accept_encodings
def accept_languages
def cache_control
def if_match
def if_none_match
def if_modified_since
def if_unmodified_since
def user_agent
def authorization
def mimetype
def mimetype_params
def pragma

Public Attributes

 environ
 shallow

Static Public Attributes

string charset = 'utf-8'
string encoding_errors = 'ignore'
 is_behind_proxy = False
 max_content_length = None
 max_form_memory_size = None
tuple input_stream
tuple query_string
tuple method
tuple remote_user
tuple is_multithread
tuple is_multiprocess
tuple is_run_once
tuple content_type
tuple content_length
tuple referrer
tuple date
tuple max_forwards

Properties

 is_xhr
 is_secure

Detailed Description

Full featured request object implementing the following mixins:

- :class:`AcceptMixin` for accept header parsing
- :class:`ETagRequestMixin` for etag and cache control handling
- :class:`UserAgentMixin` for user agent introspection
- :class:`AuthorizationMixin` for http auth handling
- :class:`CommonRequestDescriptorsMixin` for common headers

Definition at line 1177 of file wrappers.py.


Member Function Documentation

List of charsets this client supports as :class:`CharsetAccept`
object.

Definition at line 734 of file wrappers.py.

00734 
00735     def accept_charsets(self):
00736         """List of charsets this client supports as :class:`CharsetAccept`
00737         object.
00738         """
00739         return parse_accept_header(self.environ.get('HTTP_ACCEPT_CHARSET'),
00740                                    CharsetAccept)

Here is the call graph for this function:

List of encodings this client accepts.  Encodings in a HTTP term
are compression encodings such as gzip.  For charsets have a look at
:attr:`accept_charset`.

Definition at line 742 of file wrappers.py.

00742 
00743     def accept_encodings(self):
00744         """List of encodings this client accepts.  Encodings in a HTTP term
00745         are compression encodings such as gzip.  For charsets have a look at
00746         :attr:`accept_charset`.
00747         """
00748         return parse_accept_header(self.environ.get('HTTP_ACCEPT_ENCODING'))

Here is the call graph for this function:

List of languages this client accepts as :class:`LanguageAccept`
object.

.. versionchanged 0.5
   In previous versions this was a regualr :class:`Accept` object.

Definition at line 750 of file wrappers.py.

00750 
00751     def accept_languages(self):
00752         """List of languages this client accepts as :class:`LanguageAccept`
00753         object.
00754 
00755         .. versionchanged 0.5
00756            In previous versions this was a regualr :class:`Accept` object.
00757         """
00758         return parse_accept_header(self.environ.get('HTTP_ACCEPT_LANGUAGE'),
00759                                    LanguageAccept)
00760 

Here is the call graph for this function:

List of mimetypes this client supports as :class:`MIMEAccept`
object.

Definition at line 727 of file wrappers.py.

00727 
00728     def accept_mimetypes(self):
00729         """List of mimetypes this client supports as :class:`MIMEAccept`
00730         object.
00731         """
00732         return parse_accept_header(self.environ.get('HTTP_ACCEPT'), MIMEAccept)

Here is the call graph for this function:

If a forwarded header exists this is a list of all ip addresses
from the client ip to the last proxy server.

Definition at line 373 of file wrappers.py.

00373 
00374     def access_route(self):
00375         """If a forwarded header exists this is a list of all ip addresses
00376         from the client ip to the last proxy server.
00377         """
00378         if 'HTTP_X_FORWARDED_FOR' in self.environ:
00379             addr = self.environ['HTTP_X_FORWARDED_FOR'].split(',')
00380             return ImmutableList([x.strip() for x in addr])
00381         elif 'REMOTE_ADDR' in self.environ:
00382             return ImmutableList([self.environ['REMOTE_ADDR']])
00383         return ImmutableList()

Here is the caller graph for this function:

Decorate a function as responder that accepts the request as first
argument.  This works like the :func:`responder` decorator but the
function is passed the request object as first argument::

    @Request.application
    def my_wsgi_app(request):
return Response('Hello World!')

:param f: the WSGI callable to decorate
:return: a new WSGI callable

Definition at line 163 of file wrappers.py.

00163 
00164     def application(cls, f):
00165         """Decorate a function as responder that accepts the request as first
00166         argument.  This works like the :func:`responder` decorator but the
00167         function is passed the request object as first argument::
00168 
00169             @Request.application
00170             def my_wsgi_app(request):
00171                 return Response('Hello World!')
00172 
00173         :param f: the WSGI callable to decorate
00174         :return: a new WSGI callable
00175         """
00176         #: return a callable that wraps the -2nd argument with the request
00177         #: and calls the function with all the arguments up to that one and
00178         #: the request.  The return value is then called with the latest
00179         #: two arguments.  This makes it possible to use this decorator for
00180         #: both methods and standalone WSGI functions.
00181         return _patch_wrapper(f, lambda *a: f(*a[:-2]+(cls(a[-2]),))(*a[-2:]))

Here is the call graph for this function:

The parsed URL parameters as :class:`ImmutableMultiDict`.

Definition at line 267 of file wrappers.py.

00267 
00268     def args(self):
00269         """The parsed URL parameters as :class:`ImmutableMultiDict`."""
00270         return url_decode(self.environ.get('QUERY_STRING', ''), self.charset,
00271                           errors=self.encoding_errors,
00272                           cls=ImmutableMultiDict)

Here is the call graph for this function:

Here is the caller graph for this function:

The `Authorization` object in parsed form.

Definition at line 821 of file wrappers.py.

00821 
00822     def authorization(self):
00823         """The `Authorization` object in parsed form."""
00824         header = self.environ.get('HTTP_AUTHORIZATION')
00825         return parse_authorization_header(header)
00826 

Here is the call graph for this function:

Like :attr:`url` but without the querystring

Definition at line 348 of file wrappers.py.

00348 
00349     def base_url(self):
00350         """Like :attr:`url` but without the querystring"""
00351         return get_current_url(self.environ, strip_querystring=True)

Here is the call graph for this function:

A :class:`RequestCacheControl` object for the incoming cache control
headers.

Definition at line 768 of file wrappers.py.

00768 
00769     def cache_control(self):
00770         """A :class:`RequestCacheControl` object for the incoming cache control
00771         headers.
00772         """
00773         cache_control = self.environ.get('HTTP_CACHE_CONTROL')
00774         return parse_cache_control_header(cache_control, None,
00775                                           RequestCacheControl)

Here is the call graph for this function:

The retrieved cookie values as regular dictionary.

Definition at line 315 of file wrappers.py.

00315 
00316     def cookies(self):
00317         """The retrieved cookie values as regular dictionary."""
00318         return parse_cookie(self.environ, self.charset,
00319                             cls=ImmutableTypeConversionDict)

Here is the call graph for this function:

This reads the buffered incoming data from the client into the
string.  Usually it's a bad idea to access :attr:`data` because a client
could send dozens of megabytes or more to cause memory problems on the
server.

To circumvent that make sure to check the content length first.

Definition at line 274 of file wrappers.py.

00274 
00275     def data(self):
00276         """This reads the buffered incoming data from the client into the
00277         string.  Usually it's a bad idea to access :attr:`data` because a client
00278         could send dozens of megabytes or more to cause memory problems on the
00279         server.
00280 
00281         To circumvent that make sure to check the content length first.
00282         """
00283         return self.stream.read()

Here is the caller graph for this function:

:class:`MultiDict` object containing all uploaded files.  Each key in
:attr:`files` is the name from the ``<input type="file" name="">``.  Each
value in :attr:`files` is a Werkzeug :class:`FileStorage` object.

Note that :attr:`files` will only contain data if the request method was
POST or PUT and the ``<form>`` that posted to the request had
``enctype="multipart/form-data"``.  It will be empty otherwise.

See the :class:`MultiDict` / :class:`FileStorage` documentation for more
details about the used data structure.

Definition at line 299 of file wrappers.py.

00299 
00300     def files(self):
00301         """:class:`MultiDict` object containing all uploaded files.  Each key in
00302         :attr:`files` is the name from the ``<input type="file" name="">``.  Each
00303         value in :attr:`files` is a Werkzeug :class:`FileStorage` object.
00304 
00305         Note that :attr:`files` will only contain data if the request method was
00306         POST or PUT and the ``<form>`` that posted to the request had
00307         ``enctype="multipart/form-data"``.  It will be empty otherwise.
00308 
00309         See the :class:`MultiDict` / :class:`FileStorage` documentation for more
00310         details about the used data structure.
00311         """
00312         self._load_form_data()
00313         return self._files

Here is the call graph for this function:

Form parameters.  Currently it's not guaranteed that the
:class:`ImmutableMultiDict` returned by this function is ordered in
the same way as the submitted form data.

Definition at line 285 of file wrappers.py.

00285 
00286     def form(self):
00287         """Form parameters.  Currently it's not guaranteed that the
00288         :class:`ImmutableMultiDict` returned by this function is ordered in
00289         the same way as the submitted form data.
00290         """
00291         self._load_form_data()
00292         return self._form

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.wrappers.BaseRequest.from_values (   cls,
  args,
  kwargs 
) [inherited]
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:`EnvironBuilder`.

.. versionchanged:: 0.5
   This method now accepts the same arguments as
   :class:`EnvironBuilder`.  Because of this the `environ` parameter
   is now called `environ_overrides`.

:return: request object

Definition at line 129 of file wrappers.py.

00129 
00130     def from_values(cls, *args, **kwargs):
00131         """Create a new request object based on the values provided.  If
00132         environ is given missing values are filled from there.  This method is
00133         useful for small scripts when you need to simulate a request from an URL.
00134         Do not use this method for unittesting, there is a full featured client
00135         object (:class:`Client`) that allows to create multipart requests,
00136         support for cookies etc.
00137 
00138         This accepts the same options as the :class:`EnvironBuilder`.
00139 
00140         .. versionchanged:: 0.5
00141            This method now accepts the same arguments as
00142            :class:`EnvironBuilder`.  Because of this the `environ` parameter
00143            is now called `environ_overrides`.
00144 
00145         :return: request object
00146         """
00147         from werkzeug.test import EnvironBuilder
00148         charset = kwargs.pop('charset', cls.charset)
00149         environ = kwargs.pop('environ', None)
00150         if environ is not None:
00151             from warnings import warn
00152             warn(DeprecationWarning('The environ parameter to from_values'
00153                                     ' is now called environ_overrides for'
00154                                     ' consistency with EnvironBuilder'),
00155                  stacklevel=2)
00156             kwargs['environ_overrides'] = environ
00157         builder = EnvironBuilder(*args, **kwargs)
00158         try:
00159             return builder.get_request(cls)
00160         finally:
00161             builder.close()

The headers from the WSGI environ as immutable
:class:`EnvironHeaders`.

Definition at line 321 of file wrappers.py.

00321 
00322     def headers(self):
00323         """The headers from the WSGI environ as immutable
00324         :class:`EnvironHeaders`.
00325         """
00326         return EnvironHeaders(self.environ)

Here is the caller graph for this function:

Just the host including the port if available.

Definition at line 363 of file wrappers.py.

00363 
00364     def host(self):
00365         """Just the host including the port if available."""
00366         return get_host(self.environ)

Here is the call graph for this function:

Here is the caller graph for this function:

Just the host with scheme.

Definition at line 358 of file wrappers.py.

00358 
00359     def host_url(self):
00360         """Just the host with scheme."""
00361         return get_current_url(self.environ, host_only=True)

Here is the call graph for this function:

An object containing all the etags in the `If-Match` header.

Definition at line 777 of file wrappers.py.

00777 
00778     def if_match(self):
00779         """An object containing all the etags in the `If-Match` header."""
00780         return parse_etags(self.environ.get('HTTP_IF_MATCH'))

Here is the call graph for this function:

The parsed `If-Modified-Since` header as datetime object.

Definition at line 787 of file wrappers.py.

00787 
00788     def if_modified_since(self):
00789         """The parsed `If-Modified-Since` header as datetime object."""
00790         return parse_date(self.environ.get('HTTP_IF_MODIFIED_SINCE'))

Here is the call graph for this function:

An object containing all the etags in the `If-None-Match` header.

Definition at line 782 of file wrappers.py.

00782 
00783     def if_none_match(self):
00784         """An object containing all the etags in the `If-None-Match` header."""
00785         return parse_etags(self.environ.get('HTTP_IF_NONE_MATCH'))

Here is the call graph for this function:

The parsed `If-Unmodified-Since` header as datetime object.

Definition at line 792 of file wrappers.py.

00792 
00793     def if_unmodified_since(self):
00794         """The parsed `If-Unmodified-Since` header as datetime object."""
00795         return parse_date(self.environ.get('HTTP_IF_UNMODIFIED_SINCE'))
00796 

Here is the call graph for this function:

Like :attr:`content_type` but without parameters (eg, without
charset, type etc.).  For example if the content
type is ``text/html; charset=utf-8`` the mimetype would be
``'text/html'``.

Definition at line 993 of file wrappers.py.

00993 
00994     def mimetype(self):
00995         """Like :attr:`content_type` but without parameters (eg, without
00996         charset, type etc.).  For example if the content
00997         type is ``text/html; charset=utf-8`` the mimetype would be
00998         ``'text/html'``.
00999         """
01000         self._parse_content_type()
01001         return self._parsed_content_type[0]

Here is the call graph for this function:

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

Definition at line 1003 of file wrappers.py.

01003 
01004     def mimetype_params(self):
01005         """The mimetype parameters as dict.  For example if the content
01006         type is ``text/html; charset=utf-8`` the params would be
01007         ``{'charset': 'utf-8'}``.
01008         """
01009         self._parse_content_type()
01010         return self._parsed_content_type[1]

Here is the call graph for this function:

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.

Definition at line 328 of file wrappers.py.

00328 
00329     def path(self):
00330         """Requested path as unicode.  This works a bit like the regular path
00331         info in the WSGI environment but will always include a leading slash,
00332         even if the URL root is accessed.
00333         """
00334         path = '/' + (self.environ.get('PATH_INFO') or '').lstrip('/')
00335         return _decode_unicode(path, self.charset, self.encoding_errors)

Here is the call graph for this function:

Here is the caller graph for this function:

The Pragma general-header field is used to include
implementation-specific directives that might apply to any recipient
along the request/response chain.  All pragma directives specify
optional behavior from the viewpoint of the protocol; however, some
systems MAY require that behavior be consistent with the directives.

Definition at line 1012 of file wrappers.py.

01012 
01013     def pragma(self):
01014         """The Pragma general-header field is used to include
01015         implementation-specific directives that might apply to any recipient
01016         along the request/response chain.  All pragma directives specify
01017         optional behavior from the viewpoint of the protocol; however, some
01018         systems MAY require that behavior be consistent with the directives.
01019         """
01020         return parse_set_header(self.environ.get('HTTP_PRAGMA', ''))
01021 

Here is the call graph for this function:

The remote address of the client.

Definition at line 385 of file wrappers.py.

00385 
00386     def remote_addr(self):
00387         """The remote address of the client."""
00388         if self.is_behind_proxy and self.access_route:
00389             return self.access_route[0]
00390         return self.environ.get('REMOTE_ADDR')

Here is the call graph for this function:

The root path of the script without the trailing slash.

Definition at line 337 of file wrappers.py.

00337 
00338     def script_root(self):
00339         """The root path of the script without the trailing slash."""
00340         path = (self.environ.get('SCRIPT_NAME') or '').rstrip('/')
00341         return _decode_unicode(path, self.charset, self.encoding_errors)

Here is the call graph for this function:

The parsed stream if the submitted data was not multipart or
urlencoded form data.  This stream is the stream left by the form data
parser module after parsing.  This is *not* the WSGI input stream but
a wrapper around it that ensures the caller does not accidentally
read past `Content-Length`.

Definition at line 252 of file wrappers.py.

00252 
00253     def stream(self):
00254         """The parsed stream if the submitted data was not multipart or
00255         urlencoded form data.  This stream is the stream left by the form data
00256         parser module after parsing.  This is *not* the WSGI input stream but
00257         a wrapper around it that ensures the caller does not accidentally
00258         read past `Content-Length`.
00259         """
00260         self._load_form_data()
00261         return self._data_stream

Here is the call graph for this function:

The reconstructed current URL

Definition at line 343 of file wrappers.py.

00343 
00344     def url(self):
00345         """The reconstructed current URL"""
00346         return get_current_url(self.environ)

Here is the call graph for this function:

The full URL root (with hostname), this is the application root.

Definition at line 353 of file wrappers.py.

00353 
00354     def url_root(self):
00355         """The full URL root (with hostname), this is the application root."""
00356         return get_current_url(self.environ, True)

Here is the call graph for this function:

The current user agent.

Definition at line 809 of file wrappers.py.

00809 
00810     def user_agent(self):
00811         """The current user agent."""
00812         from werkzeug.useragents import UserAgent
00813         return UserAgent(self.environ)
00814 

Here is the caller graph for this function:

Combined multi dict for :attr:`args` and :attr:`form`.

Definition at line 294 of file wrappers.py.

00294 
00295     def values(self):
00296         """Combined multi dict for :attr:`args` and :attr:`form`."""
00297         return CombinedMultiDict([self.args, self.form])

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

string MoinMoin.support.werkzeug.wrappers.BaseRequest.charset = 'utf-8' [static, inherited]
Very basic request object.  This does not implement advanced stuff like
entity tag parsing or cache controls.  The request object is created with
the WSGI environment as first argument and will add itself to the WSGI
environment as ``'werkzeug.request'`` unless it's created with
`populate_request` set to False.

There are a couple of mixins available that add additional functionality
to the request object, there is also a class called `Request` which
subclasses `BaseRequest` and all the important mixins.

It's a good idea to create a custom subclass of the :class:`BaseRequest`
and add missing functionality either via mixins or direct implementation.
Here an example for such subclasses::

from werkzeug import BaseRequest, ETagRequestMixin

class Request(BaseRequest, ETagRequestMixin):
    pass

Request objects are **read only**.  As of 0.5 modifications are not
allowed in any place.  Unlike the lower level parsing functions the
request object will use immutable objects everywhere possible.

Per default the request object will assume all the text data is `utf-8`
encoded.  Please refer to `the unicode chapter <unicode.txt>`_ for more
details about customizing the behavior.

Per default the request object will be added to the WSGI
environment as `werkzeug.request` to support the debugging system.
If you don't want that, set `populate_request` to `False`.

If `shallow` is `True` the environment is initialized as shallow
object around the environ.  Every operation that would modify the
environ in any way (such as consuming form data) raises an exception
unless the `shallow` attribute is explicitly set to `False`.  This
is useful for middlewares where you don't want to consume the form
data by accident.  A shallow request is not populated to the WSGI
environment.

.. versionchanged:: 0.5
   read-only mode was enforced by using immutables classes for all
   data.

Definition at line 91 of file wrappers.py.

Initial value:
environ_property('CONTENT_LENGTH', None, int, str, doc='''
     The Content-Length entity-header field indicates the size of the
     entity-body in bytes or, in the case of the HEAD method, the size of
     the entity-body that would have been sent had the request been a
     GET.''')

Definition at line 968 of file wrappers.py.

Initial value:
environ_property('CONTENT_TYPE', doc='''
     The Content-Type entity-header field indicates the media type of
     the entity-body sent to the recipient or, in the case of the HEAD
     method, the media type that would have been sent had the request
     been a GET.''')

Definition at line 963 of file wrappers.py.

Initial value:
environ_property('HTTP_DATE', None, parse_date, doc='''
    The Date general-header field represents the date and time at which
    the message was originated, having the same semantics as orig-date
    in RFC 822.''')

Definition at line 978 of file wrappers.py.

Definition at line 94 of file wrappers.py.

Definition at line 122 of file wrappers.py.

Initial value:
environ_property('wsgi.input', 'The WSGI input stream.\n'
        'In general it\'s a bad idea to use this one because you can easily '
        'read past the boundary.  Use the :attr:`stream` instead.')

Definition at line 262 of file wrappers.py.

Definition at line 97 of file wrappers.py.

Initial value:
environ_property('wsgi.multiprocess', doc='''
    boolean that is `True` if the application is served by
    a WSGI server that spawns multiple processes.''')

Definition at line 407 of file wrappers.py.

Initial value:
environ_property('wsgi.multithread', doc='''
    boolean that is `True` if the application is served by
    a multithreaded WSGI server.''')

Definition at line 404 of file wrappers.py.

Initial value:
environ_property('wsgi.run_once', doc='''
    boolean that is `True` if the application will be executed only
    once in a process lifetime.  This is the case for CGI for example,
    but it's not guaranteed that the exeuction only happens one time.''')

Definition at line 410 of file wrappers.py.

Definition at line 108 of file wrappers.py.

Definition at line 119 of file wrappers.py.

Initial value:
environ_property('HTTP_MAX_FORWARDS', None, int, doc='''
     The Max-Forwards request-header field provides a mechanism with the
     TRACE and OPTIONS methods to limit the number of proxies or gateways
     that can forward the request to the next inbound server.''')

Definition at line 982 of file wrappers.py.

Initial value:
environ_property('REQUEST_METHOD', 'GET', read_only=True, doc=
        '''The transmission method. (For example ``'GET'`` or ``'POST'``).''')

Definition at line 369 of file wrappers.py.

Initial value:
environ_property('QUERY_STRING', '', read_only=True, doc=
        '''The URL parameters as raw bytestring.''')

Definition at line 367 of file wrappers.py.

Initial value:
environ_property('HTTP_REFERER', doc='''
    The Referer[sic] request-header field allows the client to specify,
    for the server's benefit, the address (URI) of the resource from which
    the Request-URI was obtained (the "referrer", although the header
    field is misspelled).''')

Definition at line 973 of file wrappers.py.

Initial value:
environ_property('REMOTE_USER', doc='''
    If the server supports user authentication, and the script is
    protected, this attribute contains the username the user has
    authenticated as.''')

Definition at line 391 of file wrappers.py.

Definition at line 125 of file wrappers.py.


Property Documentation

Initial value:
property(lambda x: x.environ['wsgi.url_scheme'] == 'https',
                         doc='`True` if the request is secure.')

Definition at line 402 of file wrappers.py.

Initial value:
property(lambda x: x.environ.get('HTTP_X_REQUESTED_WITH', '')
                      .lower() == 'xmlhttprequest', doc='''
        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.''')

Definition at line 396 of file wrappers.py.


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