from cherrypy._cperror import format_exc, bare_error
from cherrypy.lib import http, file_generator
class Hook(object):
__metaclass__ = cherrypy._AttributeDocstrings
callback = None
callback__doc = '\n The bare callable that this Hook object is wrapping, which will\n be called when the Hook is called.'
failsafe = False
failsafe__doc = '\n If True, the callback is guaranteed to run even if other callbacks\n from the same call point raise exceptions.'
priority = 50
priority__doc = '\n Defines the order of execution for a list of Hooks. Priority numbers\n should be limited to the closed interval [0, 100], but values outside\n this range are acceptable, as are fractional values.'
kwargs = { }
kwargs__doc = '\n A set of keyword arguments that will be passed to the\n callable on each call.'
prev__doc = '\n The previous Request object (if any). This should be None\n unless we are processing an InternalRedirect.'
local = http.Host('127.0.0.1', 80)
local__doc = 'An http.Host(ip, port, hostname) object for the server socket.'
remote = http.Host('127.0.0.1', 1111)
remote__doc = 'An http.Host(ip, port, hostname) object for the client socket.'
scheme = 'http'
scheme__doc = "\n The protocol used between client and server. In most cases,\n this will be either 'http' or 'https'."
server_protocol = 'HTTP/1.1'
server_protocol__doc = '\n The HTTP version for which the HTTP server is at least\n conditionally compliant.'
base = ''
base__doc = 'The (scheme://host) portion of the requested URL.'
request_line = ''
request_line__doc = '\n The complete Request-Line received from the client. This is a\n single string consisting of the request method, URI, and protocol\n version (joined by spaces). Any final CRLF is removed.'
method = 'GET'
method__doc = '\n Indicates the HTTP method to be performed on the resource identified\n by the Request-URI. Common methods include GET, HEAD, POST, PUT, and\n DELETE. CherryPy allows any extension method; however, various HTTP\n servers and gateways may restrict the set of allowable methods.\n CherryPy applications SHOULD restrict the set (on a per-URI basis).'
query_string = ''
query_string__doc = "\n The query component of the Request-URI, a string of information to be\n interpreted by the resource. The query portion of a URI follows the\n path component, and is separated by a '?'. For example, the URI\n 'http://www.cherrypy.org/wiki?a=3&b=4' has the query component,\n 'a=3&b=4'."
protocol = (1, 1)
protocol__doc = "The HTTP protocol version corresponding to the set\n of features which should be allowed in the response. If BOTH\n the client's request message AND the server's level of HTTP\n compliance is HTTP/1.1, this attribute will be the tuple (1, 1).\n If either is 1.0, this attribute will be the tuple (1, 0).\n Lower HTTP protocol versions are not explicitly supported."
params = { }
params__doc = "\n A dict which combines query string (GET) and request entity (POST)\n variables. This is populated in two stages: GET params are added\n before the 'on_start_resource' hook, and POST params are added\n between the 'before_request_body' and 'before_handler' hooks."
header_list = []
header_list__doc = '\n A list of the HTTP request headers as (name, value) tuples.\n In general, you should use request.headers (a dict) instead.'
headers = http.HeaderMap()
headers__doc = "\n A dict-like object containing the request headers. Keys are header\n names (in Title-Case format); however, you may get and set them in\n a case-insensitive manner. That is, headers['Content-Type'] and\n headers['content-type'] refer to the same value. Values are header\n values (decoded according to RFC 2047 if necessary). See also:\n http.HeaderMap, http.HeaderElement."
cookie = Cookie.SimpleCookie()
cookie__doc = 'See help(Cookie).'
rfile = None
rfile__doc = "\n If the request included an entity (body), it will be available\n as a stream in this attribute. However, the rfile will normally\n be read for you between the 'before_request_body' hook and the\n 'before_handler' hook, and the resulting string is placed into\n either request.params or the request.body attribute.\n \n You may disable the automatic consumption of the rfile by setting\n request.process_request_body to False, either in config for the desired\n path, or in an 'on_start_resource' or 'before_request_body' hook.\n \n WARNING: In almost every case, you should not attempt to read from the\n rfile stream after CherryPy's automatic mechanism has read it. If you\n turn off the automatic parsing of rfile, you should read exactly the\n number of bytes specified in request.headers['Content-Length'].\n Ignoring either of these warnings may result in a hung request thread\n or in corruption of the next (pipelined) request.\n "
process_request_body = True
process_request_body__doc = '\n If True, the rfile (if any) is automatically read and parsed,\n and the result placed into request.params or request.body.'
methods_with_bodies = ('POST', 'PUT')
methods_with_bodies__doc = '\n A sequence of HTTP methods for which CherryPy will automatically\n attempt to read a body from the rfile.'
body = None
body__doc = "\n If the request Content-Type is 'application/x-www-form-urlencoded'\n or multipart, this will be None. Otherwise, this will contain the\n request entity body as a string; this value is set between the\n 'before_request_body' and 'before_handler' hooks (assuming that\n process_request_body is True)."
body_params = None
body_params__doc = '\n If the request Content-Type is \'application/x-www-form-urlencoded\' or\n multipart, this will be a dict of the params pulled from the entity\n body; that is, it will be the portion of request.params that come\n from the message body (sometimes called "POST params", although they\n can be sent with various HTTP method verbs). This value is set between\n the \'before_request_body\' and \'before_handler\' hooks (assuming that\n process_request_body is True).'
dispatch = cherrypy.dispatch.Dispatcher()
dispatch__doc = "\n The object which looks up the 'page handler' callable and collects\n config for the current request based on the path_info, other\n request attributes, and the application architecture. The core\n calls the dispatcher as early as possible, passing it a 'path_info'\n argument.\n \n The default dispatcher discovers the page handler by matching path_info\n to a hierarchical arrangement of objects, starting at request.app.root.\n See help(cherrypy.dispatch) for more information."
script_name = ''
script_name__doc = '\n The \'mount point\' of the application which is handling this request.\n \n This attribute MUST NOT end in a slash. If the script_name refers to\n the root of the URI, it MUST be an empty string (not "/").\n '
path_info = '/'
path_info__doc = "\n The 'relative path' portion of the Request-URI. This is relative\n to the script_name ('mount point') of the application which is\n handling this request."
login = None
login__doc = "\n When authentication is used during the request processing this is\n set to 'False' if it failed and to the 'username' value if it succeeded.\n The default 'None' implies that no authentication happened."
app = None
app__doc = 'The cherrypy.Application object which is handling this request.'
handler = None
handler__doc = '\n The function, method, or other callable which CherryPy will call to\n produce the response. The discovery of the handler and the arguments\n it will receive are determined by the request.dispatch object.\n By default, the handler is discovered by walking a tree of objects\n starting at request.app.root, and is then passed all HTTP params\n (from the query string and POST body) as keyword arguments.'
toolmaps = { }
toolmaps__doc = '\n A nested dict of all Toolboxes and Tools in effect for this request,\n of the form: {Toolbox.namespace: {Tool.name: config dict}}.'
config = None
config__doc = '\n A flat dict of all configuration entries which apply to the\n current request. These entries are collected from global config,\n application config (based on request.path_info), and from handler\n config (exactly how is governed by the request.dispatch object in\n effect for this request; by default, handler config can be attached\n anywhere in the tree between request.app.root and the final handler,\n and inherits downward).'
is_index = None
is_index__doc = "\n This will be True if the current request is mapped to an 'index'\n resource handler (also, a 'default' handler if path_info ends with\n a slash). The value may be used to automatically redirect the\n user-agent to a 'more canonical' URL which either adds or removes\n the trailing slash. See cherrypy.tools.trailing_slash."
hooks = HookMap(hookpoints)
hooks__doc = '\n A HookMap (dict-like object) of the form: {hookpoint: [hook, ...]}.\n Each key is a str naming the hook point, and each value is a list\n of hooks which will be called at that hook point during this request.\n The list of hooks is generally populated as early as possible (mostly\n from Tools specified in config), but may be extended at any time.\n See also: _cprequest.Hook, _cprequest.HookMap, and cherrypy.tools.'
error_response__doc = '\n The no-arg callable which will handle unexpected, untrapped errors\n during request processing. This is not used for expected exceptions\n (like NotFound, HTTPError, or HTTPRedirect) which are raised in\n response to expected conditions (those should be customized either\n via request.error_page or by overriding HTTPError.set_response).\n By default, error_response uses HTTPError(500) to return a generic\n error response to the user-agent.'
error_page = { }
error_page__doc = "\n A dict of {error code: response filename or callable} pairs.\n \n The error code must be an int representing a given HTTP error code,\n or the string 'default', which will be used if no matching entry\n is found for a given numeric code.\n \n If a filename is provided, the file should contain a Python string-\n formatting template, and can expect by default to receive format \n values with the mapping keys %(status)s, %(message)s, %(traceback)s,\n and %(version)s. The set of format mappings can be extended by\n overriding HTTPError.set_response.\n \n If a callable is provided, it will be called by default with keyword \n arguments 'status', 'message', 'traceback', and 'version', as for a\n string-formatting template. The callable must return a string which\n will be set to response.body. It may also override headers or perform\n any other processing.\n \n If no entry is given for an error code, and no 'default' entry exists,\n a default template will be used.\n "
show_tracebacks = True
show_tracebacks__doc = '\n If True, unexpected errors encountered during request processing will\n include a traceback in the response body.'
throws__doc = 'The sequence of exceptions which Request.run does not trap.'
throw_errors = False
throw_errors__doc = "\n If True, Request.run will not trap any errors (except HTTPRedirect and\n HTTPError, which are more properly called 'exceptions', not errors)."
closed = False
closed__doc = '\n True once the close method has been called, False otherwise.'
stage = None
stage__doc = '\n A string containing the stage reached in the request-handling process.\n This is useful when debugging a live server with hung requests.'
self.body_params = p = http.params_from_CGI_form(forms)
self.params.update(p)
def handle_error(self):
try:
self.hooks.run('before_error_response')
if self.error_response:
self.error_response()
self.hooks.run('after_error_response')
cherrypy.response.finalize()
except cherrypy.HTTPRedirect:
inst = None
inst.set_response()
cherrypy.response.finalize()
class Body(object):
def __get__(self, obj, objclass = None):
if obj is None:
return self
return obj._body
def __set__(self, obj, value):
if isinstance(value, basestring):
if value:
value = [
value]
else:
value = []
elif isinstance(value, types.FileType):
value = file_generator(value)
elif value is None:
value = []
obj._body = value
class Response(object):
__metaclass__ = cherrypy._AttributeDocstrings
status = ''
status__doc = 'The HTTP Status-Code and Reason-Phrase.'
header_list = []
header_list__doc = '\n A list of the HTTP response headers as (name, value) tuples.\n In general, you should use response.headers (a dict) instead.'
headers = http.HeaderMap()
headers__doc = "\n A dict-like object containing the response headers. Keys are header\n names (in Title-Case format); however, you may get and set them in\n a case-insensitive manner. That is, headers['Content-Type'] and\n headers['content-type'] refer to the same value. Values are header\n values (decoded according to RFC 2047 if necessary). See also:\n http.HeaderMap, http.HeaderElement."
cookie = Cookie.SimpleCookie()
cookie__doc = 'See help(Cookie).'
body = Body()
body__doc = 'The body (entity) of the HTTP response.'
time = None
time__doc = 'The value of time.time() when created. Use in HTTP dates.'
timeout = 300
timeout__doc = 'Seconds after which the response will be aborted.'
timed_out = False
timed_out__doc = '\n Flag to indicate the response should be aborted, because it has\n exceeded its timeout.'
stream = False
stream__doc = 'If False, buffer the response body.'