B °-_ó ã @ sâ d Z dZdddddgZddlZddlZddlZddlZddlZ ddl Z ddlZddlZddl Z ddlZddlZddlZddlZddlZddlZddlZdd lmZ dd l mZ dZdZG d d„ dejƒZG dd„ dejeƒZG dd„ dejƒZ G dd„ de ƒZ!dd„ Z"da#dd„ Z$dd„ Z%G dd„ de!ƒZ&e edddfdd„Z'e(dkrÞddl)Z)e) *¡ Z+e+j,ddd d! e+j,d"d#dd$d%d& e+j,d'd(e -¡ d)d* e+j,d+d,de.d-d.d/ e+ /¡ Z0e0j1r¾e&Z2nee!e0j3d0Z2e'e2e0j4e0j5d1 dS )2a@ 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)Úpartial)Ú HTTPStatusa¹
Error code: %(code)d
Message: %(message)s.
Error code explanation: %(code)s - %(explain)s.
ztext/html;charset=utf-8c @ s e Zd ZdZdd„ ZdS )r é c C s4 t j | ¡ | jdd… \}}t |¡| _|| _dS )z.Override server_bind to store the server name.Né )ÚsocketserverÚ TCPServerÚserver_bindÚserver_addressÚsocketZgetfqdnÚserver_nameÚserver_port)ÚselfÚhostÚport© r ú!/usr/lib/python3.7/http/server.pyr ‡ s zHTTPServer.server_bindN)Ú__name__Ú __module__Ú__qualname__Zallow_reuse_addressr r r r r r ƒ s c @ s e Zd ZdZdS )r TN)r r r Zdaemon_threadsr r r r r s c @ s e Zd ZdZdej ¡ d Zde Z e ZeZ dZdd„ Zdd „ Zd d„ Zdd „ Zd@dd„ZdAdd„ZdBdd„Zdd„ Zdd„ Zdd„ ZdCdd„Zdd„ Zd d!„ Zd"d#„ ZdDd$d%„Zd&d'„ Zd(d)d*d+d,d-d.gZdd/d0d1d2d3d4d5d6d7d8d9d:g Z d;d<„ Z!d=Z"e#j$j%Z&d>d?„ e'j( )¡ D ƒZ*dS )Er a¿ 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