ó »ÏâIc@sdZddlZddlZddlZddlmZddlm Z de fd„ƒYZ de fd„ƒYZ d e fd „ƒYZdS( sWSGI interface (see PEP 333).iÿÿÿÿN(t_cperror(thttpt VirtualHostcBs&eZdZded„Zd„ZRS(s2Select a different WSGI application based on the Host header. This can be useful when running multiple sites within one CP server. It allows several domains to point to different applications. For example: root = Root() RootApp = cherrypy.Application(root) Domain2App = cherrypy.Application(root) SecureApp = cherrypy.Application(Secure()) vhost = cherrypy._cpwsgi.VirtualHost(RootApp, domains={'www.domain2.example': Domain2App, 'www.domain2.example:443': SecureApp, }) cherrypy.tree.graft(vhost) default: required. The default WSGI application. use_x_forwarded_host: if True (the default), any "X-Forwarded-Host" request header will be used instead of the "Host" header. This is commonly added by HTTP servers (such as Apache) when proxying. domains: a dict of {host header value: application} pairs. The incoming "Host" request header is looked up in this dict, and, if a match is found, the corresponding WSGI application will be called instead of the default. Note that you often need separate entries for "example.com" and "www.example.com". In addition, "Host" headers may contain the port number. cCs%||_|pi|_||_dS(N(tdefaulttdomainstuse_x_forwarded_host(tselfRRR((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyt__init__+s cCsg|jddƒ}|jr0|jd|ƒ}n|jj|ƒ}|dkrZ|j}n|||ƒS(Nt HTTP_HOSTttHTTP_X_FORWARDED_HOST(tgetRRtNoneR(Rtenvirontstart_responsetdomaintnextapp((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyt__call__0s   N(t__name__t __module__t__doc__R tTrueRR(((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyR st AppResponsecBs—eZeefZdZed„Zd„Z d„Z d„Z d„Z d„Z d„Zd„Zidd 6d d 6d d 6dd6dd6Zd„ZRS(cCs;g|_||_||_||_||_|jƒdS(N(t redirectionst recursiveR Rtcpapptsetapp(RR RRR((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyRDs      cCs‘yG|jƒ|_|jƒ\}}}t|ƒ|_|j||ƒWnC|jk rj|jƒ‚n#tj k r³}tj j|j d<|jƒ|j |j |jƒdSt|jdtƒrÛ|jƒ‚ntjƒ}tj|ddƒt|jdtƒsd}ntj|ƒ\}}}t|ƒ|_y|j||tjƒƒWqtjdtddƒ|jƒ‚qXnXdS(Nscherrypy.previous_requestt throw_errorstseverityi(tshow_tracebacksR t traceback(t get_requesttrequestt get_responsetitert iter_responseRtthrowstcloset _cherrypytInternalRedirecttservingR t iredirecttpatht query_stringtgetattrtFalseRt format_exctlogRt bare_errort_systexc_info(Rtsthtbtirttb((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyRLs:      cCs|j}|jsÂ|jddƒ}|}|r=d|}n||||jkrptd|||fƒ‚qÂ|jddƒ}|jddƒ}|r§d|}n|jj|||ƒnd|d<||d<||d       cCs|jjƒdS(s?Close and de-reference the current request and response. (Core)N(Rtrelease_serving(R((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyR%ÎscCsº|jd}tj|jjddƒ|jjddƒƒ}|jjddƒ}|jjdƒ}|j|jƒ}|jd}|jj||||||ƒ}|j|j|j fS(s)Run self.request and return its response.R=R8R R:R;tSERVER_PROTOCOLs wsgi.input( R t_httpturljoinR ttranslate_headersR truntstatust header_listtbody(RtmethR*RFtrprototheaderstrfiletresponse((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyR!Òs  !cCs|jj}tjdt|ddƒƒ|ddƒƒ}tj|ddƒt|ddƒƒ|ddƒƒ}|d ƒ}|d d ƒ}|jj||||ƒ\}}|d ƒpÆ|d ƒpÆd|_|jd|_ |jd|_ |j|_ |ddƒ|_ |S(s&Create a Request object using environ.R t SERVER_PORTiPt SERVER_NAMEt REMOTE_ADDRt REMOTE_PORTiÿÿÿÿt REMOTE_HOSTswsgi.url_schemetACTUAL_SERVER_PROTOCOLsHTTP/1.1t LOGON_USERt REMOTE_USERswsgi.multithreadswsgi.multiprocessscherrypy.previous_requestN( R R RRtHosttintRt get_servingR tlogint multithreadt multiprocesst wsgi_environtprev(RRDtlocaltremotetschemetsprotoR tresp((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyRÞs  !! t AuthorizationtHTTP_CGI_AUTHORIZATIONsContent-LengthR?s Content-Typet CONTENT_TYPEs Remote-HostRbs Remote-AddrR`ccsuxn|D]f}||jkr5|j|||fVq|d dkr|djddƒ}|||fVqqWdS(s8Translate CGI-environ header names to HTTP header names.itHTTP_t_t-N(t headerNamestreplace(RR tcgiNamettranslatedHeader((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyRTüs  N(RRtKeyboardInterruptt SystemExitR$R R R-RRR)RHRIR%R!RRyRT(((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyR?s    & ,  -    t CPWSGIAppcBsMeZdZgZdZiZeZdd„Z d„Z d„Z d„Z RS(snA WSGI application object for a CherryPy Application. pipeline: a list of (name, wsgiapp) pairs. Each 'wsgiapp' MUST be a constructor that takes an initial, positional 'nextapp' argument, plus optional keyword arguments, and returns a WSGI application (that takes environ and start_response arguments). The 'name' can be any you choose, and will correspond to keys in self.config. head: rather than nest all apps in the pipeline on each call, it's only done the first time, and the result is memoized into self.head. Set this to None again if you change self.pipeline after calling self. config: a dict whose keys match names listed in the pipeline. Each value is a further dict which will be passed to the corresponding named WSGI callable (from the pipeline) as keyword arguments. cCsE||_|j|_|r/|jj|ƒn|jjƒ|_dS(N(Rtpipelinetextendtconfigtcopy(RRR€((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyR s   cCs|j|||jƒS(sÚWSGI application callable for the actual CherryPy application. You probably shouldn't call this; call self.__call__ instead, so that any WSGI middleware in self.pipeline can run first. (tresponse_classR(RR R((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyttail'scCs‚|j}|dkru|j}xH|jddd…D]0\}}|jj|iƒ}|||}q5W||_n|||ƒS(Niÿÿÿÿ(theadR R…R€R‚R (RR RR†tnametcallabletconf((s6/usr/lib/python2.7/vendor-packages/cherrypy/_cpwsgi.pyR/s   # cCsr|dkr|jj|ƒnO|dkr7||_n7|jddƒ\}}|jj|iƒ}|||s   4É