e;RSrSr/SQrSSKrSSKrSSKrSSKrSSKr SSK r SSK r SSK r SSK r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK Jr SrSr"SS \R45r"S S \R8\5r"S S \R<5r"SS\5r Sr!Sq"Sr#Sr$"SS\ 5r%Sr&\\SSS4Sjr'\(S:XaSSK)r)SSK*r*\)RV"5r,\,R[SSSS9 \,R[SSS S!S"9 \,R[S#S$\ R\"5S%S&9 \,R[S'S(S)SS*S+9 \,R[S,S\/S-S.S/9 \,Ra5r1\1Rd(a\%r3O\ r3"S0S1\5r4\'"\3\4\1Rj\1Rl\1RnS29 gg)3aHTTP server classes. Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST, and (deprecated) CGIHTTPRequestHandler for CGI scripts. It does, however, optionally implement HTTP/1.1 persistent connections. Notes on CGIHTTPRequestHandler ------------------------------ This class is deprecated. It implements GET and POST requests to cgi-bin scripts. If the os.fork() function is not present (Windows), subprocess.Popen() is used, with slightly altered but never documented semantics. Use from a threaded process is likely to trigger a warning at os.fork() time. 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) HTTPServerThreadingHTTPServerBaseHTTPRequestHandlerSimpleHTTPRequestHandlerCGIHTTPRequestHandlerN) HTTPStatusaD Error response

Error response

Error code: %(code)d

Message: %(message)s.

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

ztext/html;charset=utf-8c\rSrSrSrSrSrg)rc[RRU5 URSSup[R "U5UlX lg)z.Override server_bind to store the server name.N) socketserver TCPServer server_bindserver_addresssocketgetfqdn server_name server_port)selfhostports 1/opt/imh/python3.13/lib/python3.13/http/server.pyrHTTPServer.server_bindsA**40((!, !>>$/)rrN)__name__ __module__ __qualname____firstlineno__allow_reuse_addressr__static_attributes__rrrrs  rrc\rSrSrSrSrg)rTr"N)rrrrdaemon_threadsr!r"rrrrsNrrc h\rSrSrSrS\R R5S-rS\ -r \ r \ rSrSrSrS rS rS$S jrS%S jrS%SjrSrSrSrS&SjrSr\R;\R>"\ "S5\ "SS55VVs0sH oSUS3_M snn5r!S\!\""S5'Sr#Sr$S%Sjr%Sr&/SQr'/S Qr(S!r)S"r*\+RXRZr.\/R`Rc5VVs0sHnX"RdURf4_M snnr4S#r5g s snnfs snnf)'ra 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.9czSUlUR=UlnSUl[ UR S5nUR S5nX lUR5n[U5S:Xag[U5S:Ga USnURS 5(d[eURS S 5S nURS 5n[U5S :wa[e[SU55(a [S5e[SU55(a [S5e[US5[US 54nUS:aUR$S:aSUlUS:a$UR[ R&SU-5 gXlS [U5s=::aS::d&O UR[ R"SU-5 gUSS upg[U5S :Xa1SUlUS:wa$UR[ R"SU-5 gXgsUlUlUR(RS5(a#S UR(R+S 5-Ul[,R.R1UR2UR4S9UlUR6R?SS5n U RA5S :XaSUlO+U RA5S!:XaUR$S:aSUlUR6R?S"S5n U RA5S#:Xa6UR$S:a&URS:aURC5(dgg![[4a& UR[ R"SU-5 gf=f![,R.R8a4nUR[ R:S[ U55 SnAgSnAf[,R.R<a4nUR[ R:S[ U55 SnAgSnAff=f)$aParse 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-1 rFzHTTP//r .r c3J# UHoR5(+v M g7fN)isdigit.0 components r 7BaseHTTPRequestHandler.parse_request../sO9,,...s!#znon digit in http versionc3># UHn[U5S:v M g7f) N)lenr2s rr5r61sKNys9~*Nsz unreasonable length http versionzBad request version (%r))r r zHTTP/1.1)r rzInvalid HTTP version (%s)zBad request syntax (%r)GETzBad HTTP/0.9 request type (%r)z//)_classz Line too longzToo many headers Connectionclose keep-aliveExpectz 100-continue)"commanddefault_request_versionrequest_versionclose_connectionstrraw_requestlinerstrip requestlinesplitr9 startswith ValueErroranyint IndexError send_errorr BAD_REQUESTprotocol_versionHTTP_VERSION_NOT_SUPPORTEDpathlstriphttpclient parse_headersrfile MessageClassheaders LineTooLongREQUEST_HEADER_FIELDS_TOO_LARGE HTTPExceptiongetlowerhandle_expect_100) rversionrHwordsbase_version_numberversion_numberrArSerrconntypeexpects r parse_request$BaseHTTPRequestHandler.parse_request s )-)E)EEw $$.. = !((0 &!!# u:? u:?BiG ))'22$$&-mmC&;A&>#!4!:!:3!?~&!+$$OOOO$%@AAKNKKK$%GHH!$^A%6!7^A=N9O!O 'D,A,AZ,O(-%'99/2EEG#* CJ#!# OO&&)K7 9bq  u:?$(D !%**4w>@") di 99   % %dii..s33DI ;;44TZZ<@> w &$(D !nn,.##z1$)D !!!(B/ LLNn ,%%3$$ 2))++G + **.8:  P{{&&  OO::C {{((  OO::"C    s7B7M7N3NNP:6*O%%!P:*P55P:cbUR[R5 UR5 g)aDecide 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_onlyrCONTINUE end_headersrs rr`(BaseHTTPRequestHandler.handle_expect_100ys'  3 34 rcURRS5Ul[UR5S:a5SUlSUlSUlUR[R5 gUR(dSUl gUR5(dgSUR -n[X5(d.UR[RSUR -5 g[X5nU"5 URR!5 g!["a#nUR%SU5 SUl SnAgSnAff=f) zHandle 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. iir=NTdo_zUnsupported method (%r)zRequest timed out: %r)rXreadlinerFr9rHrCrArOrREQUEST_URI_TOO_LONGrDrhhasattrNOT_IMPLEMENTEDgetattrwfileflush TimeoutError log_error)rmnamemethodes rhandle_one_request)BaseHTTPRequestHandler.handle_one_requests  #'::#6#6u#=D 4''(50#% ')$!  ? ?@''(,%%%''DLL(E4''..- <>T)F H JJ     NN2A 6$(D !   s1A-D0D DA D,,D E#EEcSUlUR5 UR(d$UR5 UR(dM#gg)z&Handle multiple requests if necessary.TN)rDr~rns rhandleBaseHTTPRequestHandler.handles9 $ !''  # # %'''rNcURUupEUcUnUcUnURSX5 URX5 UR SS5 SnUS:aU[ R [ R[ R4;aURU[R"USS9[R"USS9S .-nURS S 5nUR S UR5 UR S [[U555 UR!5 UR"S:wa$U(aUR$R'U5 ggg![a SupEGN[f=f)a Send 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. )???rNzcode %d, message %sr<r>Fquote)codemessageexplainzUTF-8replacez Content-TypeContent-LengthHEAD) responsesKeyErrorrz send_response send_headerr NO_CONTENT RESET_CONTENT NOT_MODIFIEDerror_message_formathtmlescapeencodeerror_content_typerEr9rmrArwwrite)rrrrshortmsglongmsgbodycontents rrO!BaseHTTPRequestHandler.send_errorsV$ - $t 4 H ?G ?G ,d< 4) w/  CK ..#11#002 2 00;;we<;;we<4G >>'95D   ^T-D-D E   -s3t9~ >  <<6 !d JJ  T "'+ != - , Hg -sEE/.E/cURU5 URX5 URSUR55 URSUR 55 g)zAdd 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. ServerDateN) log_requestrkrversion_stringdate_time_stringrrrs rr$BaseHTTPRequestHandler.send_responsesR  . 4#6#6#89 !6!6!89rcURS:wazUc$XR;aURUSnOSn[US5(d/UlURR SUR X4-R SS55 gg) zSend the response header only.r(Nrr=_headers_bufferz %s %d %s latin-1strict)rCrrtrappendrQrrs rrk)BaseHTTPRequestHandler.send_response_onlys   : ->>)"nnT215G G4!233')$  ' '**D:*;Tr?FN)rCrtrrrr_rD)rkeywordvalues rr"BaseHTTPRequestHandler.send_headers   : -4!233')$  ' '!(%088HM O ==?l *{{}'(,%,.(-%/ +rc|URS:wa,URRS5 UR5 gg)z,Send the blank line ending the MIME headers.r(s N)rCrr flush_headersrns rrm"BaseHTTPRequestHandler.end_headerss5   : -  ' ' 0     .rc[US5(a<URRSRUR55 /Ulgg)Nrr)rtrwrjoinrrns rr$BaseHTTPRequestHandler.flush_headerss> 4* + + JJ  SXXd&:&:; <#%D  ,rc[U[5(a URnURSUR[ U5[ U55 g)z>Log an accepted request. This is called by send_response(). z "%s" %s %sN) isinstancerr log_messagerHrE)rrsizes rr"BaseHTTPRequestHandler.log_request!s@ dJ ' '::D ))3t9c$i Arc*UR"U/UQ76 g)zLog 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)r)rformatargss rrz BaseHTTPRequestHandler.log_error,s '$'r z\x02xz\\\c X-n[RRUR5<SUR 5<SUR UR 5<S35 g)aLog 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 - - [z]  N)sysstderrraddress_stringlog_date_time_string translate_control_char_table)rrrrs rr"BaseHTTPRequestHandler.log_message?sP(- --/335!++D,D,DEG Hrc:URS-UR-$)z*Return the server software version string. )server_version sys_versionrns rr%BaseHTTPRequestHandler.version_stringYs""S(4+;+;;;rcnUc[R"5n[RRUSS9$)z@Return the current date and time formatted for a message header.T)usegmt)timeemailutils formatdate)r timestamps rr'BaseHTTPRequestHandler.date_time_string]s-   I{{%%i%==rc [R"5n[R"U5u p#pEpgpn SX@RUX%Xg4-n U $)z.Return the current time formatted for logging.z%02d/%3s/%04d %02d:%02d:%02d)r localtime monthname) rnowyearmonthdayhhmmssxyzss rr+BaseHTTPRequestHandler.log_date_time_stringcsJiik04s0C-SbaA *^^E*Db.> >r)MonTueWedThuFriSatSun) NJanFebMarAprMayJunJulAugSepOctNovDecc URS$)zReturn the client address.r)client_addressrns rr%BaseHTTPRequestHandler.address_stringqs""1%%rHTTP/1.0)rrDrArZrSrFrCrH)NNr0)-r)6rrrr__doc__rrarIr __version__rDEFAULT_ERROR_MESSAGErDEFAULT_ERROR_CONTENT_TYPErrBrhr`r~rrOrrkrrmrrrzrE maketrans itertoolschainrangerordrrrr weekdaynamerrrQrUrV HTTPMessagerYr __members__valuesphrase descriptionrr!)r3cvs000rrrskdNckk//1!44K !;.N03 )l\$#J&3#j : . .! & A (--'0uT{E$tDT'U V'U!2aW 'U VX%*D "H4<> DK;I&";;**L ''..00A HHamm $$0II WHs D( ?"D.rc~^\rSrSrSrS\-rSrSSSSS .=rr S S .U4S jjr S r Sr Sr SrSrSrSrS rU=r$)ria?Simple 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/)z index.htmlz index.htmzapplication/gzipapplication/octet-streamzapplication/x-bzip2zapplication/x-xz)z.gzz.Zz.bz2z.xzN directoryc>Uc[R"5n[R"U5Ul[TU]"U0UD6 gr0)osgetcwdfspathrsuper__init__)rrrkwargs __class__s rr!SimpleHTTPRequestHandler.__init__s6   I9- $)&)rcUR5nU(a-URXR5 UR5 gg!UR5 f=f)zServe a GET request.N) send_headcopyfilerwr>rfs rdo_GETSimpleHTTPRequestHandler.do_GETsA NN    a,  s AAcTUR5nU(aUR5 gg)zServe a HEAD request.N)r#r>r%s rdo_HEAD SimpleHTTPRequestHandler.do_HEADs NN  GGI rc^URUR5nSn[RRU5(Ga@[R R UR5nURRS5(dUR[R5 USUSUSS-USUS4n[R RU5nURSU5 URS S 5 UR5 gURHJn[RRX5n[RR!U5(dMHUn O UR#U5$UR%U5nURS5(a!UR'[R(S 5 g[+US 5n[R."UR155nS UR2;Ga/SUR2;Ga[4R6R9UR2S 5n U R:c'U R=[>R@RBS9n U R:[>R@RBLa[>R>REURF[>R@RB5n U R=SS9n X::a@UR[RH5 UR5 URK5 gUR[RT5 URSU5 URS [WUS55 URSURYURF55 UR5 U$![,a# UR'[R(S 5 gf=f![L[N[P[R4a Nf=f! URK5 e=f)aKCommon 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. Nr-rr r r+Locationr0zFile not foundrbzIf-Modified-Sincez If-None-Match)tzinfo) microsecond Content-typez Last-Modified)-translate_pathrSrisdirurllibparseurlsplitendswithrrMOVED_PERMANENTLY urlunsplitrrm index_pagesrisfilelist_directory guess_typerO NOT_FOUNDopenOSErrorfstatfilenorZrrparsedate_to_datetimer1rdatetimetimezoneutc fromtimestampst_mtimerr> TypeErrorrN OverflowErrorrKOKrEr) rrSr&parts new_partsnew_urlindexctypefsims last_modifs rr#"SimpleHTTPRequestHandler.send_headsJ""499-  77==  LL))$))4E::&&s++"":#?#?@"1XuQxqC"1XuQx1  ,,11)<  W5  !137  ")) T177>>%(( D * **400% ==   OOJ002B C T4 A ' !((*%B#t||3't||;(++;; %89;C zz)"kk1B1B1F1FkGzzX%6%6%:%::%-%6%6%D%DKK):):)>)>&@ &0%7%7A%7%F %, ..z/F/FG ,,.GGI#'   z}} -   ^U 3   -s2a5z :   _%%bkk2 4    HQ  OOJ002B C ":}jI8  GGI sK O AP ,O9 C0P=B P *O65O69PPPPP,c [R"U5nUR SS9 /n[RRURSS9n[R"USS9n[R"5nS U3nUR!S 5 UR!S 5 UR!S 5 UR!S US35 UR!SUS35 UR!SUS35 UR!S5 UHn[RR#X5nU=p[RR%U5(a US-n US-n [RR'U5(aUS-n UR!S[RR)U SS9<S[R"U SS9<S35 M UR!S5 SR#U5R+US5n [,R."5n U R1U 5 U R3S5 UR5[R65 UR9SSU-5 UR9S[;[=U 555 UR?5 U $![a# UR[R S5 gf=f![a- [RRUR5nGNf=f)zHelper 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 directoryNc"UR5$r0)r_)as r9SimpleHTTPRequestHandler.list_directory..s  r)key surrogatepasserrorsFrzDirectory listing for zzzzzz z

z

z