ó »ÏâIc@sédZdZddlmZdefd„ƒYZddlmZm Z m Z ddlm Z m Z m Z ddlmZdd lmZejZejZdd lmZdd lmZdd lmZejƒZdd lmZddlmZddlm Z y5ddl!m"Z"e"j#ƒZ$e"j%e$ƒe$_&["Wne'k rYe j(Z$nXde j)j*fd„ƒYZ+e+e$ƒe$_,e$j,j-ƒe j)j.e$ƒe$_/e$j/j-ƒe j)j0e$ƒe$_1e$j1j-ƒe j)j2e$ƒe$_3ddlm4Z4e4j5ƒZ6e6j-ƒd!dd!d„Z8yddl9m:Z;Wn!e'k rZddl<m:Z;nXde;fd„ƒYZ=e=ƒZ>de?fd„ƒYZ@e@dƒZAe@dƒZBde;fd„ƒYZCeCƒZDdd „ZEy%dd!lFZGeGjHeG_IeEeG_HWne'k r nXdd"lmJZJd#eJjKfd$„ƒYZLeLƒZMeNeM_OdeM_PdeM_Qd%„ZRe$j-d&eRƒd!d!d'„ZSddd!d!d!d(„ZTdd)lmUZUeUjVƒZWZXdd*lmYZYeYjZƒZ[e$j-d+e[ƒd!S(,s”CherryPy is a pythonic, object-oriented HTTP framework. CherryPy consists of not one, but four separate API layers. The APPLICATION LAYER is the simplest. CherryPy applications are written as a tree of classes and methods, where each branch in the tree corresponds to a branch in the URL path. Each method is a 'page handler', which receives GET and POST params as keyword arguments, and returns or yields the (HTML) body of the response. The special method name 'index' is used for paths that end in a slash, and the special method name 'default' is used to handle multiple paths via a single handler. This layer also includes: * the 'exposed' attribute (and cherrypy.expose) * cherrypy.quickstart() * _cp_config attributes * cherrypy.tools (including cherrypy.session) * cherrypy.url() The ENVIRONMENT LAYER is used by developers at all levels. It provides information about the current request and response, plus the application and server environment, via a (default) set of top-level objects: * cherrypy.request * cherrypy.response * cherrypy.engine * cherrypy.server * cherrypy.tree * cherrypy.config * cherrypy.thread_data * cherrypy.log * cherrypy.HTTPError, NotFound, and HTTPRedirect * cherrypy.lib The EXTENSION LAYER allows advanced users to construct and share their own plugins. It consists of: * Hook API * Tool API * Toolbox API * Dispatch API * Config Namespace API Finally, there is the CORE LAYER, which uses the core API's to construct the default components which are available at higher layers. You can think of the default components as the 'reference implementation' for CherryPy. Megaframeworks (and advanced users) may replace the default components with customized or extended components. The core API's are: * Application API * Engine API * Request API * Server API * WSGI API These API's are described in the CherryPy specification: http://www.cherrypy.org/wiki/CherryPySpec s3.1.2iÿÿÿÿ(turljoint_AttributeDocstringscBseZdZd„ZRS(s8Metaclass for declaring docstrings for class attributes.c Cs |jp dg}|jƒ}|jƒxÉ|D]Á}|jdƒr/t||ƒrct||ƒndjg||jdƒD]}d|jƒ^q}ƒ}|d }yt ||ƒ} Wnt k rÒd} nX|j d|| |fƒq/q/Wdj|ƒ|_d S( sb Metaclass for declaring docstrings for class attributes. Base Python doesn't provide any syntax for setting docstrings on 'data attributes' (non-callables). This metaclass allows class definitions to follow the declaration of a data attribute with a docstring for that attribute; the attribute docstring will be popped from the class dict and folded into the class docstring. The naming convention for attribute docstrings is: + "__doc". For example: class Thing(object): """A thing and its properties.""" __metaclass__ = cherrypy._AttributeDocstrings height = 50 height__doc = """The height of the Thing in inches.""" In which case, help(Thing) starts like this: >>> help(mod.Thing) Help on class Thing in module pkg.mod: class Thing(__builtin__.object) | A thing and its properties. | | height [= 50]: | The height of the Thing in inches. | The benefits of this approach over hand-edited class docstrings: 1. Places the docstring nearer to the attribute declaration. 2. Makes attribute docs more uniform ("name (default): doc"). 3. Reduces mismatches of attribute _names_ between the declaration and the documentation. 4. Reduces mismatches of attribute default _values_ between the declaration and the documentation. The benefits of a metaclass approach over other approaches: 1. Simpler ("less magic") than interface-based solutions. 2. __metaclass__ can be specified at the module global level for classic classes. For various formatting reasons, you should write multiline docs with a leading newline and not a trailing one: response__doc = """ The response object for the current thread. In the main thread, and any threads which are not HTTP requests, this is None.""" The type of the attribute is intentionally not included, because that's not How Python Works. Quack. tt__docs s iûÿÿÿtmissings %s [= %r]: %ss N( t__doc__tkeystsorttendswiththasattrtdelattrtjointsplittstriptgetattrtAttributeErrortappend( tclstnametbasestdcttnewdoctdctnamestlinetvaltattrnametattrval((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyt__init__Fs 9    0   !(t__name__t __module__RR(((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyRAs(t HTTPErrort HTTPRedirecttInternalRedirect(tNotFoundtCherryPyExceptiont TimeoutError(t _cpdispatch(t_cptools(t _cprequest(thttp(t_cptree(t Application(t_cpwsgi(tprocess(twin32t_TimeoutMonitorcBs,eZd„Zd„Zd„Zd„ZRS(cCs)g|_tjjj|||jƒdS(N(tservingsR+tpluginstMonitorRtrun(tselftbus((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyRºs cCs |jjtjtjfƒdS(N(R.Rtservingtrequesttresponse(R2((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pytacquire¾scCs8y |jjtjtjfƒWntk r3nXdS(N(R.tremoveR4R5R6t ValueError(R2((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pytreleaseÁs  cCs(x!|jD]\}}|jƒq WdS(s*Check timeout on all responses. (Internal)N(R.t check_timeout(R2treqtresp((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyR1Çs(RRRR7R:R1(((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyR-¸s   (t _cpserverRcCsŽ|rtj|ƒn|dk r8tj|||ƒnttdƒrWtjjƒnttdƒrvtj jƒntj ƒtj ƒdS(szMount the given root, start the builtin server (and engine), then block. root: an instance of a "controller class" (a collection of page handler methods) which represents the root of the application. script_name: a string containing the "mount point" of the application. This should start with a slash, and be the path portion of the URL at which to mount the given root. For example, if root.index() will handle requests to "http://www.example.com:8080/dept/app1/", then the script_name argument would be "/dept/app1". It MUST NOT end in a slash. If the script_name refers to the root of the URI, it MUST be an empty string (not "/"). config: a file or dict containing application config. If this contains a [global] section, those entries will be used in the global (site-wide) config. tsignal_handlertconsole_control_handlerN( t_global_conf_aliastupdatetNonettreetmountR tengineR?t subscribeR@tstarttblock(troott script_nametconfig((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyt quickstartÜs  (tlocalt_ServingcBsheZdZeZejejddƒejddƒƒZ dZ ej ƒZ dZ d„Zd„ZRS(sÆAn interface for registering request and response objects. Rather than have a separate "thread local" object for the request and the response, this class works as a single threadlocal container for both objects (and any others which developers wish to define). In this way, we can easily dump those objects when we stop/start a new HTTP conversation, yet still refer to them as module-level globals in a thread-safe way. s 127.0.0.1iPiWsŒ The request object for the current thread. In the main thread, and any threads which are not receiving HTTP requests, this is None.s The response object for the current thread. In the main thread, and any threads which are not receiving HTTP requests, this is None.cCs||_||_dS(N(R5R6(R2R5R6((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pytloads cCs|jjƒdS(sRemove all attributes of self.N(t__dict__tclear(R2((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyRRs(RRRRt __metaclass__R&tRequestt_httptHostR5t request__doctResponseR6t response__docRPRR(((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyROs   t_ThreadLocalProxycBsƒeZddgZd„Zd„Zd„Zd„Zd„ZeeƒZ d„Z d„Z d „Z d „Z d „Zd „ZRS( t __attrname__RQcCs ||_dS(N(R[(R2R((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyR(scCstt|jƒ}t||ƒS(N(RR4R[(R2Rtchild((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyt __getattr__+scCsH|dkr"tj|||ƒn"tt|jƒ}t|||ƒdS(NR[(s __attrname__(tobjectt __setattr__RR4R[tsetattr(R2RtvalueR\((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyR_/s cCs#tt|jƒ}t||ƒdS(N(RR4R[R (R2RR\((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyt __delattr__6scCs8tt|jƒ}|jjjƒ}|j|jƒ|S(N(RR4R[t __class__RQtcopyRB(R2R\td((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyt _get_dict:scCstt|jƒ}||S(N(RR4R[(R2tkeyR\((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyt __getitem__AscCs tt|jƒ}|||tServerRRCRMt threadingRNt_localtcherrypy._cpthreadinglocalROR4R^RZR5R6Rrt thread_dataRxtpydocRttresolveRuRyR‚RzR|RŠtscreent error_filet access_fileR‡R™R¥R°tConfigRLRAR±tCheckertchecker(((s7/usr/lib/python2.7/vendor-packages/cherrypy/__init__.pyt:sˆ[              9             (j