webob – Request/Response objects¶
Request¶
-
class
webob.Request(environ, charset=None, unicode_errors=None, decode_param_names=None, **kw)¶ The default request implementation
Parse four Accept* headers used in server-driven content negotiation.
The four headers are Accept, Accept-Charset, Accept-Encoding and
Accept-Language.
-
class
webob.acceptparse.Accept¶ Represent an
Acceptheader.Base class for
AcceptValidHeader,AcceptNoHeader, andAcceptInvalidHeader.
-
class
webob.acceptparse.MIMEAccept(*args, **kw)¶ Backwards compatibility shim for AcceptValidHeader that acts like the old MIMEAccept from WebOb 1.7.
Deprecated since version 1.8.
Instead of directly creating the Accept object, please see:
create_accept_header(header_value), which will create the appropriate object.
-
class
webob.byterange.Range(start, end)¶ Represents the Range header.
Represents the Cache-Control header
-
class
webob.cachecontrol.CacheControl(properties, type)¶ Represents the Cache-Control header.
By giving a type of
'request'or'response'you can control what attributes are allowed (some Cache-Control values only apply to requests or responses).
Does parsing of ETag-related headers: If-None-Matches, If-Matches
Also If-Range parsing
-
class
webob.etag.ETagMatcher(etags)¶
-
class
webob.etag.IfRange(etag)¶
Response¶
-
class
webob.Response(body=None, status=None, headerlist=None, app_iter=None, content_type=None, conditional_response=None, charset=<object object>, **kw)¶ Represents a WSGI response.
If no arguments are passed, creates a
Responsethat uses a variety of defaults. The defaults may be changed by sub-classing theResponse. See the sub-classing notes.Variables: - body (bytes or text_type) – If
bodyis atext_type, then it will be encoded using eithercharsetwhen provided ordefault_encodingwhencharsetis not provided if thecontent_typeallows for acharset. This argument is mutually exclusive withapp_iter. - status (int or str) – Either an
intor a string that is an integer followed by the status text. If it is an integer, it will be converted to a proper status that also includes the status text. Any existing status text will be kept. Non-standard values are allowed. - headerlist (list) – A list of HTTP headers for the response.
- app_iter (iterable) – An iterator that is used as the body of the
response. Should conform to the WSGI requirements and should provide
bytes. This argument is mutually exclusive with
body. - content_type (str or None) – Sets the
Content-Typeheader. If nocontent_typeis provided, and there is noheaderlist, thedefault_content_typewill be automatically set. Ifheaderlistis provided then this value is ignored. - conditional_response (bool) – Used to change the behavior of the
Responseto check the original request for conditional response headers. Seeconditional_response_app()for more information. - charset (str or None) – Adds a
charsetContent-Typeparameter. If nocharsetis provided and theContent-Typeis text, then thedefault_charsetwill automatically be added. Currently the onlyContent-Type’s that allow for acharsetare defined to betext/*,application/xml, and*/*+xml. Any otherContent-Type’s will not have acharsetadded. If aheaderlistis provided this value is ignored.
All other response attributes may be set on the response by providing them as keyword arguments. A
TypeErrorwill be raised for any unexpected keywords.Sub-classing notes:
- The
default_content_typeis used as the default for theContent-Typeheader that is returned on the response. It istext/html. - The
default_charsetis used as the default character set to return on theContent-Typeheader, if theContent-Typeallows for acharsetparameter. Currently the onlyContent-Type’s that allow for acharsetare defined to be:text/*,application/xml, and*/*+xml. Any otherContent-Type’s will not have acharsetadded. - The
unicode_errorsis set tostrict, and access on atextwill raise an error if it fails to decode thebody. default_conditional_responseis set toFalse. This flag may be set toTrueso that allResponseobjects will attempt to check the original request for conditional response headers. Seeconditional_response_app()for more information.default_body_encodingis set to ‘UTF-8’ by default. It exists to allow users to get/set theResponseobject using.text, even if nocharsethas been set for theContent-Type.
- body (bytes or text_type) – If
-
class
webob.byterange.ContentRange(start, stop, length)¶ Represents the Content-Range header
This header is
start-stop/length, where start-stop and length can be*(represented as None in the attributes).
-
class
webob.cachecontrol.CacheControl(properties, type) Represents the Cache-Control header.
By giving a type of
'request'or'response'you can control what attributes are allowed (some Cache-Control values only apply to requests or responses).
Misc Functions¶
-
webob.html_escape(s)¶ HTML-escape a string or object
This converts any non-string objects passed into it to strings (actually, using
unicode()). All values returned are non-unicode strings (using&#num;entities for all non-ASCII characters).None is treated specially, and returns the empty string.
-
class
webob.response.AppIterRange(app_iter, start, stop)¶ Wraps an
app_iter, returning just a range of bytes.
Gives a multi-value dictionary object (MultiDict) plus several wrappers
-
class
webob.multidict.MultiDict(*args, **kw)¶ An ordered dictionary that can have multiple values for each key. Adds the methods getall, getone, mixed and extend and add to the normal dictionary interface.
-
class
webob.multidict.NestedMultiDict(*dicts)¶ Wraps several MultiDict objects, treating it as one large MultiDict
-
class
webob.multidict.NoVars(reason=None)¶ Represents no variables; used when no variables are applicable.
This is read-only