Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/python27/lib64/python2....
File: BaseHTTPServer.py
"""HTTP server base class.
[0] Fix | Delete
[1] Fix | Delete
Note: the class in this module doesn't implement any HTTP request; see
[2] Fix | Delete
SimpleHTTPServer for simple implementations of GET, HEAD and POST
[3] Fix | Delete
(including CGI scripts). It does, however, optionally implement HTTP/1.1
[4] Fix | Delete
persistent connections, as of version 0.3.
[5] Fix | Delete
[6] Fix | Delete
Contents:
[7] Fix | Delete
[8] Fix | Delete
- BaseHTTPRequestHandler: HTTP request handler base class
[9] Fix | Delete
- test: test function
[10] Fix | Delete
[11] Fix | Delete
XXX To do:
[12] Fix | Delete
[13] Fix | Delete
- log requests even later (to capture byte count)
[14] Fix | Delete
- log user-agent header and other interesting goodies
[15] Fix | Delete
- send error log to separate file
[16] Fix | Delete
"""
[17] Fix | Delete
[18] Fix | Delete
[19] Fix | Delete
# See also:
[20] Fix | Delete
#
[21] Fix | Delete
# HTTP Working Group T. Berners-Lee
[22] Fix | Delete
# INTERNET-DRAFT R. T. Fielding
[23] Fix | Delete
# <draft-ietf-http-v10-spec-00.txt> H. Frystyk Nielsen
[24] Fix | Delete
# Expires September 8, 1995 March 8, 1995
[25] Fix | Delete
#
[26] Fix | Delete
# URL: http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt
[27] Fix | Delete
#
[28] Fix | Delete
# and
[29] Fix | Delete
#
[30] Fix | Delete
# Network Working Group R. Fielding
[31] Fix | Delete
# Request for Comments: 2616 et al
[32] Fix | Delete
# Obsoletes: 2068 June 1999
[33] Fix | Delete
# Category: Standards Track
[34] Fix | Delete
#
[35] Fix | Delete
# URL: http://www.faqs.org/rfcs/rfc2616.html
[36] Fix | Delete
[37] Fix | Delete
# Log files
[38] Fix | Delete
# ---------
[39] Fix | Delete
#
[40] Fix | Delete
# Here's a quote from the NCSA httpd docs about log file format.
[41] Fix | Delete
#
[42] Fix | Delete
# | The logfile format is as follows. Each line consists of:
[43] Fix | Delete
# |
[44] Fix | Delete
# | host rfc931 authuser [DD/Mon/YYYY:hh:mm:ss] "request" ddd bbbb
[45] Fix | Delete
# |
[46] Fix | Delete
# | host: Either the DNS name or the IP number of the remote client
[47] Fix | Delete
# | rfc931: Any information returned by identd for this person,
[48] Fix | Delete
# | - otherwise.
[49] Fix | Delete
# | authuser: If user sent a userid for authentication, the user name,
[50] Fix | Delete
# | - otherwise.
[51] Fix | Delete
# | DD: Day
[52] Fix | Delete
# | Mon: Month (calendar name)
[53] Fix | Delete
# | YYYY: Year
[54] Fix | Delete
# | hh: hour (24-hour format, the machine's timezone)
[55] Fix | Delete
# | mm: minutes
[56] Fix | Delete
# | ss: seconds
[57] Fix | Delete
# | request: The first line of the HTTP request as sent by the client.
[58] Fix | Delete
# | ddd: the status code returned by the server, - if not available.
[59] Fix | Delete
# | bbbb: the total number of bytes sent,
[60] Fix | Delete
# | *not including the HTTP/1.0 header*, - if not available
[61] Fix | Delete
# |
[62] Fix | Delete
# | You can determine the name of the file accessed through request.
[63] Fix | Delete
#
[64] Fix | Delete
# (Actually, the latter is only true if you know the server configuration
[65] Fix | Delete
# at the time the request was made!)
[66] Fix | Delete
[67] Fix | Delete
__version__ = "0.3"
[68] Fix | Delete
[69] Fix | Delete
__all__ = ["HTTPServer", "BaseHTTPRequestHandler"]
[70] Fix | Delete
[71] Fix | Delete
import sys
[72] Fix | Delete
import time
[73] Fix | Delete
import socket # For gethostbyaddr()
[74] Fix | Delete
from warnings import filterwarnings, catch_warnings
[75] Fix | Delete
with catch_warnings():
[76] Fix | Delete
if sys.py3kwarning:
[77] Fix | Delete
filterwarnings("ignore", ".*mimetools has been removed",
[78] Fix | Delete
DeprecationWarning)
[79] Fix | Delete
import mimetools
[80] Fix | Delete
import SocketServer
[81] Fix | Delete
[82] Fix | Delete
# Default error message template
[83] Fix | Delete
DEFAULT_ERROR_MESSAGE = """\
[84] Fix | Delete
<head>
[85] Fix | Delete
<title>Error response</title>
[86] Fix | Delete
</head>
[87] Fix | Delete
<body>
[88] Fix | Delete
<h1>Error response</h1>
[89] Fix | Delete
<p>Error code %(code)d.
[90] Fix | Delete
<p>Message: %(message)s.
[91] Fix | Delete
<p>Error code explanation: %(code)s = %(explain)s.
[92] Fix | Delete
</body>
[93] Fix | Delete
"""
[94] Fix | Delete
[95] Fix | Delete
DEFAULT_ERROR_CONTENT_TYPE = "text/html"
[96] Fix | Delete
[97] Fix | Delete
def _quote_html(html):
[98] Fix | Delete
return html.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
[99] Fix | Delete
[100] Fix | Delete
class HTTPServer(SocketServer.TCPServer):
[101] Fix | Delete
[102] Fix | Delete
allow_reuse_address = 1 # Seems to make sense in testing environment
[103] Fix | Delete
[104] Fix | Delete
def server_bind(self):
[105] Fix | Delete
"""Override server_bind to store the server name."""
[106] Fix | Delete
SocketServer.TCPServer.server_bind(self)
[107] Fix | Delete
host, port = self.socket.getsockname()[:2]
[108] Fix | Delete
self.server_name = socket.getfqdn(host)
[109] Fix | Delete
self.server_port = port
[110] Fix | Delete
[111] Fix | Delete
[112] Fix | Delete
class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
[113] Fix | Delete
[114] Fix | Delete
"""HTTP request handler base class.
[115] Fix | Delete
[116] Fix | Delete
The following explanation of HTTP serves to guide you through the
[117] Fix | Delete
code as well as to expose any misunderstandings I may have about
[118] Fix | Delete
HTTP (so you don't need to read the code to figure out I'm wrong
[119] Fix | Delete
:-).
[120] Fix | Delete
[121] Fix | Delete
HTTP (HyperText Transfer Protocol) is an extensible protocol on
[122] Fix | Delete
top of a reliable stream transport (e.g. TCP/IP). The protocol
[123] Fix | Delete
recognizes three parts to a request:
[124] Fix | Delete
[125] Fix | Delete
1. One line identifying the request type and path
[126] Fix | Delete
2. An optional set of RFC-822-style headers
[127] Fix | Delete
3. An optional data part
[128] Fix | Delete
[129] Fix | Delete
The headers and data are separated by a blank line.
[130] Fix | Delete
[131] Fix | Delete
The first line of the request has the form
[132] Fix | Delete
[133] Fix | Delete
<command> <path> <version>
[134] Fix | Delete
[135] Fix | Delete
where <command> is a (case-sensitive) keyword such as GET or POST,
[136] Fix | Delete
<path> is a string containing path information for the request,
[137] Fix | Delete
and <version> should be the string "HTTP/1.0" or "HTTP/1.1".
[138] Fix | Delete
<path> is encoded using the URL encoding scheme (using %xx to signify
[139] Fix | Delete
the ASCII character with hex code xx).
[140] Fix | Delete
[141] Fix | Delete
The specification specifies that lines are separated by CRLF but
[142] Fix | Delete
for compatibility with the widest range of clients recommends
[143] Fix | Delete
servers also handle LF. Similarly, whitespace in the request line
[144] Fix | Delete
is treated sensibly (allowing multiple spaces between components
[145] Fix | Delete
and allowing trailing whitespace).
[146] Fix | Delete
[147] Fix | Delete
Similarly, for output, lines ought to be separated by CRLF pairs
[148] Fix | Delete
but most clients grok LF characters just fine.
[149] Fix | Delete
[150] Fix | Delete
If the first line of the request has the form
[151] Fix | Delete
[152] Fix | Delete
<command> <path>
[153] Fix | Delete
[154] Fix | Delete
(i.e. <version> is left out) then this is assumed to be an HTTP
[155] Fix | Delete
0.9 request; this form has no optional headers and data part and
[156] Fix | Delete
the reply consists of just the data.
[157] Fix | Delete
[158] Fix | Delete
The reply form of the HTTP 1.x protocol again has three parts:
[159] Fix | Delete
[160] Fix | Delete
1. One line giving the response code
[161] Fix | Delete
2. An optional set of RFC-822-style headers
[162] Fix | Delete
3. The data
[163] Fix | Delete
[164] Fix | Delete
Again, the headers and data are separated by a blank line.
[165] Fix | Delete
[166] Fix | Delete
The response code line has the form
[167] Fix | Delete
[168] Fix | Delete
<version> <responsecode> <responsestring>
[169] Fix | Delete
[170] Fix | Delete
where <version> is the protocol version ("HTTP/1.0" or "HTTP/1.1"),
[171] Fix | Delete
<responsecode> is a 3-digit response code indicating success or
[172] Fix | Delete
failure of the request, and <responsestring> is an optional
[173] Fix | Delete
human-readable string explaining what the response code means.
[174] Fix | Delete
[175] Fix | Delete
This server parses the request and the headers, and then calls a
[176] Fix | Delete
function specific to the request type (<command>). Specifically,
[177] Fix | Delete
a request SPAM will be handled by a method do_SPAM(). If no
[178] Fix | Delete
such method exists the server sends an error response to the
[179] Fix | Delete
client. If it exists, it is called with no arguments:
[180] Fix | Delete
[181] Fix | Delete
do_SPAM()
[182] Fix | Delete
[183] Fix | Delete
Note that the request name is case sensitive (i.e. SPAM and spam
[184] Fix | Delete
are different requests).
[185] Fix | Delete
[186] Fix | Delete
The various request details are stored in instance variables:
[187] Fix | Delete
[188] Fix | Delete
- client_address is the client IP address in the form (host,
[189] Fix | Delete
port);
[190] Fix | Delete
[191] Fix | Delete
- command, path and version are the broken-down request line;
[192] Fix | Delete
[193] Fix | Delete
- headers is an instance of mimetools.Message (or a derived
[194] Fix | Delete
class) containing the header information;
[195] Fix | Delete
[196] Fix | Delete
- rfile is a file object open for reading positioned at the
[197] Fix | Delete
start of the optional input data part;
[198] Fix | Delete
[199] Fix | Delete
- wfile is a file object open for writing.
[200] Fix | Delete
[201] Fix | Delete
IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING!
[202] Fix | Delete
[203] Fix | Delete
The first thing to be written must be the response line. Then
[204] Fix | Delete
follow 0 or more header lines, then a blank line, and then the
[205] Fix | Delete
actual data (if any). The meaning of the header lines depends on
[206] Fix | Delete
the command executed by the server; in most cases, when data is
[207] Fix | Delete
returned, there should be at least one header line of the form
[208] Fix | Delete
[209] Fix | Delete
Content-type: <type>/<subtype>
[210] Fix | Delete
[211] Fix | Delete
where <type> and <subtype> should be registered MIME types,
[212] Fix | Delete
e.g. "text/html" or "text/plain".
[213] Fix | Delete
[214] Fix | Delete
"""
[215] Fix | Delete
[216] Fix | Delete
# The Python system version, truncated to its first component.
[217] Fix | Delete
sys_version = "Python/" + sys.version.split()[0]
[218] Fix | Delete
[219] Fix | Delete
# The server software version. You may want to override this.
[220] Fix | Delete
# The format is multiple whitespace-separated strings,
[221] Fix | Delete
# where each string is of the form name[/version].
[222] Fix | Delete
server_version = "BaseHTTP/" + __version__
[223] Fix | Delete
[224] Fix | Delete
# The default request version. This only affects responses up until
[225] Fix | Delete
# the point where the request line is parsed, so it mainly decides what
[226] Fix | Delete
# the client gets back when sending a malformed request line.
[227] Fix | Delete
# Most web servers default to HTTP 0.9, i.e. don't send a status line.
[228] Fix | Delete
default_request_version = "HTTP/0.9"
[229] Fix | Delete
[230] Fix | Delete
def parse_request(self):
[231] Fix | Delete
"""Parse a request (internal).
[232] Fix | Delete
[233] Fix | Delete
The request should be stored in self.raw_requestline; the results
[234] Fix | Delete
are in self.command, self.path, self.request_version and
[235] Fix | Delete
self.headers.
[236] Fix | Delete
[237] Fix | Delete
Return True for success, False for failure; on failure, an
[238] Fix | Delete
error is sent back.
[239] Fix | Delete
[240] Fix | Delete
"""
[241] Fix | Delete
self.command = None # set in case of error on the first line
[242] Fix | Delete
self.request_version = version = self.default_request_version
[243] Fix | Delete
self.close_connection = 1
[244] Fix | Delete
requestline = self.raw_requestline
[245] Fix | Delete
requestline = requestline.rstrip('\r\n')
[246] Fix | Delete
self.requestline = requestline
[247] Fix | Delete
words = requestline.split()
[248] Fix | Delete
if len(words) == 3:
[249] Fix | Delete
command, path, version = words
[250] Fix | Delete
if version[:5] != 'HTTP/':
[251] Fix | Delete
self.send_error(400, "Bad request version (%r)" % version)
[252] Fix | Delete
return False
[253] Fix | Delete
try:
[254] Fix | Delete
base_version_number = version.split('/', 1)[1]
[255] Fix | Delete
version_number = base_version_number.split(".")
[256] Fix | Delete
# RFC 2145 section 3.1 says there can be only one "." and
[257] Fix | Delete
# - major and minor numbers MUST be treated as
[258] Fix | Delete
# separate integers;
[259] Fix | Delete
# - HTTP/2.4 is a lower version than HTTP/2.13, which in
[260] Fix | Delete
# turn is lower than HTTP/12.3;
[261] Fix | Delete
# - Leading zeros MUST be ignored by recipients.
[262] Fix | Delete
if len(version_number) != 2:
[263] Fix | Delete
raise ValueError
[264] Fix | Delete
version_number = int(version_number[0]), int(version_number[1])
[265] Fix | Delete
except (ValueError, IndexError):
[266] Fix | Delete
self.send_error(400, "Bad request version (%r)" % version)
[267] Fix | Delete
return False
[268] Fix | Delete
if version_number >= (1, 1) and self.protocol_version >= "HTTP/1.1":
[269] Fix | Delete
self.close_connection = 0
[270] Fix | Delete
if version_number >= (2, 0):
[271] Fix | Delete
self.send_error(505,
[272] Fix | Delete
"Invalid HTTP Version (%s)" % base_version_number)
[273] Fix | Delete
return False
[274] Fix | Delete
elif len(words) == 2:
[275] Fix | Delete
command, path = words
[276] Fix | Delete
self.close_connection = 1
[277] Fix | Delete
if command != 'GET':
[278] Fix | Delete
self.send_error(400,
[279] Fix | Delete
"Bad HTTP/0.9 request type (%r)" % command)
[280] Fix | Delete
return False
[281] Fix | Delete
elif not words:
[282] Fix | Delete
return False
[283] Fix | Delete
else:
[284] Fix | Delete
self.send_error(400, "Bad request syntax (%r)" % requestline)
[285] Fix | Delete
return False
[286] Fix | Delete
self.command, self.path, self.request_version = command, path, version
[287] Fix | Delete
[288] Fix | Delete
# Examine the headers and look for a Connection directive
[289] Fix | Delete
self.headers = self.MessageClass(self.rfile, 0)
[290] Fix | Delete
[291] Fix | Delete
conntype = self.headers.get('Connection', "")
[292] Fix | Delete
if conntype.lower() == 'close':
[293] Fix | Delete
self.close_connection = 1
[294] Fix | Delete
elif (conntype.lower() == 'keep-alive' and
[295] Fix | Delete
self.protocol_version >= "HTTP/1.1"):
[296] Fix | Delete
self.close_connection = 0
[297] Fix | Delete
return True
[298] Fix | Delete
[299] Fix | Delete
def handle_one_request(self):
[300] Fix | Delete
"""Handle a single HTTP request.
[301] Fix | Delete
[302] Fix | Delete
You normally don't need to override this method; see the class
[303] Fix | Delete
__doc__ string for information on how to handle specific HTTP
[304] Fix | Delete
commands such as GET and POST.
[305] Fix | Delete
[306] Fix | Delete
"""
[307] Fix | Delete
try:
[308] Fix | Delete
self.raw_requestline = self.rfile.readline(65537)
[309] Fix | Delete
if len(self.raw_requestline) > 65536:
[310] Fix | Delete
self.requestline = ''
[311] Fix | Delete
self.request_version = ''
[312] Fix | Delete
self.command = ''
[313] Fix | Delete
self.send_error(414)
[314] Fix | Delete
return
[315] Fix | Delete
if not self.raw_requestline:
[316] Fix | Delete
self.close_connection = 1
[317] Fix | Delete
return
[318] Fix | Delete
if not self.parse_request():
[319] Fix | Delete
# An error code has been sent, just exit
[320] Fix | Delete
return
[321] Fix | Delete
mname = 'do_' + self.command
[322] Fix | Delete
if not hasattr(self, mname):
[323] Fix | Delete
self.send_error(501, "Unsupported method (%r)" % self.command)
[324] Fix | Delete
return
[325] Fix | Delete
method = getattr(self, mname)
[326] Fix | Delete
method()
[327] Fix | Delete
self.wfile.flush() #actually send the response if not already done.
[328] Fix | Delete
except socket.timeout, e:
[329] Fix | Delete
#a read or a write timed out. Discard this connection
[330] Fix | Delete
self.log_error("Request timed out: %r", e)
[331] Fix | Delete
self.close_connection = 1
[332] Fix | Delete
return
[333] Fix | Delete
[334] Fix | Delete
def handle(self):
[335] Fix | Delete
"""Handle multiple requests if necessary."""
[336] Fix | Delete
self.close_connection = 1
[337] Fix | Delete
[338] Fix | Delete
self.handle_one_request()
[339] Fix | Delete
while not self.close_connection:
[340] Fix | Delete
self.handle_one_request()
[341] Fix | Delete
[342] Fix | Delete
def send_error(self, code, message=None):
[343] Fix | Delete
"""Send and log an error reply.
[344] Fix | Delete
[345] Fix | Delete
Arguments are the error code, and a detailed message.
[346] Fix | Delete
The detailed message defaults to the short entry matching the
[347] Fix | Delete
response code.
[348] Fix | Delete
[349] Fix | Delete
This sends an error response (so it must be called before any
[350] Fix | Delete
output has been generated), logs the error, and finally sends
[351] Fix | Delete
a piece of HTML explaining the error to the user.
[352] Fix | Delete
[353] Fix | Delete
"""
[354] Fix | Delete
[355] Fix | Delete
try:
[356] Fix | Delete
short, long = self.responses[code]
[357] Fix | Delete
except KeyError:
[358] Fix | Delete
short, long = '???', '???'
[359] Fix | Delete
if message is None:
[360] Fix | Delete
message = short
[361] Fix | Delete
explain = long
[362] Fix | Delete
self.log_error("code %d, message %s", code, message)
[363] Fix | Delete
self.send_response(code, message)
[364] Fix | Delete
self.send_header('Connection', 'close')
[365] Fix | Delete
[366] Fix | Delete
# Message body is omitted for cases described in:
[367] Fix | Delete
# - RFC7230: 3.3. 1xx, 204(No Content), 304(Not Modified)
[368] Fix | Delete
# - RFC7231: 6.3.6. 205(Reset Content)
[369] Fix | Delete
content = None
[370] Fix | Delete
if code >= 200 and code not in (204, 205, 304):
[371] Fix | Delete
# HTML encode to prevent Cross Site Scripting attacks
[372] Fix | Delete
# (see bug #1100201)
[373] Fix | Delete
content = (self.error_message_format % {
[374] Fix | Delete
'code': code,
[375] Fix | Delete
'message': _quote_html(message),
[376] Fix | Delete
'explain': explain
[377] Fix | Delete
})
[378] Fix | Delete
self.send_header("Content-Type", self.error_content_type)
[379] Fix | Delete
self.end_headers()
[380] Fix | Delete
[381] Fix | Delete
if self.command != 'HEAD' and content:
[382] Fix | Delete
self.wfile.write(content)
[383] Fix | Delete
[384] Fix | Delete
error_message_format = DEFAULT_ERROR_MESSAGE
[385] Fix | Delete
error_content_type = DEFAULT_ERROR_CONTENT_TYPE
[386] Fix | Delete
[387] Fix | Delete
def send_response(self, code, message=None):
[388] Fix | Delete
"""Send the response header and log the response code.
[389] Fix | Delete
[390] Fix | Delete
Also send two standard headers with the server software
[391] Fix | Delete
version and the current date.
[392] Fix | Delete
[393] Fix | Delete
"""
[394] Fix | Delete
self.log_request(code)
[395] Fix | Delete
if message is None:
[396] Fix | Delete
if code in self.responses:
[397] Fix | Delete
message = self.responses[code][0]
[398] Fix | Delete
else:
[399] Fix | Delete
message = ''
[400] Fix | Delete
if self.request_version != 'HTTP/0.9':
[401] Fix | Delete
self.wfile.write("%s %d %s\r\n" %
[402] Fix | Delete
(self.protocol_version, code, message))
[403] Fix | Delete
# print (self.protocol_version, code, message)
[404] Fix | Delete
self.send_header('Server', self.version_string())
[405] Fix | Delete
self.send_header('Date', self.date_time_string())
[406] Fix | Delete
[407] Fix | Delete
def send_header(self, keyword, value):
[408] Fix | Delete
"""Send a MIME header."""
[409] Fix | Delete
if self.request_version != 'HTTP/0.9':
[410] Fix | Delete
self.wfile.write("%s: %s\r\n" % (keyword, value))
[411] Fix | Delete
[412] Fix | Delete
if keyword.lower() == 'connection':
[413] Fix | Delete
if value.lower() == 'close':
[414] Fix | Delete
self.close_connection = 1
[415] Fix | Delete
elif value.lower() == 'keep-alive':
[416] Fix | Delete
self.close_connection = 0
[417] Fix | Delete
[418] Fix | Delete
def end_headers(self):
[419] Fix | Delete
"""Send the blank line ending the MIME headers."""
[420] Fix | Delete
if self.request_version != 'HTTP/0.9':
[421] Fix | Delete
self.wfile.write("\r\n")
[422] Fix | Delete
[423] Fix | Delete
def log_request(self, code='-', size='-'):
[424] Fix | Delete
"""Log an accepted request.
[425] Fix | Delete
[426] Fix | Delete
This is called by send_response().
[427] Fix | Delete
[428] Fix | Delete
"""
[429] Fix | Delete
[430] Fix | Delete
self.log_message('"%s" %s %s',
[431] Fix | Delete
self.requestline, str(code), str(size))
[432] Fix | Delete
[433] Fix | Delete
def log_error(self, format, *args):
[434] Fix | Delete
"""Log an error.
[435] Fix | Delete
[436] Fix | Delete
This is called when a request cannot be fulfilled. By
[437] Fix | Delete
default it passes the message on to log_message().
[438] Fix | Delete
[439] Fix | Delete
Arguments are the same as for log_message().
[440] Fix | Delete
[441] Fix | Delete
XXX This should go to the separate error log.
[442] Fix | Delete
[443] Fix | Delete
"""
[444] Fix | Delete
[445] Fix | Delete
self.log_message(format, *args)
[446] Fix | Delete
[447] Fix | Delete
def log_message(self, format, *args):
[448] Fix | Delete
"""Log an arbitrary message.
[449] Fix | Delete
[450] Fix | Delete
This is used by all other logging functions. Override
[451] Fix | Delete
it if you have specific logging wishes.
[452] Fix | Delete
[453] Fix | Delete
The first argument, FORMAT, is a format string for the
[454] Fix | Delete
message to be logged. If the format string contains
[455] Fix | Delete
any % escapes requiring parameters, they should be
[456] Fix | Delete
specified as subsequent arguments (it's just like
[457] Fix | Delete
printf!).
[458] Fix | Delete
[459] Fix | Delete
The client ip address and current date/time are prefixed to every
[460] Fix | Delete
message.
[461] Fix | Delete
[462] Fix | Delete
"""
[463] Fix | Delete
[464] Fix | Delete
sys.stderr.write("%s - - [%s] %s\n" %
[465] Fix | Delete
(self.client_address[0],
[466] Fix | Delete
self.log_date_time_string(),
[467] Fix | Delete
format%args))
[468] Fix | Delete
[469] Fix | Delete
def version_string(self):
[470] Fix | Delete
"""Return the server software version string."""
[471] Fix | Delete
return self.server_version + ' ' + self.sys_version
[472] Fix | Delete
[473] Fix | Delete
def date_time_string(self, timestamp=None):
[474] Fix | Delete
"""Return the current date and time formatted for a message header."""
[475] Fix | Delete
if timestamp is None:
[476] Fix | Delete
timestamp = time.time()
[477] Fix | Delete
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
[478] Fix | Delete
s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
[479] Fix | Delete
self.weekdayname[wd],
[480] Fix | Delete
day, self.monthname[month], year,
[481] Fix | Delete
hh, mm, ss)
[482] Fix | Delete
return s
[483] Fix | Delete
[484] Fix | Delete
def log_date_time_string(self):
[485] Fix | Delete
"""Return the current time formatted for logging."""
[486] Fix | Delete
now = time.time()
[487] Fix | Delete
year, month, day, hh, mm, ss, x, y, z = time.localtime(now)
[488] Fix | Delete
s = "%02d/%3s/%04d %02d:%02d:%02d" % (
[489] Fix | Delete
day, self.monthname[month], year, hh, mm, ss)
[490] Fix | Delete
return s
[491] Fix | Delete
[492] Fix | Delete
weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
[493] Fix | Delete
[494] Fix | Delete
monthname = [None,
[495] Fix | Delete
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
[496] Fix | Delete
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
[497] Fix | Delete
[498] Fix | Delete
def address_string(self):
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function