Back to index

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

List of all members.

Public Member Functions

def force_type
def from_app
def iter_encoded
def set_cookie
def delete_cookie
def header_list
def is_streamed
def fix_headers
def close
def freeze
def __call__
def cache_control
def make_conditional
def add_etag
def set_etag
def get_etag
def freeze
def stream
def www_authenticate

Public Attributes

 response
 headers
 status
 direct_passthrough
 status_code

Static Public Attributes

string charset = 'utf-8'
int default_status = 200
string default_mimetype = 'text/plain'
tuple location
tuple age
tuple content_type
tuple content_length
tuple content_location
tuple content_encoding
tuple content_md5
tuple date
tuple expires
tuple last_modified
tuple vary
tuple content_language
tuple allow

Properties

 status_code
 data = property(_get_data, _set_data, doc=_get_data.__doc__)
 mimetype
 mimetype_params
 retry_after

Detailed Description

Full featured response object implementing the following mixins:

- :class:`ETagResponseMixin` for etag and cache control handling
- :class:`ResponseStreamMixin` to add support for the `stream` property
- :class:`CommonResponseDescriptorsMixin` for various HTTP descriptors
- :class:`WWWAuthenticateMixin` for HTTP authentication support

Definition at line 1190 of file wrappers.py.


Member Function Documentation

def MoinMoin.support.werkzeug.wrappers.BaseResponse.__call__ (   self,
  environ,
  start_response 
) [inherited]
Process this response as WSGI application.

:param environ: the WSGI environment.
:param start_response: the response callable provided by the WSGI
               server.

Definition at line 698 of file wrappers.py.

00698 
00699     def __call__(self, environ, start_response):
00700         """Process this response as WSGI application.
00701 
00702         :param environ: the WSGI environment.
00703         :param start_response: the response callable provided by the WSGI
00704                                server.
00705         """
00706         self.fix_headers(environ)
00707         if environ['REQUEST_METHOD'] == 'HEAD':
00708             resp = ()
00709         elif 100 <= self.status_code < 200 or self.status_code in (204, 304):
00710             # no response for 204/304.  the headers are adapted accordingly
00711             # by fix_headers()
00712             resp = ()
00713         elif self.direct_passthrough:
00714             resp = self.response
00715         else:
00716             resp = self.iter_encoded()
00717         start_response(self.status, self.header_list)
00718         return resp
00719 

Here is the call graph for this function:

def MoinMoin.support.werkzeug.wrappers.ETagResponseMixin.add_etag (   self,
  overwrite = False,
  weak = False 
) [inherited]
Add an etag for the current response if there is none yet.

Definition at line 877 of file wrappers.py.

00877 
00878     def add_etag(self, overwrite=False, weak=False):
00879         """Add an etag for the current response if there is none yet."""
00880         if overwrite or 'etag' not in self.headers:
00881             self.set_etag(generate_etag(self.data), weak)

Here is the call graph for this function:

Here is the caller graph for this function:

The Cache-Control general-header field is used to specify
directives that MUST be obeyed by all caching mechanisms along the
request/response chain.

Definition at line 834 of file wrappers.py.

00834 
00835     def cache_control(self):
00836         """The Cache-Control general-header field is used to specify
00837         directives that MUST be obeyed by all caching mechanisms along the
00838         request/response chain.
00839         """
00840         def on_update(cache_control):
00841             if not cache_control and 'cache-control' in self.headers:
00842                 del self.headers['cache-control']
00843             elif cache_control:
00844                 self.headers['Cache-Control'] = cache_control.to_header()
00845         return parse_cache_control_header(self.headers.get('cache-control'),
00846                                           on_update,
00847                                           ResponseCacheControl)

Here is the call graph for this function:

Close the wrapped response if possible.

Definition at line 687 of file wrappers.py.

00687 
00688     def close(self):
00689         """Close the wrapped response if possible."""
00690         if hasattr(self.response, 'close'):
00691             self.response.close()

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.wrappers.BaseResponse.delete_cookie (   self,
  key,
  path = '/',
  domain = None 
) [inherited]
Delete a cookie.  Fails silently if key doesn't exist.

:param key: the key (name) of the cookie to be deleted.
:param path: if the cookie that should be deleted was limited to a
     path, the path has to be defined here.
:param domain: if the cookie that should be deleted was limited to a
       domain, that domain has to be defined here.

Definition at line 635 of file wrappers.py.

00635 
00636     def delete_cookie(self, key, path='/', domain=None):
00637         """Delete a cookie.  Fails silently if key doesn't exist.
00638 
00639         :param key: the key (name) of the cookie to be deleted.
00640         :param path: if the cookie that should be deleted was limited to a
00641                      path, the path has to be defined here.
00642         :param domain: if the cookie that should be deleted was limited to a
00643                        domain, that domain has to be defined here.
00644         """
00645         self.set_cookie(key, expires=0, max_age=0, path=path, domain=domain)

Here is the call graph for this function:

def MoinMoin.support.werkzeug.wrappers.BaseResponse.fix_headers (   self,
  environ 
) [inherited]
This is automatically called right before the response is started
and should fix common mistakes in headers.  For example location
headers are joined with the root URL here.

:param environ: the WSGI environment of the request to be used for
        the applied fixes.

Definition at line 669 of file wrappers.py.

00669 
00670     def fix_headers(self, environ):
00671         """This is automatically called right before the response is started
00672         and should fix common mistakes in headers.  For example location
00673         headers are joined with the root URL here.
00674 
00675         :param environ: the WSGI environment of the request to be used for
00676                         the applied fixes.
00677         """
00678         if 'Location' in self.headers:
00679             self.headers['Location'] = urlparse.urljoin(
00680                 get_current_url(environ, root_only=True),
00681                 self.headers['Location']
00682             )
00683         if 100 <= self.status_code < 200 or self.status_code == 204:
00684             self.headers['Content-Length'] = 0
00685         elif self.status_code == 304:
00686             remove_entity_headers(self.headers)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.wrappers.BaseResponse.force_type (   cls,
  response,
  environ = None 
) [inherited]
Enforce that the WSGI response is a response object of the current
type.  Werkzeug will use the :class:`BaseResponse` internally in many
situations like the exceptions.  If you call :meth:`get_response` on an
exception you will get back a regular :class:`BaseResponse` object, even
if you are using a custom subclass.

This method can enforce a given response type, and it will also
convert arbitrary WSGI callables into response objects if an environ
is provided::

    # convert a Werkzeug response object into an instance of the
    # MyResponseClass subclass.
    response = MyResponseClass.force_type(response)

    # convert any WSGI application into a response object
    response = MyResponseClass.force_type(response, environ)

This is especially useful if you want to post-process responses in
the main dispatcher and use functionality provided by your subclass.

Keep in mind that this will modify response objects in place if
possible!

:param response: a response object or wsgi application.
:param environ: a WSGI environment object.
:return: a response object.

Definition at line 518 of file wrappers.py.

00518 
00519     def force_type(cls, response, environ=None):
00520         """Enforce that the WSGI response is a response object of the current
00521         type.  Werkzeug will use the :class:`BaseResponse` internally in many
00522         situations like the exceptions.  If you call :meth:`get_response` on an
00523         exception you will get back a regular :class:`BaseResponse` object, even
00524         if you are using a custom subclass.
00525 
00526         This method can enforce a given response type, and it will also
00527         convert arbitrary WSGI callables into response objects if an environ
00528         is provided::
00529 
00530             # convert a Werkzeug response object into an instance of the
00531             # MyResponseClass subclass.
00532             response = MyResponseClass.force_type(response)
00533 
00534             # convert any WSGI application into a response object
00535             response = MyResponseClass.force_type(response, environ)
00536 
00537         This is especially useful if you want to post-process responses in
00538         the main dispatcher and use functionality provided by your subclass.
00539 
00540         Keep in mind that this will modify response objects in place if
00541         possible!
00542 
00543         :param response: a response object or wsgi application.
00544         :param environ: a WSGI environment object.
00545         :return: a response object.
00546         """
00547         if not isinstance(response, BaseResponse):
00548             if environ is None:
00549                 raise TypeError('cannot convert WSGI application into '
00550                                 'response objects without an environ')
00551             response = BaseResponse(*run_wsgi_app(response, environ))
00552         response.__class__ = cls
00553         return response

Here is the call graph for this function:

Call this method if you want to make your response object ready for
being pickled.  This buffers the generator if there is one.

Definition at line 692 of file wrappers.py.

00692 
00693     def freeze(self):
00694         """Call this method if you want to make your response object ready for
00695         being pickled.  This buffers the generator if there is one.
00696         """
00697         BaseResponse.data.__get__(self)

def MoinMoin.support.werkzeug.wrappers.ETagResponseMixin.freeze (   self,
  no_etag = False 
) [inherited]
Call this method if you want to make your response object ready for
pickeling.  This buffers the generator if there is one.  This also
sets the etag unless `no_etag` is set to `True`.

Definition at line 892 of file wrappers.py.

00892 
00893     def freeze(self, no_etag=False):
00894         """Call this method if you want to make your response object ready for
00895         pickeling.  This buffers the generator if there is one.  This also
00896         sets the etag unless `no_etag` is set to `True`.
00897         """
00898         if not no_etag:
00899             self.add_etag()
00900         super(ETagResponseMixin, self).freeze()
00901 

Here is the call graph for this function:

def MoinMoin.support.werkzeug.wrappers.BaseResponse.from_app (   cls,
  app,
  environ,
  buffered = False 
) [inherited]
Create a new response object from an application output.  This
works best if you pass it an application that returns a generator all
the time.  Sometimes applications may use the `write()` callable
returned by the `start_response` function.  This tries to resolve such
edge cases automatically.  But if you don't get the expected output
you should set `buffered` to `True` which enforces buffering.

:param app: the WSGI application to execute.
:param environ: the WSGI environment to execute against.
:param buffered: set to `True` to enforce buffering.
:return: a response object.

Definition at line 555 of file wrappers.py.

00555 
00556     def from_app(cls, app, environ, buffered=False):
00557         """Create a new response object from an application output.  This
00558         works best if you pass it an application that returns a generator all
00559         the time.  Sometimes applications may use the `write()` callable
00560         returned by the `start_response` function.  This tries to resolve such
00561         edge cases automatically.  But if you don't get the expected output
00562         you should set `buffered` to `True` which enforces buffering.
00563 
00564         :param app: the WSGI application to execute.
00565         :param environ: the WSGI environment to execute against.
00566         :param buffered: set to `True` to enforce buffering.
00567         :return: a response object.
00568         """
00569         return cls(*run_wsgi_app(app, environ, buffered))

Here is the call graph for this function:

Return a tuple in the form ``(etag, is_weak)``.  If there is no
ETag the return value is ``(None, None)``.

Definition at line 886 of file wrappers.py.

00886 
00887     def get_etag(self):
00888         """Return a tuple in the form ``(etag, is_weak)``.  If there is no
00889         ETag the return value is ``(None, None)``.
00890         """
00891         return unquote_etag(self.headers.get('ETag'))

Here is the call graph for this function:

This returns the headers in the target charset as list.  It's used
in __call__ to get the headers for the response.

Definition at line 647 of file wrappers.py.

00647 
00648     def header_list(self):
00649         """This returns the headers in the target charset as list.  It's used
00650         in __call__ to get the headers for the response.
00651         """
00652         return self.headers.to_list(self.charset)

Here is the caller graph for this function:

If the response is streamed (the response is not a sequence) this
property is `True`.  In this case streamed means that there is no
information about the number of iterations.  This is usully `True`
if a generator is passed to the response object.

This is useful for checking before applying some sort of post
filtering that should not take place for streamed responses.

Definition at line 654 of file wrappers.py.

00654 
00655     def is_streamed(self):
00656         """If the response is streamed (the response is not a sequence) this
00657         property is `True`.  In this case streamed means that there is no
00658         information about the number of iterations.  This is usully `True`
00659         if a generator is passed to the response object.
00660 
00661         This is useful for checking before applying some sort of post
00662         filtering that should not take place for streamed responses.
00663         """
00664         try:
00665             len(self.response)
00666         except TypeError:
00667             return False
00668         return True

def MoinMoin.support.werkzeug.wrappers.BaseResponse.iter_encoded (   self,
  charset = None 
) [inherited]
Iter the response encoded with the encoding specified.  If no
encoding is given the encoding from the class is used.  Note that
this does not encode data that is already a bytestring.  If the
response object is invoked as WSGI application the return value
of this method is used as application iterator except if
:attr:`direct_passthrough` was activated.

Definition at line 597 of file wrappers.py.

00597 
00598     def iter_encoded(self, charset=None):
00599         """Iter the response encoded with the encoding specified.  If no
00600         encoding is given the encoding from the class is used.  Note that
00601         this does not encode data that is already a bytestring.  If the
00602         response object is invoked as WSGI application the return value
00603         of this method is used as application iterator except if
00604         :attr:`direct_passthrough` was activated.
00605         """
00606         charset = charset or self.charset or 'ascii'
00607         for item in self.response:
00608             if isinstance(item, unicode):
00609                 yield item.encode(charset)
00610             else:
00611                 yield str(item)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.wrappers.ETagResponseMixin.make_conditional (   self,
  request_or_environ 
) [inherited]
Make the response conditional to the request.  This method works
best if an etag was defined for the response already.  The `add_etag`
method can be used to do that.  If called without etag just the date
header is set.

This does nothing if the request method in the request or environ is
anything but GET or HEAD.

It does not remove the body of the response because that's something
the :meth:`__call__` function does for us automatically.

Returns self so that you can do ``return resp.make_conditional(req)``
but modifies the object in-place.

:param request_or_environ: a request object or WSGI environment to be
                   used to make the response conditional
                   against.

Definition at line 848 of file wrappers.py.

00848 
00849     def make_conditional(self, request_or_environ):
00850         """Make the response conditional to the request.  This method works
00851         best if an etag was defined for the response already.  The `add_etag`
00852         method can be used to do that.  If called without etag just the date
00853         header is set.
00854 
00855         This does nothing if the request method in the request or environ is
00856         anything but GET or HEAD.
00857 
00858         It does not remove the body of the response because that's something
00859         the :meth:`__call__` function does for us automatically.
00860 
00861         Returns self so that you can do ``return resp.make_conditional(req)``
00862         but modifies the object in-place.
00863 
00864         :param request_or_environ: a request object or WSGI environment to be
00865                                    used to make the response conditional
00866                                    against.
00867         """
00868         environ = getattr(request_or_environ, 'environ', request_or_environ)
00869         if environ['REQUEST_METHOD'] in ('GET', 'HEAD'):
00870             self.headers['Date'] = http_date()
00871             if 'content-length' in self.headers:
00872                 self.headers['Content-Length'] = len(self.data)
00873             if not is_resource_modified(environ, self.headers.get('etag'), None,
00874                                         self.headers.get('last-modified')):
00875                 self.status_code = 304
00876         return self

Here is the call graph for this function:

def MoinMoin.support.werkzeug.wrappers.BaseResponse.set_cookie (   self,
  key,
  value = '',
  max_age = None,
  expires = None,
  path = '/',
  domain = None,
  secure = None,
  httponly = False 
) [inherited]
Sets a cookie. The parameters are the same as in the cookie `Morsel`
object in the Python standard library but it accepts unicode data, too.

:param key: the key (name) of the cookie to be set.
:param value: the value of the cookie.
:param max_age: should be a number of seconds, or `None` (default) if
        the cookie should last only as long as the client's
        browser session.
:param expires: should be a `datetime` object or UNIX timestamp.
:param domain: 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.
:param path: limits the cookie to a given path, per default it will
     span the whole domain.

Definition at line 613 of file wrappers.py.

00613 
00614                    path='/', domain=None, secure=None, httponly=False):
00615         """Sets a cookie. The parameters are the same as in the cookie `Morsel`
00616         object in the Python standard library but it accepts unicode data, too.
00617 
00618         :param key: the key (name) of the cookie to be set.
00619         :param value: the value of the cookie.
00620         :param max_age: should be a number of seconds, or `None` (default) if
00621                         the cookie should last only as long as the client's
00622                         browser session.
00623         :param expires: should be a `datetime` object or UNIX timestamp.
00624         :param domain: if you want to set a cross-domain cookie.  For example,
00625                        ``domain=".example.com"`` will set a cookie that is
00626                        readable by the domain ``www.example.com``,
00627                        ``foo.example.com`` etc.  Otherwise, a cookie will only
00628                        be readable by the domain that set it.
00629         :param path: limits the cookie to a given path, per default it will
00630                      span the whole domain.
00631         """
00632         self.headers.add('Set-Cookie', dump_cookie(key, value, max_age,
00633                          expires, path, domain, secure, httponly,
00634                          self.charset))

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.wrappers.ETagResponseMixin.set_etag (   self,
  etag,
  weak = False 
) [inherited]
Set the etag, and override the old one if there was one.

Definition at line 882 of file wrappers.py.

00882 
00883     def set_etag(self, etag, weak=False):
00884         """Set the etag, and override the old one if there was one."""
00885         self.headers['ETag'] = quote_etag(etag, weak)

Here is the call graph for this function:

Here is the caller graph for this function:

The response iterable as write-only stream.

Definition at line 950 of file wrappers.py.

00950 
00951     def stream(self):
00952         """The response iterable as write-only stream."""
00953         return ResponseStream(self)
00954 

The `WWW-Authenticate` header in a parsed form.

Definition at line 1164 of file wrappers.py.

01164 
01165     def www_authenticate(self):
01166         """The `WWW-Authenticate` header in a parsed form."""
01167         def on_update(www_auth):
01168             if not www_auth and 'www-authenticate' in self.headers:
01169                 del self.headers['www-authenticate']
01170             elif www_auth:
01171                 self.headers['WWW-Authenticate'] = www_auth.to_header()
01172         header = self.headers.get('www-authenticate')
01173         return parse_www_authenticate_header(header, on_update)
01174 

Here is the call graph for this function:


Member Data Documentation

Initial value:
header_property('Age', None, parse_date, http_date, doc='''
    The Age response-header field conveys the sender's estimate of the
    amount of time since the response (or its revalidation) was
    generated at the origin server.

    Age values are non-negative decimal integers, representing time in
    seconds.''')

Definition at line 1056 of file wrappers.py.

Initial value:
_set_property('Allow', doc='''
    The Allow entity-header field lists the set of methods supported
    by the resource identified by the Request-URI. The purpose of this
    field is strictly to inform the recipient of valid methods
    associated with the resource. An Allow header field MUST be
    present in a 405 (Method Not Allowed) response.''')

Definition at line 1149 of file wrappers.py.

string MoinMoin.support.werkzeug.wrappers.BaseResponse.charset = 'utf-8' [static, inherited]

Definition at line 483 of file wrappers.py.

Initial value:
header_property('Content-Encoding', doc='''
    The Content-Encoding entity-header field is used as a modifier to the
    media-type.  When present, its value indicates what additional content
    codings have been applied to the entity-body, and thus what decoding
    mechanisms must be applied in order to obtain the media-type
    referenced by the Content-Type header field.''')

Definition at line 1078 of file wrappers.py.

Initial value:
_set_property('Content-Language', doc='''
     The Content-Language entity-header field describes the natural
     language(s) of the intended audience for the enclosed entity.  Note
     that this might not be equivalent to all the languages used within
     the entity-body.''')

Definition at line 1144 of file wrappers.py.

Initial value:
header_property('Content-Length', None, int, str, doc='''
    The Content-Length entity-header field indicates the size of the
    entity-body, in decimal number of OCTETs, sent to the recipient 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 1068 of file wrappers.py.

Initial value:
header_property('Content-Location', doc='''
    The Content-Location entity-header field MAY be used to supply the
    resource location for the entity enclosed in the message when that
    entity is accessible from a location separate from the requested
    resource's URI.''')

Definition at line 1073 of file wrappers.py.

Initial value:
header_property('Content-MD5', doc='''
     The Content-MD5 entity-header field, as defined in RFC 1864, is an
     MD5 digest of the entity-body for the purpose of providing an
     end-to-end message integrity check (MIC) of the entity-body.  (Note:
     a MIC is good for detecting accidental modification of the
     entity-body in transit, but is not proof against malicious attacks.)
    ''')

Definition at line 1084 of file wrappers.py.

Initial value:
header_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 1063 of file wrappers.py.

Initial value:
header_property('Date', None, parse_date, http_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 1091 of file wrappers.py.

string MoinMoin.support.werkzeug.wrappers.BaseResponse.default_mimetype = 'text/plain' [static, inherited]

Definition at line 485 of file wrappers.py.

Definition at line 484 of file wrappers.py.

Definition at line 515 of file wrappers.py.

Initial value:
header_property('Expires', None, parse_date, http_date, doc='''
    The Expires entity-header field gives the date/time after which the
    response is considered stale. A stale cache entry may not normally be
    returned by a cache.''')

Definition at line 1095 of file wrappers.py.

Definition at line 496 of file wrappers.py.

Initial value:
header_property('Last-Modified', None, parse_date,
                                    http_date, doc='''
        The Last-Modified entity-header field indicates the date and time at
        which the origin server believes the variant was last modified.''')

Definition at line 1099 of file wrappers.py.

Initial value:
header_property('Location', doc='''
    The Location response-header field is used to redirect the recipient
    to a location other than the Request-URI for completion of the request
    or identification of a new resource.''')

Definition at line 1052 of file wrappers.py.

Definition at line 490 of file wrappers.py.

Definition at line 514 of file wrappers.py.

Definition at line 874 of file wrappers.py.

Initial value:
_set_property('Vary', doc='''
     The Vary field value indicates the set of request-header fields that
     fully determines, while the response is fresh, whether a cache is
     permitted to use the response to reply to a subsequent request
     without revalidation.''')

Definition at line 1139 of file wrappers.py.


Property Documentation

MoinMoin.support.werkzeug.wrappers.BaseResponse.data = property(_get_data, _set_data, doc=_get_data.__doc__) [static, inherited]

Definition at line 594 of file wrappers.py.

Initial value:
property(_get_mimetype, _set_mimetype, doc='''
    The mimetype (content type without charset etc.)''')

Definition at line 1043 of file wrappers.py.

Initial value:
property(_get_mimetype_params, doc='''
    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.5
    ''')

Definition at line 1045 of file wrappers.py.

Initial value:
property(_get_retry_after, _set_retry_after, doc='''
    The Retry-After response-header field can be used with a 503 (Service
    Unavailable) response to indicate how long the service is expected
    to be unavailable to the requesting client.

    Time in seconds until expiration or date.''')

Definition at line 1122 of file wrappers.py.

Initial value:
property(_get_status_code, _set_status_code,
                           'The HTTP Status code as number')

Definition at line 580 of file wrappers.py.


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