o ?Og¥Tã@sÈdZddlmZmZmZddlmZddlZddlZddl Z gd¢Z gd¢Z gd¢Z d d „Z hd £jZd d „Zdd„ZGdd„dƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZdS)z/Base classes for server/gateway implementationsé)Ú FileWrapperÚ guess_schemeÚ is_hop_by_hop)ÚHeaderséN)Ú BaseHandlerÚ SimpleHandlerÚBaseCGIHandlerÚ CGIHandlerÚ IISCGIHandlerÚ read_environ)ZMonZTueZWedZThuZFriZSatZSun) NZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc Cs:t |¡\ }}}}}}}}} dt||t|||||fS)Nz#%s, %02d %3s %4d %02d:%02d:%02d GMT)ÚtimeÚgmtimeÚ _weekdaynameÚ _monthname) Z timestampZyearZmonthZdayZhhZmmZssZwdÚyÚz©rú7/opt/alt/python310/lib64/python3.10/wsgiref/handlers.pyÚformat_date_timesÿr> ZHTTPSÚ PATH_INFOZ AUTH_TYPEZREQUEST_METHODZ CONTENT_TYPEZ REMOTE_USERZ REMOTE_IDENTZ QUERY_STRINGZCONTENT_LENGTHÚ SCRIPT_NAMEcCs6t|ƒp| d¡p| d¡p| d¡ot|dd…ƒS)NZHTTP_ZSSL_Z REDIRECT_é )Ú _is_requestÚ startswithÚ_needs_transcode)ÚkrrrrsÿrcCsît ¡}d}zd d|¡Wn tyd}Ynwi}tj ¡D]S\}}t|ƒrptjdkrgtj  dd¡  ¡}|  d¡rE| d¡  d¡}n+|  d ¡rKn%|  d ¡r]d |vr]| d¡  d¡}n| |d¡  d¡}n | ||¡  d¡}|||<q!|S) z'Read environment, fixing HTTP variablesÚsurrogateescapeÚzutf-8ÚreplaceZwin32ÚSERVER_SOFTWAREzmicrosoft-iis/ú iso-8859-1zapache/z simplehttp/zpython/3) ÚsysÚgetfilesystemencodingÚencodeÚ LookupErrorÚosÚenvironÚitemsrÚplatformÚgetÚlowerrÚdecode)ÚencZescr'rÚvZsoftwarerrrr "s0 ÿ   ÿ r c@s"eZdZdZdZdZdZdZdZdZ dZ e ƒZ e ZeZdZdZdgZd ZdZZdZdZd Zd d „Zd d„Zdd„Zdd„Zdd„Zdd„Zd;dd„Z dd„Z!dd„Z"dd„Z#dd „Z$d!d"„Z%d#d$„Z&d%d&„Z'd'd(„Z(d)d*„Z)d+d,„Z*d-d.„Z+d/d0„Z,d1d2„Z-d3d4„Z.d5d6„Z/d7d8„Z0d9d:„Z1dS)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. r7N)Úresult_is_fileÚsendfiler1ÚwriteÚfinish_contentÚhasattrr7©r8Údatarrrr2­s  €   zBaseHandler.finish_responsecCs t|jƒS)z Return the URL scheme being used)rr'©r8rrrrAÇs zBaseHandler.get_schemec CsJzt|jƒ}Wn tttfyYdSw|dkr#t|jƒ|jd<dSdS)z@Compute Content-Length or switch to chunked encoding if possiblerúContent-LengthN)Úlenr1Ú TypeErrorÚAttributeErrorÚNotImplementedErrorÚstrÚ bytes_sentÚheaders)r8ZblocksrrrÚset_content_lengthÌsÿþzBaseHandler.set_content_lengthcCsd|jvr | ¡dSdS)zqMake any necessary header changes or defaults Subclasses can extend this to add other defaults. rQN)rXrYrPrrrÚcleanup_headersÙs  ÿzBaseHandler.cleanup_headerscCsð|rz|jr|d|dƒ |d¡‚Wd}n d}w|jdur#tdƒ‚||_| |¡|_| |d¡}t|ƒdkss zBaseHandler.finish_contentc Cs’z5t|jdƒr!|j ¡Wd|_|_|_|_d|_d|_dSWd|_|_|_|_d|_d|_dSd|_|_|_|_d|_d|_w)z„Close the iterable (if needed) and reset all instance vars Subclasses may want to also drop the client connection. r7NrF)rMr1r7rXrbr'rWr_rPrrrr7Hs  üÿzBaseHandler.closecCs<| ¡d|_|jr| ¡r| ¡| t|jƒ¡dSdS)z1Transmit headers to the client, via self._write()TN)rZr_rErnrqrorrrXrPrrrrsUs þzBaseHandler.send_headerscCs|j}|duo t|j|ƒS)z@True if 'self.result' is an instance of 'self.wsgi_file_wrapper'N)rDÚ isinstancer1)r8ÚwrapperrrrrI^szBaseHandler.result_is_filecCs|jd ¡dkS)z,True if client can accept status and headersZSERVER_PROTOCOLzHTTP/0.9)r'ÚupperrPrrrrndszBaseHandler.client_is_moderncCsLz"ddlm}| ¡}||d|d|d|j|ƒ| ¡Wd}dSd}w)zLog the 'exc_info' tuple in the server log Subclasses may override to retarget the output or change its format. r)Úprint_exceptionrr[N)Ú tracebackryr>Útraceback_limitÚflush)r8rfryÚstderrrrrÚ log_exceptionis þ zBaseHandler.log_exceptioncCs6| t ¡¡|js| |j|j¡|_| ¡dSdS)z>Log current error, and send error output to client if possibleN) r~r"rfr_Ú error_outputr'r0r1r2rPrrrr6ys  þzBaseHandler.handle_errorcCs$||j|jdd…t ¡ƒ|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"rfÚ error_body)r8r'r0rrrrs zBaseHandler.error_outputcCót‚)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. ©rUrNrrrro”szBaseHandler._writecCrƒ)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. r„rPrrrrtszBaseHandler._flushcCrƒ)z4Override in subclass to return suitable 'wsgi.input'r„rPrrrr=¥ózBaseHandler.get_stdincCrƒ)z5Override in subclass to return suitable 'wsgi.errors'r„rPrrrr>©r…zBaseHandler.get_stderrcCrƒ)z>Override in subclass to insert CGI variables in 'self.environ'r„rPrrrr<­r…zBaseHandler.add_cgi_vars©N)2Ú__name__Ú __module__Ú __qualname__Ú__doc__r?rBrCr@rErprFr r:rrDrrcr{r€rr‚rbr1r_rXrWr9r/r2rArYrZr0rdrqrKrJrLr7rsrIrnr~r6rrortr=r>r<rrrrr^sX      rc@sDeZdZdZ ddd„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(||_||_||_||_||_||_dSr†)ÚstdinÚstdoutr}Úbase_envrBrC)r8r‹rŒr}r'Ú multithreadÚ multiprocessrrrÚ__init__¿s  zSimpleHandler.__init__cCó|jSr†)r‹rPrrrr=ÉózSimpleHandler.get_stdincCr‘r†)r}rPrrrr>Ìr’zSimpleHandler.get_stderrcCs|j |j¡dSr†)r'ÚupdaterrPrrrr<ÏszSimpleHandler.add_cgi_varscCs^|j |¡}|dus|t|ƒkrdSddlm}|dtƒ ||d…}|s(dS|j |¡}q)Nr)Úwarnz9SimpleHandler.stdout.write() should not do partial writes)rŒrKrRÚwarningsr”ÚDeprecationWarning)r8rOr1r”rrrroÒs  ÿ  üzSimpleHandler._writecCs|j ¡|jj|_dSr†)rŒr|rtrPrrrrtßs zSimpleHandler._flushN)TF) r‡rˆr‰rŠrr=r>r<rortrrrrr²s ÿ  rc@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)r‡rˆr‰rŠrErrrrr äsr c@ó 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ƒddddS)NFT©rŽr)r rr"r‹ÚbufferrŒr}r rPrrrrs þzCGIHandler.__init__N©r‡rˆr‰rŠr@r:rrrrrr üs  r c@r—)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 Csjtƒ}| dd¡}| dd¡}|d |d¡r"|t|ƒd…|d<tj|tjjtj jtj |ddddS)Nrrrú/FTr˜) r r*rrRr rr"r‹r™rŒr})r8r'ÚpathZscriptrrrr2s   þzIISCGIHandler.__init__Nršrrrrr s  r )rŠÚutilrrrrXrr"r&r Ú__all__rrrÚ __contains__rrr rrr r r rrrrÚs( ý<V2