�`^c
@sGdZddlmZddlmZmZmZddlmZddl Z ddl
Z
ddlZdddd gZye
Wnek
r�d
�Z
nXddd
ddddgZeddddddddddddg
Zd�Zdfd��YZdefd ��YZdefd!��YZd efd"��YZdS(#s/Base classes for server/gateway implementationsi�(t
StringType(tFileWrappertguess_schemet
is_hop_by_hop(tHeadersNtBaseHandlert
SimpleHandlertBaseCGIHandlert
CGIHandlercCs+i}x|D]\}}|||<q
W|S(N((titemstdtktv((s&/sys/lib/python2.7/wsgiref/handlers.pytdictstMontTuetWedtThutFritSattSuntJantFebtMartAprtMaytJuntJultAugtSeptOcttNovtDecc
CsOtj|�\ }}}}}}}}} dt||t|||||fS(Ns#%s, %02d %3s %4d %02d:%02d:%02d GMT(ttimetgmtimet_weekdaynamet
_monthname(
t timestamptyeartmonthtdaythhtmmtsstwdtytz((s&/sys/lib/python2.7/wsgiref/handlers.pytformat_date_time#s*cBsbeZdZdZeZeZeZeZ dZ
d Ze
ejj��ZeZeZd ZdZd!gZdZd ZZeZd ZdZd�Zd �Z d
�Z!d�Z"d�Z#d
�Z$d d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/d�Z0d�Z1d�Z2d�Z3d�Z4d�Z5RS("s+Manage the invocation of a WSGI applicationiis1.0s500 Internal Server ErrorsContent-Types
text/plains;A server error occurred. Please contact the administrator.cCscy0|j�||j|j�|_|j�Wn,y|j�Wq_|j��q_XnXdS(sInvoke the applicationN(t
setup_environtenvirontstart_responsetresulttfinish_responsethandle_errortclose(tselftapplication((s&/sys/lib/python2.7/wsgiref/handlers.pytrunLs
cCs�|jj�}|_|j�|j�|d<|j�|d<|j|d<|j|d<|j�|d<|j |d<|j
|d<|jd
k r�|j|d<n|j
r�|jr�|jd |j�nd
S(s&Set up the environment for one requests
wsgi.inputswsgi.errorsswsgi.versions
wsgi.run_onceswsgi.url_schemeswsgi.multithreadswsgi.multiprocessswsgi.file_wrappertSERVER_SOFTWAREN(t
os_environtcopyR1tadd_cgi_varst get_stdint
get_stderrtwsgi_versiont
wsgi_run_oncet
get_schemetwsgi_multithreadtwsgi_multiprocesstwsgi_file_wrappertNonet
origin_servertserver_softwaret
setdefault(R7tenv((s&/sys/lib/python2.7/wsgiref/handlers.pyR0`s
cCs^zL|j�s|j�rKx|jD]}|j|�q'W|j�nWd|j�XdS(s>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(tresult_is_filetsendfileR3twritetfinish_contentR6(R7tdata((s&/sys/lib/python2.7/wsgiref/handlers.pyR4uscCs
t|j�S(s Return the URL scheme being used(RR1(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyRB�scCsZyt|j�}Wntttfk
r/n'X|dkrVt|j�|jd<dSdS(s@Compute Content-Length or switch to chunked encoding if possibleisContent-LengthN(tlenR3t TypeErrortAttributeErrortNotImplementedErrortstrt
bytes_senttheaders(R7tblocks((s&/sys/lib/python2.7/wsgiref/handlers.pytset_content_length�scCs d|jkr|j�ndS(sqMake any necessary header changes or defaults
Subclasses can extend this to add other defaults.
sContent-LengthN(RVRX(R7((s&/sys/lib/python2.7/wsgiref/handlers.pytcleanup_headers�scCs{|r;z(|jr-|d|d|d�nWdd}Xn|jdk rYtd��n||_|j|�|_|jS(s3'start_response()' callable as specified by PEP 333iiiNsHeaders already set!(theaders_sentRFRVtAssertionErrortstatust
headers_classRM(R7R\RVtexc_info((s&/sys/lib/python2.7/wsgiref/handlers.pyR2�s
cCs�|jr�|j�r�|jd|j|jf�d|jkra|jdttj���n|jr�d|jkr�|jd|j�q�q�n|jd|j�dS(s6Transmit version/status/date/server, via self._write()sHTTP/%s %s
tDates
Date: %s
tServersServer: %s
sStatus: %s
N( RGtclient_is_modernt_writethttp_versionR\RVR/R!RH(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyt
send_preamble�s cCsm|jstd��n:|js=t|�|_|j�n|jt|�7_|j|�|j�dS(s*'write()' callable as specified by PEP 333swrite() before start_response()N(R\R[RZRPRUtsend_headersRbt_flush(R7RO((s&/sys/lib/python2.7/wsgiref/handlers.pyRM�s
cCstS(sPlatform-specific file transmission
Override this method in subclasses to support platform-specific
file transmission. It is only called if the application's
return iterable ('self.result') is an instance of
'self.wsgi_file_wrapper'.
This method should return a true value if it was able to actually
transmit the wrapped file-like object using a platform-specific
approach. It should return a false value if normal iteration
should be used instead. An exception can be raised to indicate
that transmission was attempted, but failed.
NOTE: this method should call 'self.send_headers()' if
'self.headers_sent' is false and it is going to attempt direct
transmission of the file.
(tFalse(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyRL�scCs-|js)|jjdd�|j�ndS(s.Ensure headers and content have both been sentsContent-Lengtht0N(RZRVRIRe(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyRN�s
cCs^z&t|jd�r%|jj�nWdd|_|_|_|_d|_t|_ XdS(s�Close the iterable (if needed) and reset all instance vars
Subclasses may want to also drop the client connection.
R6Ni(
thasattrR3R6RFRVR\R1RURgRZ(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR6�s cCsP|j�t|_|js)|j�rL|j�|jt|j��ndS(s1Transmit headers to the client, via self._write()N( RYtTrueRZRGRaRdRbRTRV(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyRe s
cCs%|j}|dk o$t|j|�S(s@True if 'self.result' is an instance of 'self.wsgi_file_wrapper'N(RERFt
isinstanceR3(R7twrapper((s&/sys/lib/python2.7/wsgiref/handlers.pyRKs cCs|jdj�dkS(s,True if client can accept status and headerstSERVER_PROTOCOLsHTTP/0.9(R1tupper(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyRascCs]zOddlm}|j�}||d|d|d|j|�|j�Wdd}XdS(s�Log the 'exc_info' tuple in the server log
Subclasses may override to retarget the output or change its format.
i�(tprint_exceptioniiiN(t tracebackRoR?ttraceback_limittflushRF(R7R^Rotstderr((s&/sys/lib/python2.7/wsgiref/handlers.pyt
log_exceptions
cCsH|jtj��|jsD|j|j|j�|_|j�ndS(s>Log current error, and send error output to client if possibleN( RttsysR^RZterror_outputR1R2R3R4(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR5-s cCs'||j|jtj��|jgS(sZWSGI 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!
(terror_statust
error_headersRuR^t
error_body(R7R1R2((s&/sys/lib/python2.7/wsgiref/handlers.pyRv5s
cCs
t�dS(sOverride 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(RS(R7RO((s&/sys/lib/python2.7/wsgiref/handlers.pyRbHscCs
t�dS(s�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(RS(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyRfQscCs
t�dS(s4Override in subclass to return suitable 'wsgi.input'N(RS(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR>YscCs
t�dS(s5Override in subclass to return suitable 'wsgi.errors'N(RS(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR?]scCs
t�dS(s>Override in subclass to insert CGI variables in 'self.environ'N(RS(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR=as(iiN(sContent-Types
text/plain(6t__name__t
__module__t__doc__R@RjRCRDRgRARGRcRFRHR
tosR1R R;RRERR]RqRwRxRyR\R3RZRVRUR9R0R4RBRXRYR2RdRMRLRNR6ReRKRaRtR5RvRbRfR>R?R=(((s&/sys/lib/python2.7/wsgiref/handlers.pyR*sT
cBsJeZdZeed�Zd�Zd�Zd�Zd�Z d�Z
RS(sqHandler 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)cCs:||_||_||_||_||_||_dS(N(tstdintstdoutRstbase_envRCRD(R7R~RRsR1tmultithreadtmultiprocess((s&/sys/lib/python2.7/wsgiref/handlers.pyt__init__ss cCs|jS(N(R~(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR>}scCs|jS(N(Rs(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR?�scCs|jj|j�dS(N(R1tupdateR�(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR=�scCs#|jj|�|jj|_dS(N(RRMRb(R7RO((s&/sys/lib/python2.7/wsgiref/handlers.pyRb�scCs |jj�|jj|_dS(N(RRrRf(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyRf�s
(RzR{R|RjRgR�R>R?R=RbRf(((s&/sys/lib/python2.7/wsgiref/handlers.pyRfs cBseZdZeZRS(s�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.
(RzR{R|RgRG(((s&/sys/lib/python2.7/wsgiref/handlers.pyR�scBs#eZdZeZiZd�ZRS(s�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.
c
CsAtj|tjtjtjttjj ��dt
dt�dS(NR�R�(RR�RuR~RRsR
R}R1R RgRj(R7((s&/sys/lib/python2.7/wsgiref/handlers.pyR��s*(RzR{R|RjRAR;R�(((s&/sys/lib/python2.7/wsgiref/handlers.pyR�s(R|ttypesRtutilRRRRVRRuR}R!t__all__R
t NameErrorR#RFR$R/RRRR(((s&/sys/lib/python2.7/wsgiref/handlers.pyt<module>s&$
�)
|