3 Õì2a Rã @süddlmZmZmZddlmZddlZddlZddlZddddd d gZ d d d ddddgZ dddddddddddddg Z dd„Z d d!d"d#d$d%d&d'd(d)h j Zd*d+„Zd,d „ZGd-d„dƒZGd.d„deƒZGd/d„deƒZGd0d„deƒZGd1d „d eƒZdS)2é)Ú FileWrapperÚ guess_schemeÚ is_hop_by_hop)ÚHeaderséNÚ BaseHandlerÚ SimpleHandlerÚBaseCGIHandlerÚ CGIHandlerÚ IISCGIHandlerÚ read_environZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc Cs:tj|ƒ\ }}}}}}}}} dt||t|||||fS)Nz#%s, %02d %3s %4d %02d:%02d:%02d GMT)ÚtimeZgmtimeÚ _weekdaynameÚ _monthname) Z timestampZyearZmonthZdayZhhZmmÚssZwdÚyÚz©rú-/opt/alt/python36/lib64/python3.6/handlers.pyÚformat_date_timesrÚ SCRIPT_NAMEÚ PATH_INFOZ QUERY_STRINGZREQUEST_METHODZ AUTH_TYPEZ CONTENT_TYPEZCONTENT_LENGTHZHTTPSZ REMOTE_USERZ REMOTE_IDENTcCs6t|ƒp4|jdƒp4|jdƒp4|jdƒo4t|dd…ƒS)NZHTTP_ZSSL_Z REDIRECT_é )Ú _is_requestÚ startswithÚ_needs_transcode)Úkrrrrsrc Csôtjƒ}d}ydjd|ƒWntk r4d}YnXi}x´tjjƒD]¦\}}t|ƒrätjdkrÒtjj ddƒj ƒ}|j dƒrŽ|jdƒj dƒ}qä|j d ƒršqä|j d ƒr¾d |kr¾|jdƒj dƒ}qä|j|dƒj dƒ}n|j||ƒj dƒ}|||<qFW|S) NÚsurrogateescapeÚzutf-8ÚreplaceÚwin32ÚSERVER_SOFTWAREzmicrosoft-iis/z iso-8859-1zapache/z simplehttp/zpython/3) ÚsysÚgetfilesystemencodingÚencodeÚ LookupErrorÚosÚenvironÚitemsrÚplatformÚgetÚlowerrÚdecode)ÚencÚescr'rÚvZsoftwarerrrr "s,      c@seZdZd;ZdZdZdZdZdZdZ e ƒZ e Z eZdZdZdrrrTFz1.0Nz500 Internal Server Errorú Content-Typeú text/plains;A server error occurred. Please contact the administrator.cCsZy$|jƒ||j|jƒ|_|jƒWn0y |jƒWn|jƒ‚YnXYnXdS)N)Ú 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 rx|j |d<|j r’|j r’|jd |j ƒdS) Nz wsgi.inputz wsgi.errorsz wsgi.versionz wsgi.run_oncezwsgi.url_schemezwsgi.multithreadzwsgi.multiprocesszwsgi.file_wrapperr!)Ú os_environÚcopyr'Ú add_cgi_varsÚ get_stdinÚ get_stderrÚ wsgi_versionÚ wsgi_run_onceÚ get_schemeÚwsgi_multithreadÚwsgi_multiprocessÚwsgi_file_wrapperÚ origin_serverÚserver_softwareÚ setdefault)r8Úenvrrrr2”s          zBaseHandler.setup_environc CsJz:|jƒ s|jƒ r8x|jD]}|j|ƒqW|jƒWd|jƒXdS)N)Úresult_is_fileÚsendfiler4ÚwriteÚfinish_contentr7)r8Údatarrrr5©s   zBaseHandler.finish_responsecCs t|jƒS)N)rr')r8rrrrAºszBaseHandler.get_schemec CsJyt|jƒ}Wntttfk r(YnX|dkrFt|jƒ|jd<dSdS)NrzContent-Length)Úlenr4Ú TypeErrorÚAttributeErrorÚNotImplementedErrorÚstrÚ bytes_sentÚheaders)r8ZblocksrrrÚset_content_length¿szBaseHandler.set_content_lengthcCsd|jkr|jƒdS)NzContent-Length)rTrU)r8rrrÚcleanup_headersÌs zBaseHandler.cleanup_headersc Csh|r2z$|jr&|d|dƒj|dƒ‚Wdd}Xn|jdk rDtdƒ‚||_|j|ƒ|_|j|dƒ}|jS)NrrézHeaders already set!ZStatus)Ú headers_sentÚwith_tracebackrTÚAssertionErrorÚstatusÚ headers_classÚ_convert_string_typerK)r8r[rTÚexc_inforrrr3Ôs   zBaseHandler.start_responsecCs(t|ƒtkr|Stdj|t|ƒƒƒ‚dS)Nz!{0} must be of type str (got {1}))ÚtyperRrZÚformatÚrepr)r8ÚvalueÚtitlerrrr]ðs z BaseHandler._convert_string_typecCs’|jrx|jƒrŽ|jd|j|jfjdƒƒd|jkrP|jdttjƒƒjdƒƒ|j rŽd|jkrŽ|jd|j jdƒƒn|jd|jjdƒƒdS)Nz HTTP/%s %s z iso-8859-1ZDatez Date: %s ZServerz Server: %s z Status: %s ) rEÚclient_is_modernÚ_writeÚ http_versionr[r$rTrr rF)r8rrrÚ send_preambleøs zBaseHandler.send_preamblecCsR|jstdƒ‚n,|js*t|ƒ|_|jƒn|jt|ƒ7_|j|ƒ|jƒdS)Nzwrite() before start_response())r[rZrXrNrSÚ send_headersreÚ_flush)r8rMrrrrKs    zBaseHandler.writecCsdS)NFr)r8rrrrJszBaseHandler.sendfilecCs"|js|jjddƒ|jƒndS)NzContent-LengthÚ0)rXrTrGrh)r8rrrrL0s zBaseHandler.finish_contentc CsFzt|jdƒr|jjƒWdd|_|_|_|_d|_d|_XdS)Nr7rF)Úhasattrr4r7rTr[r'rSrX)r8rrrr7:s  zBaseHandler.closecCs:|jƒd|_|j s|jƒr6|jƒ|jt|jƒƒdS)NT)rVrXrErdrgreÚbytesrT)r8rrrrhGs zBaseHandler.send_headerscCs|j}|dk ot|j|ƒS)N)rDÚ isinstancer4)r8ÚwrapperrrrrIPszBaseHandler.result_is_filecCs|jdjƒdkS)NZSERVER_PROTOCOLzHTTP/0.9)r'Úupper)r8rrrrdVszBaseHandler.client_is_modernc CsJz>ddlm}|jƒ}||d|d|d|j|ƒ|jƒWdd}XdS)Nr)Úprint_exceptionrrW)Ú tracebackrpr>Útraceback_limitÚflush)r8r^rpÚstderrrrrÚ log_exception[s   zBaseHandler.log_exceptioncCs2|jtjƒƒ|js.|j|j|jƒ|_|jƒdS)N) rur"r^rXÚ error_outputr'r3r4r5)r8rrrr6kszBaseHandler.handle_errorcCs$||j|jdd…tjƒƒ|jgS)N)Ú error_statusÚ error_headersr"r^Ú error_body)r8r'r3rrrrvss zBaseHandler.error_outputcCst‚dS)N)rQ)r8rMrrrre†szBaseHandler._writecCst‚dS)N)rQ)r8rrrri�szBaseHandler._flushcCst‚dS)N)rQ)r8rrrr=—szBaseHandler.get_stdincCst‚dS)N)rQ)r8rrrr>›szBaseHandler.get_stderrcCst‚dS)N)rQ)r8rrrr<ŸszBaseHandler.add_cgi_vars)rr)r0r1)N)1Ú__name__Ú __module__Ú __qualname__r?rBrCr@rErfrFr r:rrDrr\rrrwrxryr[r4rXrTrSr9r2r5rArUrVr3r]rgrKrJrLr7rhrIrdrur6rvrerir=r>r<rrrrr^sT      c@s>eZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„ZdS)rTFcCs(||_||_||_||_||_||_dS)N)ÚstdinÚstdoutrtÚbase_envrBrC)r8r}r~rtr'Ú multithreadÚ multiprocessrrrÚ__init__±s zSimpleHandler.__init__cCs|jS)N)r})r8rrrr=»szSimpleHandler.get_stdincCs|jS)N)rt)r8rrrr>¾szSimpleHandler.get_stderrcCs|jj|jƒdS)N)r'Úupdater)r8rrrr<ÁszSimpleHandler.add_cgi_varscCsb|jj|ƒ}|dks |t|ƒkr$dSddlm}|dtƒx"||d…}|sNP|jj|ƒ}qr<rerirrrrr¤s   c@seZdZdZdS)r FN)rzr{r|rErrrrr Ösc@seZdZdZiZdd„ZdS)r Tc Cs(tj|tjjtjjtjtƒddd�dS)NFT)r€r�)r r‚r"r}Úbufferr~rtr )r8rrrr‚szCGIHandler.__init__N)rzr{r|r@r:r‚rrrrr îsc@seZdZdZiZdd„ZdS)r Tc Csjtƒ}|jddƒ}|jddƒ}|dj|dƒrD|t|ƒd…|d<tj|tjjtj jtj |ddd�dS)Nrrrú/FT)r€r�) r r*rrNr r‚r"r}r‡r~rt)r8r'ÚpathZscriptrrrr‚$s  zIISCGIHandler.__init__N)rzr{r|r@r:r‚rrrrr s)ÚutilrrrrTrr"r&r Ú__all__rrrÚ __contains__rrr rrr r r rrrrÚs(   <H2