î i f˜Pã @spdZddlmZmZmZddlmZddlZddlZddl Z dddd d d gZ d d dddddgZ dddddddddddddg Z dd „Z d!d"d#d$d%d&d'd(d)d*h jZd+d,„Zd-d „ZGd.d„dƒZGd/d„deƒZGd0d„deƒZGd1d „d eƒZGd2d „d eƒZdS)3z/Base classes for server/gateway implementationsé)Ú FileWrapperÚ guess_schemeÚ is_hop_by_hop)ÚHeaderséNÚ BaseHandlerÚ SimpleHandlerÚBaseCGIHandlerÚ CGIHandlerÚ IISCGIHandlerÚ read_environZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc CsOtj|ƒ\ }}}}}}}}} dt||t|||||fS)Nz#%s, %02d %3s %4d %02d:%02d:%02d GMT)ÚtimeZgmtimeÚ _weekdaynameÚ _monthname) Z timestampZyearZmonthZdayZhhZmmZssZwdÚyÚz©rú5/opt/alt/python34/lib64/python3.4/wsgiref/handlers.pyÚformat_date_times*rÚ SCRIPT_NAMEÚ PATH_INFOZ QUERY_STRINGZREQUEST_METHODZ AUTH_TYPEZ CONTENT_TYPEZCONTENT_LENGTHZHTTPSZ REMOTE_USERZ REMOTE_IDENTcCsMt|ƒpL|jdƒpL|jdƒpL|jdƒoLt|dd…ƒS)NZHTTP_ZSSL_Z REDIRECT_é )Ú _is_requestÚ startswithÚ_needs_transcode)Úkrrrrs*rc CsYtjƒ}d}ydjd|ƒWntk r@d}YnXi}x tjjƒD]ú\}}t|ƒrGtjdkr)tjj ddƒj ƒ}|j dƒrÃ|jdƒj dƒ}qD|j d ƒrÕqD|j d ƒr d |kr |jdƒj dƒ}qD|j|dƒj dƒ}qG|j||ƒj dƒ}n|||rz+Manage the invocation of a WSGI applicationrrTFz1.0Nz500 Internal Server Errorú Content-Typeú text/plains;A server error occurred. Please contact the administrator.cCsey0|jƒ||j|jƒ|_|jƒWn.y|jƒWn|jƒ‚YnXYnXdS)zInvoke the applicationN)Ú setup_environr&Ústart_responseÚresultÚfinish_responseÚ handle_errorÚclose)ÚselfZ applicationrrrÚrun€s  zBaseHandler.runcCsÏ|jjƒ}|_|jƒ|jƒ|d<|jƒ|d<|j|d<|j|d<|jƒ|d<|j |d<|j |d<|j dk r£|j |d Send any iterable data, then close self and the iterable Subclasses intended for use in asynchronous servers will want to redefine this method, such that it sets up callbacks in the event loop to iterate over the data, and to call 'self.close()' once the response is finished. N)Úresult_is_fileÚsendfiler3ÚwriteÚfinish_contentr6)r7Údatarrrr4©s zBaseHandler.finish_responsecCs t|jƒS)z Return the URL scheme being used)rr&)r7rrrr@ºszBaseHandler.get_schemec Cs[yt|jƒ}Wntttfk r0Yn'X|dkrWt|jƒ|jdLog current error, and send error output to client if possibleN) rtr!r]rWÚ error_outputr&r2r3r4)r7rrrr5ks zBaseHandler.handle_errorcCs0||j|jdd…tjƒƒ|jgS)aZWSGI mini-app to create error output By default, this just uses the 'error_status', 'error_headers', and 'error_body' attributes to generate an output page. It can be overridden in a subclass to dynamically generate diagnostics, choose an appropriate message for the user's preferred language, etc. Note, however, that it's not recommended from a security perspective to spit out diagnostics to any old user; ideally, you should have to do something special to enable diagnostic output, which is why we don't include any here! N)Ú error_statusÚ error_headersr!r]Ú error_body)r7r&r2rrrruss &zBaseHandler.error_outputcCs t‚dS)aOverride in subclass to buffer data for send to client It's okay if this method actually transmits the data; BaseHandler just separates write and flush operations for greater efficiency when the underlying system actually has such a distinction. N)rP)r7rLrrrrd†szBaseHandler._writecCs t‚dS)z¬Override in subclass to force sending of recent '_write()' calls It's okay if this method is a no-op (i.e., if '_write()' actually sends the data. N)rP)r7rrrrh�szBaseHandler._flushcCs t‚dS)z4Override in subclass to return suitable 'wsgi.input'N)rP)r7rrrr<—szBaseHandler.get_stdincCs t‚dS)z5Override in subclass to return suitable 'wsgi.errors'N)rP)r7rrrr=›szBaseHandler.get_stderrcCs t‚dS)z>Override in subclass to insert CGI variables in 'self.environ'N)rP)r7rrrr;ŸszBaseHandler.add_cgi_vars)rr)r/r0)2Ú__name__Ú __module__Ú __qualname__Ú__doc__r>rArBr?rDrerEr r9rrCrr[rqrvrwrxrZr3rWrSrRr8r1r4r@rTrUr2r\rfrJrIrKr6rgrHrcrtr5rurdrhr<r=r;rrrrr^sV                     c@sdeZdZdZdddd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dS)raqHandler that's just initialized with streams, environment, etc. This handler subclass is intended for synchronous HTTP/1.0 origin servers, and handles sending the entire response output, given the correct inputs. Usage:: handler = SimpleHandler( inp,out,err,env, multithread=False, multiprocess=True ) handler.run(app)TFcCs:||_||_||_||_||_||_dS)N)ÚstdinÚstdoutrsÚbase_envrArB)r7r}r~rsr&Ú multithreadÚ multiprocessrrrÚ__init__±s      zSimpleHandler.__init__cCs|jS)N)r})r7rrrr<»szSimpleHandler.get_stdincCs|jS)N)rs)r7rrrr=¾szSimpleHandler.get_stderrcCs|jj|jƒdS)N)r&Úupdater)r7rrrr;ÁszSimpleHandler.add_cgi_varscCs|jj|ƒdS)N)r~rJ)r7rLrrrrdÄszSimpleHandler._writecCs |jjƒ|jj|_dS)N)r~rrrh)r7rrrrhÇs zSimpleHandler._flushN) ryrzr{r|r‚r<r=r;rdrhrrrrr¤s     c@seZdZdZdZdS)r aÚCGI-like systems using input/output/error streams and environ mapping Usage:: handler = BaseCGIHandler(inp,out,err,env) handler.run(app) This handler class is useful for gateway protocols like ReadyExec and FastCGI, that have usable input/output/error streams and an environment mapping. It's also the base class for CGIHandler, which just uses sys.stdin, os.environ, and so on. The constructor also takes keyword arguments 'multithread' and 'multiprocess' (defaulting to 'True' and 'False' respectively) to control the configuration sent to the application. It sets 'origin_server' to False (to enable CGI-like output), and assumes that 'wsgi.run_once' is False. FN)ryrzr{r|rDrrrrr Ìs c@s.eZdZdZdZiZdd„ZdS)r aéCGI-based invocation via sys.stdin/stdout/stderr and os.environ Usage:: CGIHandler().run(app) The difference between this class and BaseCGIHandler is that it always uses 'wsgi.run_once' of 'True', 'wsgi.multithread' of 'False', and 'wsgi.multiprocess' of 'True'. It does not take any initialization parameters, but always uses 'sys.stdin', 'os.environ', and friends. If you need to override any of these parameters, use BaseCGIHandler instead. Tc Cs;tj|tjjtjjtjtƒddddƒdS)Nr€Fr�T)r r‚r!r}Úbufferr~rsr )r7rrrr‚ûszCGIHandler.__init__N)ryrzr{r|r?r9r‚rrrrr äs c@s.eZdZdZdZiZdd„ZdS)r aCGI-based invocation with workaround for IIS path bug This handler should be used in preference to CGIHandler when deploying on Microsoft IIS without having set the config allowPathInfo option (IIS>=7) or metabase allowPathInfoForScriptMappings (IIS<7). Tc Cs™tƒ}|jddƒ}|jddƒ}|dj|dƒra|t|ƒd…|ds($     <ÿG(