o ?OgO¼ã@sîdZdZgd¢ZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddl mZdZdZGdd „d ejƒZGd d „d ejeƒZGd d „d ejƒZGdd„deƒZ dd„Z!da"dd„Z#dd„Z$Gdd„de ƒZ%dd„Z&eedddfdd„Z'e(dkrõddl)Z)ddl*Z*e) +¡Z,e,j-dd d!d"e,j-d#d$d%d&d'e,j-d(d)e  .¡d*d+e,j-d,d-de/d.d/d0e, 0¡Z1e1j2rße%Z3ne Z3Gd1d2„d2eƒZ4e'e3e4e1j5e1j6d3dSdS)4a@HTTP server classes. Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST, and CGIHTTPRequestHandler for CGI scripts. It does, however, optionally implement HTTP/1.1 persistent connections, as of version 0.3. Notes on CGIHTTPRequestHandler ------------------------------ This class implements GET and POST requests to cgi-bin scripts. If the os.fork() function is not present (e.g. on Windows), subprocess.Popen() is used as a fallback, with slightly altered semantics. In all cases, the implementation is intentionally naive -- all requests are executed synchronously. SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL -- it may execute arbitrary Python code or external programs. Note that status code 200 is sent prior to execution of a CGI script, so scripts cannot send other status codes such as 302 (redirect). XXX To do: - log requests even later (to capture byte count) - log user-agent header and other interesting goodies - send error log to separate file z0.6)Ú HTTPServerÚThreadingHTTPServerÚBaseHTTPRequestHandlerÚSimpleHTTPRequestHandlerÚCGIHTTPRequestHandleréN)Ú HTTPStatusa¹ Error response

Error response

Error code: %(code)d

Message: %(message)s.

Error code explanation: %(code)s - %(explain)s.

ztext/html;charset=utf-8c@seZdZdZdd„ZdS)récCs4tj |¡|jdd…\}}t |¡|_||_dS)z.Override server_bind to store the server name.Né)Ú socketserverÚ TCPServerÚ server_bindZserver_addressÚsocketZgetfqdnÚ server_nameÚ server_port)ÚselfÚhostÚport©rú2/opt/alt/python310/lib64/python3.10/http/server.pyr ‡s   zHTTPServer.server_bindN)Ú__name__Ú __module__Ú __qualname__Zallow_reuse_addressr rrrrrƒs rc@seZdZdZdS)rTN)rrrZdaemon_threadsrrrrrsrc @s*eZdZdZdej ¡dZdeZ e Z e Z dZdd„Zdd „Zd d „Zd d „Zd5dd„Zd6dd„Zd6dd„Zdd„Zdd„Zdd„Zd7dd„Zdd„Ze d d!„e ed"ƒed#d$ƒ¡Dƒ¡Z d%e e!d&ƒ<d'd(„Z"d)d*„Z#d6d+d,„Z$d-d.„Z%gd/¢Z&gd0¢Z'd1d2„Z(d3Z)e*j+j,Z-d4d!„e.j/ 0¡DƒZ1dS)8ra¿HTTP request handler base class. The following explanation of HTTP serves to guide you through the code as well as to expose any misunderstandings I may have about HTTP (so you don't need to read the code to figure out I'm wrong :-). HTTP (HyperText Transfer Protocol) is an extensible protocol on top of a reliable stream transport (e.g. TCP/IP). The protocol recognizes three parts to a request: 1. One line identifying the request type and path 2. An optional set of RFC-822-style headers 3. An optional data part The headers and data are separated by a blank line. The first line of the request has the form where is a (case-sensitive) keyword such as GET or POST, is a string containing path information for the request, and should be the string "HTTP/1.0" or "HTTP/1.1". is encoded using the URL encoding scheme (using %xx to signify the ASCII character with hex code xx). The specification specifies that lines are separated by CRLF but for compatibility with the widest range of clients recommends servers also handle LF. Similarly, whitespace in the request line is treated sensibly (allowing multiple spaces between components and allowing trailing whitespace). Similarly, for output, lines ought to be separated by CRLF pairs but most clients grok LF characters just fine. If the first line of the request has the form (i.e. is left out) then this is assumed to be an HTTP 0.9 request; this form has no optional headers and data part and the reply consists of just the data. The reply form of the HTTP 1.x protocol again has three parts: 1. One line giving the response code 2. An optional set of RFC-822-style headers 3. The data Again, the headers and data are separated by a blank line. The response code line has the form where is the protocol version ("HTTP/1.0" or "HTTP/1.1"), is a 3-digit response code indicating success or failure of the request, and is an optional human-readable string explaining what the response code means. This server parses the request and the headers, and then calls a function specific to the request type (). Specifically, a request SPAM will be handled by a method do_SPAM(). If no such method exists the server sends an error response to the client. If it exists, it is called with no arguments: do_SPAM() Note that the request name is case sensitive (i.e. SPAM and spam are different requests). The various request details are stored in instance variables: - client_address is the client IP address in the form (host, port); - command, path and version are the broken-down request line; - headers is an instance of email.message.Message (or a derived class) containing the header information; - rfile is a file object open for reading positioned at the start of the optional input data part; - wfile is a file object open for writing. IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING! The first thing to be written must be the response line. Then follow 0 or more header lines, then a blank line, and then the actual data (if any). The meaning of the header lines depends on the command executed by the server; in most cases, when data is returned, there should be at least one header line of the form Content-type: / where and should be registered MIME types, e.g. "text/html" or "text/plain". zPython/rz BaseHTTP/úHTTP/0.9c CsÜd|_|j|_}d|_t|jdƒ}| d¡}||_| ¡}t |ƒdkr&dSt |ƒdkrŽ|d}z*|  d ¡s8t ‚| d d ¡d }| d ¡}t |ƒd krMt ‚t |dƒt |d ƒf}Wnt t fyo| tjd|¡YdSw|dkr||jdkr|d|_|dkr‹| tjd|¡dS||_d t |ƒkršdks¦n| tjd|¡dS|dd …\}}t |ƒd krÆd|_|dkrÆ| tjd|¡dS|||_|_|j  d¡rÜd |j d ¡|_z tjj|j|jd|_Wn?tjjy }z| tjdt|ƒ¡WYd}~dSd}~wtjjy(}z| tjdt|ƒ¡WYd}~dSd}~ww|j dd¡} |  ¡dkr;d|_n|  ¡dkrK|jdkrKd|_|j dd¡} |  ¡dkrl|jdkrl|jdkrl|  ¡sldSdS) aHParse a request (internal). The request should be stored in self.raw_requestline; the results are in self.command, self.path, self.request_version and self.headers. Return True for success, False for failure; on failure, any relevant error response has already been sent back. NTz iso-8859-1z rFééÿÿÿÿzHTTP/ú/rÚ.r zBad request version (%r))rrzHTTP/1.1)r rzInvalid HTTP version (%s)zBad request syntax (%r)ZGETzBad HTTP/0.9 request type (%r)z//)Z_classz Line too longzToo many headersÚ ConnectionÚÚcloseú keep-aliveZExpectz 100-continue)!ÚcommandÚdefault_request_versionÚrequest_versionÚclose_connectionÚstrÚraw_requestlineÚrstripÚ requestlineÚsplitÚlenÚ startswithÚ ValueErrorÚintÚ IndexErrorÚ send_errorrZ BAD_REQUESTÚprotocol_versionZHTTP_VERSION_NOT_SUPPORTEDÚpathÚlstripÚhttpÚclientZ parse_headersÚrfileÚ MessageClassÚheadersZ LineTooLongZREQUEST_HEADER_FIELDS_TOO_LARGEZ HTTPExceptionÚgetÚlowerÚhandle_expect_100) rÚversionr(ÚwordsZbase_version_numberZversion_numberr!r1ÚerrZconntypeZexpectrrrÚ parse_request s®        þüþþ þ   ÿý€ý€ú    z$BaseHTTPRequestHandler.parse_requestcCs| tj¡| ¡dS)a7Decide what to do with an "Expect: 100-continue" header. If the client is expecting a 100 Continue response, we must respond with either a 100 Continue or a final response before waiting for the request body. The default is to always respond with a 100 Continue. You can behave differently (for example, reject unauthorized requests) by overriding this method. This method should either return True (possibly after sending a 100 Continue response) or send an error response and return False. T)Úsend_response_onlyrZCONTINUEÚ end_headers©rrrrr:vs z(BaseHTTPRequestHandler.handle_expect_100c CsèzW|j d¡|_t|jƒdkr!d|_d|_d|_| tj ¡WdS|js*d|_ WdS|  ¡s1WdSd|j}t ||ƒsH| tj d|j¡WdSt||ƒ}|ƒ|j ¡WdStys}z| d|¡d|_ WYd}~dSd}~ww) zÜHandle a single HTTP request. You normally don't need to override this method; see the class __doc__ string for information on how to handle specific HTTP commands such as GET and POST. iirNTZdo_zUnsupported method (%r)zRequest timed out: %r)r5Úreadliner&r*r(r#r!r/rZREQUEST_URI_TOO_LONGr$r>ÚhasattrÚNOT_IMPLEMENTEDÚgetattrÚwfileÚflushÚ TimeoutErrorÚ log_error)rZmnameÚmethodÚerrrÚhandle_one_requestˆs:   þ  €üz)BaseHTTPRequestHandler.handle_one_requestcCs*d|_| ¡|js| ¡|jr dSdS)z&Handle multiple requests if necessary.TN)r$rLrArrrÚhandle­s ÿzBaseHTTPRequestHandler.handleNcCsz |j|\}}Wn tyd\}}Ynw|dur|}|dur#|}| d||¡| ||¡| dd¡d}|dkrp|tjtjtjfvrp|j |t j |ddt j |ddd œ}|  d d ¡}| d |j ¡| d tt|ƒƒ¡| ¡|jdkrƒ|r…|j |¡dSdSdS)akSend and log an error reply. Arguments are * code: an HTTP error code 3 digits * message: a simple optional 1 line reason phrase. *( HTAB / SP / VCHAR / %x80-FF ) defaults to short entry matching the response code * explain: a detailed message defaults to the long entry matching the response code. This sends an error response (so it must be called before any output has been generated), logs the error, and finally sends a piece of HTML explaining the error to the user. )ú???rNNzcode %d, message %srréÈF©Úquote)ÚcodeÚmessageÚexplainzUTF-8Úreplacez Content-TypeúContent-LengthZHEAD)Ú responsesÚKeyErrorrIÚ send_responseÚ send_headerrZ NO_CONTENTZ RESET_CONTENTÚ NOT_MODIFIEDÚerror_message_formatÚhtmlÚescapeÚencodeÚerror_content_typer%r*r@r!rFÚwrite)rrRrSrTZshortmsgZlongmsgÚbodyZcontentrrrr/µs<  ÿ  þ  ý ÿz!BaseHTTPRequestHandler.send_errorcCs:| |¡| ||¡| d| ¡¡| d| ¡¡dS)zÁAdd the response header to the headers buffer and log the response code. Also send two standard headers with the server software version and the current date. ZServerZDateN)Ú log_requestr?rZÚversion_stringÚdate_time_string©rrRrSrrrrYês  z$BaseHTTPRequestHandler.send_responsecCsh|jdkr2|dur||jvr|j|d}nd}t|dƒs g|_|j d|j||f dd¡¡dSdS) zSend the response header only.rNrrÚ_headers_bufferz %s %d %s úlatin-1Ústrict)r#rWrCrgÚappendr0r_rfrrrr?÷s    ÿÿÿøz)BaseHTTPRequestHandler.send_response_onlycCsv|jdkrt|dƒs g|_|j d||f dd¡¡| ¡dkr7| ¡dkr,d|_d S| ¡d kr9d |_d Sd Sd S) z)Send a MIME header to the headers buffer.rrgz%s: %s rhriZ connectionrTr FN)r#rCrgrjr_r9r$)rÚkeywordÚvaluerrrrZs  ÿ     üz"BaseHTTPRequestHandler.send_headercCs&|jdkr|j d¡| ¡dSdS)z,Send the blank line ending the MIME headers.rs N)r#rgrjÚ flush_headersrArrrr@s   þz"BaseHTTPRequestHandler.end_headerscCs,t|dƒr|j d |j¡¡g|_dSdS)Nrgó)rCrFraÚjoinrgrArrrrms  þz$BaseHTTPRequestHandler.flush_headersú-cCs.t|tƒr|j}| d|jt|ƒt|ƒ¡dS)zNLog an accepted request. This is called by send_response(). z "%s" %s %sN)Ú isinstancerrlÚ log_messager(r%)rrRÚsizerrrrcs ÿz"BaseHTTPRequestHandler.log_requestcGs|j|g|¢RŽdS)zÿLog an error. This is called when a request cannot be fulfilled. By default it passes the message on to log_message(). Arguments are the same as for log_message(). XXX This should go to the separate error log. N)rr)rÚformatÚargsrrrrI)s z BaseHTTPRequestHandler.log_errorcCsi|] }|d|d›“qS)z\xZ02xr)Ú.0ÚcrrrÚ 9sz!BaseHTTPRequestHandler.é éé z\\ú\cGs2||}tj d| ¡| ¡| |j¡f¡dS)aZLog an arbitrary message. This is used by all other logging functions. Override it if you have specific logging wishes. The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it's just like printf!). The client ip and current date/time are prefixed to every message. Unicode control characters are replaced with escaped hex before writing the output to stderr. z%s - - [%s] %s N)ÚsysÚstderrraÚaddress_stringÚlog_date_time_stringÚ translateÚ_control_char_table)rrtrurSrrrrr<s þ ÿz"BaseHTTPRequestHandler.log_messagecCs|jd|jS)z*Return the server software version string.ú )Úserver_versionÚ sys_versionrArrrrdVsz%BaseHTTPRequestHandler.version_stringcCs |durt ¡}tjj|ddS)z@Return the current date and time formatted for a message header.NT)Zusegmt)ÚtimeÚemailÚutilsZ formatdate)rZ timestamprrrreZsz'BaseHTTPRequestHandler.date_time_stringc CsBt ¡}t |¡\ }}}}}}}} } d||j|||||f} | S)z.Return the current time formatted for logging.z%02d/%3s/%04d %02d:%02d:%02d)r†Ú localtimeÚ monthname) rZnowZyearZmonthZdayZhhZmmZssÚxÚyÚzÚsrrrr€`s ÿz+BaseHTTPRequestHandler.log_date_time_string)ZMonZTueZWedZThuZFriZSatZSun) NZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDeccCs |jdS)zReturn the client address.r)Úclient_addressrArrrrns z%BaseHTTPRequestHandler.address_stringúHTTP/1.0cCsi|] }||j|jf“qSr)ÚphraseÚ description)rvÚvrrrrx}s ÿÿ)NN©N)rprp)2rrrÚ__doc__r}r;r)r…Ú __version__r„ÚDEFAULT_ERROR_MESSAGEr\ÚDEFAULT_ERROR_CONTENT_TYPEr`r"r>r:rLrMr/rYr?rZr@rmrcrIr%Ú maketransÚ itertoolsÚchainÚranger‚Úordrrrdrer€Z weekdaynamerŠrr0r3r4Z HTTPMessager6rÚ __members__ÚvaluesrWrrrrr“sFgj%  5   ÿ    þrcsxeZdZdZdeZdddddœZZdd œ‡fd d „ Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Z‡ZS)raWSimple HTTP request handler with GET and HEAD commands. This serves files from the current directory and any of its subdirectories. The MIME type for files is determined by calling the .guess_type() method. The GET and HEAD requests are identical except that the HEAD request omits the actual contents of the file. z SimpleHTTP/zapplication/gzipúapplication/octet-streamzapplication/x-bzip2zapplication/x-xz)z.gzz.Zz.bz2z.xzN©Ú directorycs2|durt ¡}t |¡|_tƒj|i|¤ŽdSr”)ÚosÚgetcwdÚfspathr¢ÚsuperÚ__init__)rr¢ruÚkwargs©Ú __class__rrr§˜s z!SimpleHTTPRequestHandler.__init__cCs8| ¡}|rz| ||j¡W| ¡dS| ¡wdS)zServe a GET request.N)Ú send_headÚcopyfilerFr©rÚfrrrÚdo_GETžs üzSimpleHTTPRequestHandler.do_GETcCs| ¡}|r | ¡dSdS)zServe a HEAD request.N)r«rr­rrrÚdo_HEAD§s ÿz SimpleHTTPRequestHandler.do_HEADc CsL| |j¡}d}tj |¡rgtj |j¡}|j d¡sL| t j ¡|d|d|dd|d|df}tj  |¡}|  d|¡|  d d ¡|  ¡dSd D]}tj ||¡}tj |¡ra|}nqN| |¡S| |¡}| d¡rz| t jd ¡dSzt|d ƒ}Wnty’| t jd ¡YdSwzŠt | ¡¡}d|jvr÷d|jvr÷z tj |jd¡} Wn ttttfy½Yn:w| j durË| j!t"j#j$d} | j t"j#j$ur÷t"j" %|j&t"j#j$¡} | j!dd} | | kr÷| t j'¡|  ¡| (¡WdS| t j)¡|  d|¡|  d t*|dƒ¡|  d| +|j&¡¡|  ¡|WS| (¡‚)a{Common code for GET and HEAD commands. This sends the response code and MIME headers. Return value is either a file object (which has to be copied to the outputfile by the caller unless the command was HEAD, and must be closed by the caller under all circumstances), or None, in which case the caller has nothing further to do. Nrrrr réZLocationrVÚ0)z index.htmlz index.htmzFile not foundÚrbzIf-Modified-Sincez If-None-Match)Útzinfo)Z microsecondú Content-typeéz Last-Modified),Útranslate_pathr1r£ÚisdirÚurllibÚparseZurlsplitÚendswithrYrZMOVED_PERMANENTLYZ urlunsplitrZr@roÚisfileÚlist_directoryÚ guess_typer/Ú NOT_FOUNDÚopenÚOSErrorÚfstatÚfilenor7r‡rˆZparsedate_to_datetimeÚ TypeErrorr.Ú OverflowErrorr,r´rUÚdatetimeÚtimezoneZutcZ fromtimestampÚst_mtimer[rÚOKr%re) rr1r®ÚpartsZ new_partsZnew_urlÚindexZctypeZfsZimsZ last_modifrrrr«­s‚     ÿ    þ    þ  ÿþ  ÿ     ÿz"SimpleHTTPRequestHandler.send_headc CsÐzt |¡}Wnty| tjd¡YdSw|jdd„dg}z tjj |j dd}Wnt y>tj  |j ¡}Ynwt j |dd }t ¡}d |}| d ¡| d ¡| d |¡| d|¡| d|¡| d¡|D]9}tj  ||¡}|} } tj  |¡r|d} |d} tj  |¡r™|d} | dtjj| ddt j | dd f¡qt| d¡d |¡ |d¡} t ¡} |  | ¡|  d¡| tj¡| dd|¡| dtt| ƒƒ¡| ¡| S)zûHelper to produce a directory listing (absent index.html). Return value is either a file object, or None (indicating an error). In either case, the headers are sent, making the interface the same as for send_head(). zNo permission to list directoryNcSs| ¡Sr”)r9)ÚarrrÚsz9SimpleHTTPRequestHandler.list_directory..)ÚkeyÚ surrogatepass©ÚerrorsFrPzDirectory listing for %szZz z@z%s z

%s

z
    rú@z
  • %s
  • z

Ú Úsurrogateescaperrµztext/html; charset=%srV) r£ÚlistdirrÁr/rr¿Úsortr¹rºÚunquoter1ÚUnicodeDecodeErrorr]r^r}Úgetfilesystemencodingrjror¸ÚislinkrQr_ÚioÚBytesIOraÚseekrYrÉrZr%r*r@) rr1ÚlistÚrZ displaypathÚencÚtitleÚnameÚfullnameZ displaynameZlinknameZencodedr®rrrr½sl þü  ÿ ÿ  ÿ   ÿ þÿ    z'SimpleHTTPRequestHandler.list_directorycCsÌ| dd¡d}| dd¡d}| ¡ d¡}z tjj|dd}Wnty0tj |¡}Ynwt |¡}| d¡}t d|ƒ}|j }|D]}t j   |¡sU|t jt jfvrVqEt j  ||¡}qE|rd|d7}|S) zñTranslate a /-separated PATH to the local filename syntax. Components that mean special things to the local file system (e.g. drive or directory names) are ignored. (XXX They should probably be diagnosed.) ú?rrú#rrÏrÐN)r)r'r»r¹rºr×rØÚ posixpathÚnormpathÚfilterr¢r£r1ÚdirnameÚcurdirÚpardirro)rr1Ztrailing_slashr<Zwordrrrr·?s&  ÿ   z'SimpleHTTPRequestHandler.translate_pathcCst ||¡dS)añCopy all data between two file objects. The SOURCE argument is a file object open for reading (or anything with a read() method) and the DESTINATION argument is a file object open for writing (or anything with a write() method). The only reason for overriding this would be to change the block size or perhaps to replace newlines by CRLF -- note however that this the default server uses this to copy binary data as well. N)ÚshutilZ copyfileobj)rÚsourceZ outputfilerrrr¬]sz!SimpleHTTPRequestHandler.copyfilecCsXt |¡\}}||jvr|j|S| ¡}||jvr|j|St |¡\}}|r*|SdS)a»Guess the type of a file. Argument is a PATH (a filename). Return value is a string of the form type/subtype, usable for a MIME Content-type header. The default implementation looks the file's extension up in the table self.extensions_map, using application/octet-stream as a default; however it would be permissible (if slow) to look inside the data to make a better guess. r )ræÚsplitextÚextensions_mapr9Ú mimetypesr¾)rr1ÚbaseZextZguessÚ_rrrr¾ms    z#SimpleHTTPRequestHandler.guess_type)rrrr•r–r„rïZ_encodings_map_defaultr§r¯r°r«r½r·r¬r¾Ú __classcell__rrr©rrƒs   ü X:rc CsÎ| d¡\}}}tj |¡}| d¡}g}|dd…D]}|dkr&| ¡q|r1|dkr1| |¡q|rL| ¡}|rK|dkrE| ¡d}n |dkrKd}nd}|rWd ||f¡}dd |¡|f}d |¡}|S)aÌ Given a URL path, remove extra '/'s and '.' path elements and collapse any '..' references and returns a collapsed path. Implements something akin to RFC-2396 5.2 step 6 to parse relative paths. The utility of this function is limited to is_cgi method and helps preventing some security attacks. Returns: The reconstituted URL, which will always start with a '/'. Raises: IndexError if too many '..' occur within the path. rärNrz..rr)Ú partitionr¹rºr×r)Úpoprjro) r1ròÚqueryÚ path_partsZ head_partsÚpartZ tail_partZ splitpathÚcollapsed_pathrrrÚ_url_collapse_path‰s2     €€ rúcCsntrtSzddl}Wn tyYdSwz | d¡daWtSty6dtdd„| ¡DƒƒaYtSw) z$Internal routine to get nobody's uidrNrÚnobodyr rcss|]}|dVqdS)r Nr)rvr‹rrrÚ Çs€znobody_uid..)rûÚpwdÚ ImportErrorÚgetpwnamrXÚmaxZgetpwall)rýrrrÚ nobody_uid»s  ÿ þþrcCst |tj¡S)zTest for executable file.)r£ÚaccessÚX_OK)r1rrrÚ executableËsrc@sVeZdZdZeedƒZdZdd„Zdd„Z dd „Z d d gZ d d „Z dd„Z dd„ZdS)rz­Complete HTTP server with GET, HEAD and POST commands. GET and HEAD also support running CGI scripts. The POST command is *only* implemented for CGI scripts. ÚforkrcCs&| ¡r | ¡dS| tjd¡dS)zRServe a POST request. This is only implemented for CGI scripts. zCan only POST to CGI scriptsN)Úis_cgiÚrun_cgir/rrDrArrrÚdo_POSTás  þzCGIHTTPRequestHandler.do_POSTcCs| ¡r| ¡St |¡S)z-Version of send_head that support CGI scripts)rrrr«rArrrr«ïs zCGIHTTPRequestHandler.send_headcCs’t|jƒ}| dd¡}|dkr-|d|…|jvr-| d|d¡}|dkr-|d|…|jvs|dkrG|d|…||dd…}}||f|_dSdS)a3Test whether self.path corresponds to a CGI script. Returns True and updates the cgi_info attribute to the tuple (dir, rest) if self.path requires running a CGI script. Returns False otherwise. If any exception is raised, the caller should assume that self.path was rejected as invalid and act accordingly. The default implementation tests whether the normalized url path begins with one of the strings in self.cgi_directories (and the next character is a '/' or the end of the string). rrrNTF)rúr1ÚfindÚcgi_directoriesÚcgi_info)rrùZdir_sepÚheadÚtailrrrrös  ÿ zCGIHTTPRequestHandler.is_cgiz/cgi-binz/htbincCst|ƒS)z1Test whether argument path is an executable file.)r)rr1rrrÚ is_executablesz#CGIHTTPRequestHandler.is_executablecCstj |¡\}}| ¡dvS)z.Test whether argument path is a Python script.)z.pyz.pyw)r£r1rîr9)rr1r r rrrÚ is_pythons zCGIHTTPRequestHandler.is_pythonc) CsŒ|j\}}|d|}| dt|ƒd¡}|dkrG|d|…}||dd…}| |¡}tj |¡rB||}}| dt|ƒd¡}nn|dks| d¡\}}} | d¡}|dkrf|d|…||d…} }n|d} }|d| } | | ¡} tj | ¡s‡|  t j d| ¡dStj  | ¡s˜|  t j d| ¡dS| | ¡} |js¢| s²| | ¡s²|  t j d | ¡dSt tj¡}| ¡|d <|jj|d <d |d <|j|d<t|jjƒ|d<|j|d<tj |¡}||d<| |¡|d<| |d<| |d<|jd|d<|j  d¡}|rV| !¡}t|ƒdkrVddl"}ddl#}|d|d<|d $¡dkrVz|d %d¡}| &|¡ 'd¡}Wn |j(t)fyCYnw| !d¡}t|ƒdkrV|d|d<|j  d¡durg|j *¡|d<n|jd|d<|j  d¡}|r{||d <|j  d!¡}|rˆ||d"<|j +d#d$¡}d% ,|¡|d&<|j  d'¡}|r£||d(<t-d|j +d)g¡ƒ}d* ,|¡}|r¹||d+<d,D] }| .|d¡q»| /t j0d-¡| 1¡|  2d.d/¡}|jrw| g}d0|vrç| 3|¡t4ƒ}|j5 6¡t 7¡}|dkr4t 8|d¡\}}t9 9|j:gggd¡dr"|j: ;d¡sn t9 9|j:gggd¡ds t <|¡}|r2| =d1|›¡dSz.zt >|¡Wn t?yFYnwt @|j: A¡d¡t @|j5 A¡d¡t B| ||¡WdS|j C|jD|j¡t Ed2¡YdSddlF} | g}!| | ¡r¡tGjH}"|" $¡ Id3¡r›|"dd4…|"d5d…}"|"d6g|!}!d0| vr«|! 3| ¡| Jd7|  K|!¡¡ztL|ƒ}#WntMtNfyÈd}#Ynw| jO|!| jP| jP| jP|d8}$|j $¡d9krê|#dkrê|j: ;|#¡}%nd}%t9 9|j:jQgggd¡dr|j:jQ Rd¡snt9 9|j:jQgggd¡dsú|$ S|%¡\}&}'|j5 T|&¡|'r'| =d:|'¡|$jU V¡|$jW V¡|$jX}(|(r?| =d;|(¡dS| Jd<¡dS)=zExecute a CGI script.rrrNrärzNo such CGI script (%r)z#CGI script is not a plain file (%r)z!CGI script is not executable (%r)ZSERVER_SOFTWAREZ SERVER_NAMEzCGI/1.1ZGATEWAY_INTERFACEZSERVER_PROTOCOLZ SERVER_PORTZREQUEST_METHODZ PATH_INFOZPATH_TRANSLATEDZ SCRIPT_NAMEÚ QUERY_STRINGZ REMOTE_ADDRÚ authorizationr Z AUTH_TYPEZbasicÚasciiú:Z REMOTE_USERz content-typeZ CONTENT_TYPEzcontent-lengthÚCONTENT_LENGTHÚrefererÚ HTTP_REFERERÚacceptrú,Z HTTP_ACCEPTz user-agentÚHTTP_USER_AGENTZcookiez, Ú HTTP_COOKIE)rZ REMOTE_HOSTrrrrzScript output followsú+rƒú=zCGI script exit code rzzw.exeéûÿÿÿéüÿÿÿz-uz command: %s)ÚstdinÚstdoutr~ÚenvZpostz%szCGI script exit status %#xzCGI script exited OK)Yr r r*r·r£r1r¸rôÚexistsr/rr¿r¼Z FORBIDDENrÚ have_forkrÚcopyZdeepcopyÚenvironrdZserverrr0r%rr!r¹rºr×rr7r8r)Úbase64Úbinasciir9r_Z decodebytesÚdecodeÚErrorÚ UnicodeErrorZget_content_typeZget_allrorèÚ setdefaultrYrÉrmrUrjrrFrGrÚwaitpidÚselectr5ÚreadÚwaitstatus_to_exitcoderIÚsetuidrÁÚdup2rÃÚexecveZ handle_errorÚrequestÚ_exitÚ subprocessr}rr»rrZ list2cmdliner-rÄr,ÚPopenÚPIPEZ_sockZrecvZ communicaterar~rr Ú returncode))rÚdirÚrestr1ÚiZnextdirZnextrestZ scriptdirròröZscriptZ scriptnameZ scriptfileZispyr!Zuqrestrr&r'ZlengthrrZuaÚcoZ cookie_strÚkZ decoded_queryrurûÚpidÚstsZexitcoder5ZcmdlineZinterpÚnbytesÚpÚdatar r~Zstatusrrrrs@      ÷     þ þ   þ        ÿÿ           þ ÿ     ÿüþ    zCGIHTTPRequestHandler.run_cgiN)rrrr•rCr£r#Zrbufsizerr«rr rrrrrrrrÐs  rcGs4tj|tjtjdœŽ}tt|ƒƒ\}}}}}||fS)N)ÚtypeÚflags)r Z getaddrinfoZ SOCK_STREAMZ AI_PASSIVEÚnextÚiter)ZaddressZinfosZfamilyrCÚprotoZ canonnameZsockaddrrrrÚ_get_best_familyÖsýrHri@c CsØt||ƒ\|_}||_|||ƒR}|j ¡dd…\}}d|vr&d|›dn|}td|›d|›d|›d|›d ƒz| ¡WntyQtd ƒt  d ¡Yn wWdƒdSWdƒdS1sewYdS) zmTest the HTTP request handler class. This runs an HTTP server on port 8000 (or the port argument). Nr rú[ú]zServing HTTP on z port z (http://z/) ...z& Keyboard interrupt received, exiting.r) rHZaddress_familyr0r Z getsocknameÚprintZ serve_foreverÚKeyboardInterruptr}Úexit) Ú HandlerClassÚ ServerClassZprotocolrÚbindZaddrZhttpdrZurl_hostrrrÚtestàs, ÿÿÿ  þÿø "õrQÚ__main__z--cgiÚ store_truezrun as CGI server)ÚactionÚhelpz--bindz-bZADDRESSz8specify alternate bind address (default: all interfaces))ÚmetavarrUz --directoryz-dz8specify alternate directory (default: current directory))ÚdefaultrUrZstoreräz&specify alternate port (default: 8000))rTrWrCÚnargsrUcs$eZdZ‡fdd„Zdd„Z‡ZS)ÚDualStackServercsHt t¡|j tjtjd¡Wdƒn1swYtƒ ¡S)Nr) Ú contextlibÚsuppressÚ Exceptionr Z setsockoptZ IPPROTO_IPV6Z IPV6_V6ONLYr¦r rAr©rrr s  ÿÿ zDualStackServer.server_bindcCs|j|||tjddS)Nr¡)ZRequestHandlerClassrur¢)rr3rrrrÚfinish_requests  ÿzDualStackServer.finish_request)rrrr r]rórrr©rrYs rY)rNrOrrP)7r•r–Ú__all__r$rÆZ email.utilsr‡r]Z http.clientr3rÛršrðr£rær-rìr r r}r†Z urllib.parser¹rr—r˜r rZThreadingMixInrZStreamRequestHandlerrrrúrûrrrrHrQrÚargparserZÚArgumentParserÚparserÚ add_argumentr¤r-Ú parse_argsruZcgiZ handler_classrYrrPrrrrÚs’R  s0  þÿ ÿÿ þ  üÜ