Ic@s>ddlZddlZddlZddlZddlZddlZddlmZmZddlm Z m Z ddl m Z m Z defdYZdefdYZd Zd Zd Zd Zd dddddddgZdefdYZdefdYZdefdYZdS(iN(t_cpcgifst _cpconfig(t format_exct bare_error(thttptfile_generatortHookcBsqeZdZejZd ZdZe Z dZ dZ dZ iZdZd d dZdZdZd ZRS( s<A callback and its metadata: failsafe, priority, and kwargs.sk The bare callable that this Hook object is wrapping, which will be called when the Hook is called.sv If True, the callback is guaranteed to run even if other callbacks from the same call point raise exceptions.i2s Defines the order of execution for a list of Hooks. Priority numbers should be limited to the closed interval [0, 100], but values outside this range are acceptable, as are fractional values.sU A set of keyword arguments that will be passed to the callable on each call.cKsj||_|dkr*t|dt}n||_|dkrTt|dd}n||_||_dS(Ntfailsafetpriorityi2(tcallbacktNonetgetattrtFalseRRtkwargs(tselfR RRR ((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyt__init__(s     cCst|j|jS(N(tcmpR(Rtother((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyt__cmp__5scCs|j|jS(s!Run self.callback(**self.kwargs).(R R (R((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyt__call__8sc Csg|j}d|j|j|j|j|jdjg|jjD]\}}d||f^q@fS(Ns0%s.%s(callback=%r, failsafe=%r, priority=%r, %s)s, s%s=%r( t __class__t __module__t__name__R RRtjoinR t iteritems(Rtclstktv((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyt__repr__<s    N(RRt__doc__tcherrypyt_AttributeDocstringst __metaclass__R R t callback__docR Rt failsafe__docRt priority__docR t kwargs__docRRRR(((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyRs   tHookMapcBsSeZdZddZdZdddZdZdZeZ dZ RS(s:A map of call points to lists of callbacks (Hook objects).cCs4tj|}x|pgD]}g||ZdZe j ddZ dZ e j ddZ dZdZdZd Zd Zd Zd Zd Zd ZdZdZd ZdZd?ZdZiZdZgZdZ e j!Z"dZ#e$j%Z&dZ'd>Z(dZ)e*Z+dZ,d@Z-dZ.d>Z/dZ0d>Z1dZ2ej3j4Z3dZ5d Z6dZ7d Z8d!Z9d>Z:d"Z;d>Z<d#Z=d>Z>d$Z?iZ@d%ZAd>ZBd&ZCd>ZDd'ZEeFeGZHd(ZIejJd)jKZLd*ZMiZNd+ZOe*ZPd,ZQeReSejTfZUd-ZVeWZXd.ZYeWZZd/Z[d>Z\d0Z]e^j_ie`d16ead26ebd36ecd46ejdd56Zedd d6Zfd7Zgd8Zhd9Zid:Zjd;Zkd<Zld=ZmRS(As0An HTTP request. This object represents the metadata of an HTTP request message; that is, it contains attributes which describe the environment in which the request URL, headers, and body were sent (if you want tools to interpret the headers and body, those are elsewhere, mostly in Tools). This 'metadata' consists of socket data, transport characteristics, and the Request-Line. This object also contains data regarding the configuration in effect for the given URL, and the execution plan for generating a response. sp The previous Request object (if any). This should be None unless we are processing an InternalRedirect.s 127.0.0.1iPs>An http.Host(ip, port, hostname) object for the server socket.iWs>An http.Host(ip, port, hostname) object for the client socket.Rsk The protocol used between client and server. In most cases, this will be either 'http' or 'https'.sHTTP/1.1sX The HTTP version for which the HTTP server is at least conditionally compliant.ts1The (scheme://host) portion of the requested URL.s The complete Request-Line received from the client. This is a single string consisting of the request method, URI, and protocol version (joined by spaces). Any final CRLF is removed.tGETsf Indicates the HTTP method to be performed on the resource identified by the Request-URI. Common methods include GET, HEAD, POST, PUT, and DELETE. CherryPy allows any extension method; however, various HTTP servers and gateways may restrict the set of allowable methods. CherryPy applications SHOULD restrict the set (on a per-URI basis).s) The query component of the Request-URI, a string of information to be interpreted by the resource. The query portion of a URI follows the path component, and is separated by a '?'. For example, the URI 'http://www.cherrypy.org/wiki?a=3&b=4' has the query component, 'a=3&b=4'.isThe HTTP protocol version corresponding to the set of features which should be allowed in the response. If BOTH the client's request message AND the server's level of HTTP compliance is HTTP/1.1, this attribute will be the tuple (1, 1). If either is 1.0, this attribute will be the tuple (1, 0). Lower HTTP protocol versions are not explicitly supported.s A dict which combines query string (GET) and request entity (POST) variables. This is populated in two stages: GET params are added before the 'on_start_resource' hook, and POST params are added between the 'before_request_body' and 'before_handler' hooks.s A list of the HTTP request headers as (name, value) tuples. In general, you should use request.headers (a dict) instead.s A dict-like object containing the request headers. Keys are header names (in Title-Case format); however, you may get and set them in a case-insensitive manner. That is, headers['Content-Type'] and headers['content-type'] refer to the same value. Values are header values (decoded according to RFC 2047 if necessary). See also: http.HeaderMap, http.HeaderElement.sSee help(Cookie).s If the request included an entity (body), it will be available as a stream in this attribute. However, the rfile will normally be read for you between the 'before_request_body' hook and the 'before_handler' hook, and the resulting string is placed into either request.params or the request.body attribute. You may disable the automatic consumption of the rfile by setting request.process_request_body to False, either in config for the desired path, or in an 'on_start_resource' or 'before_request_body' hook. WARNING: In almost every case, you should not attempt to read from the rfile stream after CherryPy's automatic mechanism has read it. If you turn off the automatic parsing of rfile, you should read exactly the number of bytes specified in request.headers['Content-Length']. Ignoring either of these warnings may result in a hung request thread or in corruption of the next (pipelined) request. s If True, the rfile (if any) is automatically read and parsed, and the result placed into request.params or request.body.tPOSTtPUTsp A sequence of HTTP methods for which CherryPy will automatically attempt to read a body from the rfile.s7 If the request Content-Type is 'application/x-www-form-urlencoded' or multipart, this will be None. Otherwise, this will contain the request entity body as a string; this value is set between the 'before_request_body' and 'before_handler' hooks (assuming that process_request_body is True).s If the request Content-Type is 'application/x-www-form-urlencoded' or multipart, this will be a dict of the params pulled from the entity body; that is, it will be the portion of request.params that come from the message body (sometimes called "POST params", although they can be sent with various HTTP method verbs). This value is set between the 'before_request_body' and 'before_handler' hooks (assuming that process_request_body is True).s The object which looks up the 'page handler' callable and collects config for the current request based on the path_info, other request attributes, and the application architecture. The core calls the dispatcher as early as possible, passing it a 'path_info' argument. The default dispatcher discovers the page handler by matching path_info to a hierarchical arrangement of objects, starting at request.app.root. See help(cherrypy.dispatch) for more information.s The 'mount point' of the application which is handling this request. This attribute MUST NOT end in a slash. If the script_name refers to the root of the URI, it MUST be an empty string (not "/"). t/s The 'relative path' portion of the Request-URI. This is relative to the script_name ('mount point') of the application which is handling this request.s When authentication is used during the request processing this is set to 'False' if it failed and to the 'username' value if it succeeded. The default 'None' implies that no authentication happened.s?The cherrypy.Application object which is handling this request.s The function, method, or other callable which CherryPy will call to produce the response. The discovery of the handler and the arguments it will receive are determined by the request.dispatch object. By default, the handler is discovered by walking a tree of objects starting at request.app.root, and is then passed all HTTP params (from the query string and POST body) as keyword arguments.s A nested dict of all Toolboxes and Tools in effect for this request, of the form: {Toolbox.namespace: {Tool.name: config dict}}.s A flat dict of all configuration entries which apply to the current request. These entries are collected from global config, application config (based on request.path_info), and from handler config (exactly how is governed by the request.dispatch object in effect for this request; by default, handler config can be attached anywhere in the tree between request.app.root and the final handler, and inherits downward).sO This will be True if the current request is mapped to an 'index' resource handler (also, a 'default' handler if path_info ends with a slash). The value may be used to automatically redirect the user-agent to a 'more canonical' URL which either adds or removes the trailing slash. See cherrypy.tools.trailing_slash.s A HookMap (dict-like object) of the form: {hookpoint: [hook, ...]}. Each key is a str naming the hook point, and each value is a list of hooks which will be called at that hook point during this request. The list of hooks is generally populated as early as possible (mostly from Tools specified in config), but may be extended at any time. See also: _cprequest.Hook, _cprequest.HookMap, and cherrypy.tools.is The no-arg callable which will handle unexpected, untrapped errors during request processing. This is not used for expected exceptions (like NotFound, HTTPError, or HTTPRedirect) which are raised in response to expected conditions (those should be customized either via request.error_page or by overriding HTTPError.set_response). By default, error_response uses HTTPError(500) to return a generic error response to the user-agent.s A dict of {error code: response filename or callable} pairs. The error code must be an int representing a given HTTP error code, or the string 'default', which will be used if no matching entry is found for a given numeric code. If a filename is provided, the file should contain a Python string- formatting template, and can expect by default to receive format values with the mapping keys %(status)s, %(message)s, %(traceback)s, and %(version)s. The set of format mappings can be extended by overriding HTTPError.set_response. If a callable is provided, it will be called by default with keyword arguments 'status', 'message', 'traceback', and 'version', as for a string-formatting template. The callable must return a string which will be set to response.body. It may also override headers or perform any other processing. If no entry is given for an error code, and no 'default' entry exists, a default template will be used. sx If True, unexpected errors encountered during request processing will include a traceback in the response body.s;The sequence of exceptions which Request.run does not trap.s If True, Request.run will not trap any errors (except HTTPRedirect and HTTPError, which are more properly called 'exceptions', not errors).sA True once the close method has been called, False otherwise.s A string containing the stage reached in the request-handling process. This is useful when debugging a live server with hung requests.R=RJRORSttoolscCs^||_||_||_||_t|_|jj|_|jj|_d|_ dS(sPopulate a new Request object. local_host should be an http.Host object with the server info. remote_host should be an http.Host object with the client info. scheme should be a string, either "http" or "https". N( tlocaltremotetschemetserver_protocolR tclosedRSRCt namespacesR tstage(Rt local_hostt remote_hostRfRg((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyRs     cCs;|js7t|_d|_|jjdd|_ndS(sRun cleanup code. (Core)RZtcloseN(RhR;RjR=R?(R((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyRms    cCs)d|_yFtjdj|_||_|p3d}|p?d|_t|dt|df}t|jdt|jdf}t |||_ |} |r| d|7} nd|| |f|_ t ||_ ||_tj|_tj|_d|_|jj|_|t|j|_} d |_|j| Wn|jk rhnt|jrzqtjd td d |j rt!} nd} t"| } tj#} | \| _$| _ | _%nX|jd krgtj#_%ntjj&tj#j'r"tj(ntj#S(sProcess the Request. (Core) method, path, query_string, and req_protocol should be pulled directly from the Request-Line (e.g. "GET /path?key=val HTTP/1.0"). path should be %XX-unquoted, but query_string should not be. headers should be a list of (name, value) tuples. rfile should be a file-like object containing the HTTP request entity. When run() is done, the returned object should have 3 attributes: status, e.g. "200 OK" header_list, a list of (name, value) tuples body, an iterable yielding strings Consumer code (HTTP servers) should then access these response attributes to build the outbound stream. R?iRbR^iit?s%s %s %strespondR0R1i(tHEADN()RjRR5t set_responseterror_responsetmethodt query_stringRRRgtmintprotocolt request_linetlistt header_listtrfileRt HeaderMaptheaderstCookiet SimpleCookietcookieR thandlertappt script_nametlent path_infoRotthrowst throw_errorsR:R;tshow_tracebacksRRROtstatustbodytaccesst timed_outt TimeoutError(RRstpathRtt req_protocolR|RztrptspturltpiRtrRO((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyR?sP    &          cCsyzyQ|jd kr'tjnd|_|j|jjj|_i|_ d|_|j ||j |j d|_|jj d|jr|j|jkrt|_qnd|_|jj d|jr|jnd|_|jj d|jr0d|_|jtj_nd|_|jj dtjjWnOtjtjfk r}|jd|_|jj dtjjnXWd d |_|jj d XWn6|jk rn |jrn|jnXd S( s>Generate a response for the resource at self.path_info. (Core)tprocess_headerst get_resourceRURVRWRRXsbefore_finalize (HTTPError)NRY(RR RtNotFoundRjRRR=RCttoolmapsRRitconfigR?tprocess_request_bodyRstmethods_with_bodiesR t process_bodyRRORtfinalizeR6R5RqRRt handle_error(RRtinst((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyRo;sT                  cCs}tj|j|_|j}x|jD]\}}|j}|j}d|krwtj ||tj |ntj ||||dkr(y|j j |Wqt jk rd|jdd}tjd|qXq(q(Wtj|ds0|jd kr0d }tjd|q0ntj|d}|sc|jjp]|jj}nd |j|f|_d S( s5Parse HTTP header data into Python structures. (Core)s=?R}sIllegal cookie name %st=iitHostis*HTTP/1.1 requires a 'Host' request header.s%s://%sN(ii(Rtparse_query_stringRttparamsR|RyttitletstripR&t __setitem__t decode_TEXTRtloadR}t CookieErrorRERR5t __contains__RvtgetRdtnametipRftbase(RR|Rtvaluetmsgthost((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyRrs,     cCs|j}|pd}x|r|jjj|i}|jd}|rU|}Pn|jd}|dkrtPq|dkr|dkrd}q|| }qW||dS(s?Call a dispatcher (which sets self.handler and .config). (Core)Rbsrequest.dispatchiiN(tdispatchRRRtrfind(RRRttrailtnodeconfR)t lastslash((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyRs     c Cs|jjdds'tjdnd|jkr[tj|jj}d|d self.time + self.timeout, set self.timed_out. This purposefully sets a flag, rather than raising an error, so that a monitor thread can interrupt the Response thread. N(RttimeoutR;R(R((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyt check_timeout{sN(#RRRRRR Rt status__docRyRRR{R|RR}R~RRRRRR Rt time__docR t timeout__docR Rttimed_out__docRt stream__docRRRR(((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyRs0       &(R}tosR8RRRRRtcherrypy._cperrorRRt cherrypy.libRRtobjectRR&R%RLRNRPRTRR]RR(((s9/usr/lib/python2.7/vendor-packages/cherrypy/_cprequest.pyts.      79    U