Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
File: httplib.py
r"""HTTP/1.1 client library
[0] Fix | Delete
[1] Fix | Delete
<intro stuff goes here>
[2] Fix | Delete
<other stuff, too>
[3] Fix | Delete
[4] Fix | Delete
HTTPConnection goes through a number of "states", which define when a client
[5] Fix | Delete
may legally make another request or fetch the response for a particular
[6] Fix | Delete
request. This diagram details these state transitions:
[7] Fix | Delete
[8] Fix | Delete
(null)
[9] Fix | Delete
|
[10] Fix | Delete
| HTTPConnection()
[11] Fix | Delete
v
[12] Fix | Delete
Idle
[13] Fix | Delete
|
[14] Fix | Delete
| putrequest()
[15] Fix | Delete
v
[16] Fix | Delete
Request-started
[17] Fix | Delete
|
[18] Fix | Delete
| ( putheader() )* endheaders()
[19] Fix | Delete
v
[20] Fix | Delete
Request-sent
[21] Fix | Delete
|
[22] Fix | Delete
| response = getresponse()
[23] Fix | Delete
v
[24] Fix | Delete
Unread-response [Response-headers-read]
[25] Fix | Delete
|\____________________
[26] Fix | Delete
| |
[27] Fix | Delete
| response.read() | putrequest()
[28] Fix | Delete
v v
[29] Fix | Delete
Idle Req-started-unread-response
[30] Fix | Delete
______/|
[31] Fix | Delete
/ |
[32] Fix | Delete
response.read() | | ( putheader() )* endheaders()
[33] Fix | Delete
v v
[34] Fix | Delete
Request-started Req-sent-unread-response
[35] Fix | Delete
|
[36] Fix | Delete
| response.read()
[37] Fix | Delete
v
[38] Fix | Delete
Request-sent
[39] Fix | Delete
[40] Fix | Delete
This diagram presents the following rules:
[41] Fix | Delete
-- a second request may not be started until {response-headers-read}
[42] Fix | Delete
-- a response [object] cannot be retrieved until {request-sent}
[43] Fix | Delete
-- there is no differentiation between an unread response body and a
[44] Fix | Delete
partially read response body
[45] Fix | Delete
[46] Fix | Delete
Note: this enforcement is applied by the HTTPConnection class. The
[47] Fix | Delete
HTTPResponse class does not enforce this state machine, which
[48] Fix | Delete
implies sophisticated clients may accelerate the request/response
[49] Fix | Delete
pipeline. Caution should be taken, though: accelerating the states
[50] Fix | Delete
beyond the above pattern may imply knowledge of the server's
[51] Fix | Delete
connection-close behavior for certain requests. For example, it
[52] Fix | Delete
is impossible to tell whether the server will close the connection
[53] Fix | Delete
UNTIL the response headers have been read; this means that further
[54] Fix | Delete
requests cannot be placed into the pipeline until it is known that
[55] Fix | Delete
the server will NOT be closing the connection.
[56] Fix | Delete
[57] Fix | Delete
Logical State __state __response
[58] Fix | Delete
------------- ------- ----------
[59] Fix | Delete
Idle _CS_IDLE None
[60] Fix | Delete
Request-started _CS_REQ_STARTED None
[61] Fix | Delete
Request-sent _CS_REQ_SENT None
[62] Fix | Delete
Unread-response _CS_IDLE <response_class>
[63] Fix | Delete
Req-started-unread-response _CS_REQ_STARTED <response_class>
[64] Fix | Delete
Req-sent-unread-response _CS_REQ_SENT <response_class>
[65] Fix | Delete
"""
[66] Fix | Delete
[67] Fix | Delete
from array import array
[68] Fix | Delete
import os
[69] Fix | Delete
import re
[70] Fix | Delete
import socket
[71] Fix | Delete
from sys import py3kwarning
[72] Fix | Delete
from urlparse import urlsplit
[73] Fix | Delete
import warnings
[74] Fix | Delete
with warnings.catch_warnings():
[75] Fix | Delete
if py3kwarning:
[76] Fix | Delete
warnings.filterwarnings("ignore", ".*mimetools has been removed",
[77] Fix | Delete
DeprecationWarning)
[78] Fix | Delete
import mimetools
[79] Fix | Delete
[80] Fix | Delete
try:
[81] Fix | Delete
from cStringIO import StringIO
[82] Fix | Delete
except ImportError:
[83] Fix | Delete
from StringIO import StringIO
[84] Fix | Delete
[85] Fix | Delete
__all__ = ["HTTP", "HTTPResponse", "HTTPConnection",
[86] Fix | Delete
"HTTPException", "NotConnected", "UnknownProtocol",
[87] Fix | Delete
"UnknownTransferEncoding", "UnimplementedFileMode",
[88] Fix | Delete
"IncompleteRead", "InvalidURL", "ImproperConnectionState",
[89] Fix | Delete
"CannotSendRequest", "CannotSendHeader", "ResponseNotReady",
[90] Fix | Delete
"BadStatusLine", "error", "responses"]
[91] Fix | Delete
[92] Fix | Delete
HTTP_PORT = 80
[93] Fix | Delete
HTTPS_PORT = 443
[94] Fix | Delete
[95] Fix | Delete
_UNKNOWN = 'UNKNOWN'
[96] Fix | Delete
[97] Fix | Delete
# connection states
[98] Fix | Delete
_CS_IDLE = 'Idle'
[99] Fix | Delete
_CS_REQ_STARTED = 'Request-started'
[100] Fix | Delete
_CS_REQ_SENT = 'Request-sent'
[101] Fix | Delete
[102] Fix | Delete
# status codes
[103] Fix | Delete
# informational
[104] Fix | Delete
CONTINUE = 100
[105] Fix | Delete
SWITCHING_PROTOCOLS = 101
[106] Fix | Delete
PROCESSING = 102
[107] Fix | Delete
[108] Fix | Delete
# successful
[109] Fix | Delete
OK = 200
[110] Fix | Delete
CREATED = 201
[111] Fix | Delete
ACCEPTED = 202
[112] Fix | Delete
NON_AUTHORITATIVE_INFORMATION = 203
[113] Fix | Delete
NO_CONTENT = 204
[114] Fix | Delete
RESET_CONTENT = 205
[115] Fix | Delete
PARTIAL_CONTENT = 206
[116] Fix | Delete
MULTI_STATUS = 207
[117] Fix | Delete
IM_USED = 226
[118] Fix | Delete
[119] Fix | Delete
# redirection
[120] Fix | Delete
MULTIPLE_CHOICES = 300
[121] Fix | Delete
MOVED_PERMANENTLY = 301
[122] Fix | Delete
FOUND = 302
[123] Fix | Delete
SEE_OTHER = 303
[124] Fix | Delete
NOT_MODIFIED = 304
[125] Fix | Delete
USE_PROXY = 305
[126] Fix | Delete
TEMPORARY_REDIRECT = 307
[127] Fix | Delete
[128] Fix | Delete
# client error
[129] Fix | Delete
BAD_REQUEST = 400
[130] Fix | Delete
UNAUTHORIZED = 401
[131] Fix | Delete
PAYMENT_REQUIRED = 402
[132] Fix | Delete
FORBIDDEN = 403
[133] Fix | Delete
NOT_FOUND = 404
[134] Fix | Delete
METHOD_NOT_ALLOWED = 405
[135] Fix | Delete
NOT_ACCEPTABLE = 406
[136] Fix | Delete
PROXY_AUTHENTICATION_REQUIRED = 407
[137] Fix | Delete
REQUEST_TIMEOUT = 408
[138] Fix | Delete
CONFLICT = 409
[139] Fix | Delete
GONE = 410
[140] Fix | Delete
LENGTH_REQUIRED = 411
[141] Fix | Delete
PRECONDITION_FAILED = 412
[142] Fix | Delete
REQUEST_ENTITY_TOO_LARGE = 413
[143] Fix | Delete
REQUEST_URI_TOO_LONG = 414
[144] Fix | Delete
UNSUPPORTED_MEDIA_TYPE = 415
[145] Fix | Delete
REQUESTED_RANGE_NOT_SATISFIABLE = 416
[146] Fix | Delete
EXPECTATION_FAILED = 417
[147] Fix | Delete
UNPROCESSABLE_ENTITY = 422
[148] Fix | Delete
LOCKED = 423
[149] Fix | Delete
FAILED_DEPENDENCY = 424
[150] Fix | Delete
UPGRADE_REQUIRED = 426
[151] Fix | Delete
[152] Fix | Delete
# server error
[153] Fix | Delete
INTERNAL_SERVER_ERROR = 500
[154] Fix | Delete
NOT_IMPLEMENTED = 501
[155] Fix | Delete
BAD_GATEWAY = 502
[156] Fix | Delete
SERVICE_UNAVAILABLE = 503
[157] Fix | Delete
GATEWAY_TIMEOUT = 504
[158] Fix | Delete
HTTP_VERSION_NOT_SUPPORTED = 505
[159] Fix | Delete
INSUFFICIENT_STORAGE = 507
[160] Fix | Delete
NOT_EXTENDED = 510
[161] Fix | Delete
[162] Fix | Delete
# Mapping status codes to official W3C names
[163] Fix | Delete
responses = {
[164] Fix | Delete
100: 'Continue',
[165] Fix | Delete
101: 'Switching Protocols',
[166] Fix | Delete
[167] Fix | Delete
200: 'OK',
[168] Fix | Delete
201: 'Created',
[169] Fix | Delete
202: 'Accepted',
[170] Fix | Delete
203: 'Non-Authoritative Information',
[171] Fix | Delete
204: 'No Content',
[172] Fix | Delete
205: 'Reset Content',
[173] Fix | Delete
206: 'Partial Content',
[174] Fix | Delete
[175] Fix | Delete
300: 'Multiple Choices',
[176] Fix | Delete
301: 'Moved Permanently',
[177] Fix | Delete
302: 'Found',
[178] Fix | Delete
303: 'See Other',
[179] Fix | Delete
304: 'Not Modified',
[180] Fix | Delete
305: 'Use Proxy',
[181] Fix | Delete
306: '(Unused)',
[182] Fix | Delete
307: 'Temporary Redirect',
[183] Fix | Delete
[184] Fix | Delete
400: 'Bad Request',
[185] Fix | Delete
401: 'Unauthorized',
[186] Fix | Delete
402: 'Payment Required',
[187] Fix | Delete
403: 'Forbidden',
[188] Fix | Delete
404: 'Not Found',
[189] Fix | Delete
405: 'Method Not Allowed',
[190] Fix | Delete
406: 'Not Acceptable',
[191] Fix | Delete
407: 'Proxy Authentication Required',
[192] Fix | Delete
408: 'Request Timeout',
[193] Fix | Delete
409: 'Conflict',
[194] Fix | Delete
410: 'Gone',
[195] Fix | Delete
411: 'Length Required',
[196] Fix | Delete
412: 'Precondition Failed',
[197] Fix | Delete
413: 'Request Entity Too Large',
[198] Fix | Delete
414: 'Request-URI Too Long',
[199] Fix | Delete
415: 'Unsupported Media Type',
[200] Fix | Delete
416: 'Requested Range Not Satisfiable',
[201] Fix | Delete
417: 'Expectation Failed',
[202] Fix | Delete
[203] Fix | Delete
500: 'Internal Server Error',
[204] Fix | Delete
501: 'Not Implemented',
[205] Fix | Delete
502: 'Bad Gateway',
[206] Fix | Delete
503: 'Service Unavailable',
[207] Fix | Delete
504: 'Gateway Timeout',
[208] Fix | Delete
505: 'HTTP Version Not Supported',
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
# maximal amount of data to read at one time in _safe_read
[212] Fix | Delete
MAXAMOUNT = 1048576
[213] Fix | Delete
[214] Fix | Delete
# maximal line length when calling readline().
[215] Fix | Delete
_MAXLINE = 65536
[216] Fix | Delete
[217] Fix | Delete
# maximum amount of headers accepted
[218] Fix | Delete
_MAXHEADERS = 100
[219] Fix | Delete
[220] Fix | Delete
# Header name/value ABNF (http://tools.ietf.org/html/rfc7230#section-3.2)
[221] Fix | Delete
#
[222] Fix | Delete
# VCHAR = %x21-7E
[223] Fix | Delete
# obs-text = %x80-FF
[224] Fix | Delete
# header-field = field-name ":" OWS field-value OWS
[225] Fix | Delete
# field-name = token
[226] Fix | Delete
# field-value = *( field-content / obs-fold )
[227] Fix | Delete
# field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
[228] Fix | Delete
# field-vchar = VCHAR / obs-text
[229] Fix | Delete
#
[230] Fix | Delete
# obs-fold = CRLF 1*( SP / HTAB )
[231] Fix | Delete
# ; obsolete line folding
[232] Fix | Delete
# ; see Section 3.2.4
[233] Fix | Delete
[234] Fix | Delete
# token = 1*tchar
[235] Fix | Delete
#
[236] Fix | Delete
# tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
[237] Fix | Delete
# / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
[238] Fix | Delete
# / DIGIT / ALPHA
[239] Fix | Delete
# ; any VCHAR, except delimiters
[240] Fix | Delete
#
[241] Fix | Delete
# VCHAR defined in http://tools.ietf.org/html/rfc5234#appendix-B.1
[242] Fix | Delete
[243] Fix | Delete
# the patterns for both name and value are more lenient than RFC
[244] Fix | Delete
# definitions to allow for backwards compatibility
[245] Fix | Delete
_is_legal_header_name = re.compile(r'\A[^:\s][^:\r\n]*\Z').match
[246] Fix | Delete
_is_illegal_header_value = re.compile(r'\n(?![ \t])|\r(?![ \t\n])').search
[247] Fix | Delete
[248] Fix | Delete
# These characters are not allowed within HTTP URL paths.
[249] Fix | Delete
# See https://tools.ietf.org/html/rfc3986#section-3.3 and the
[250] Fix | Delete
# https://tools.ietf.org/html/rfc3986#appendix-A pchar definition.
[251] Fix | Delete
# Prevents CVE-2019-9740. Includes control characters such as \r\n.
[252] Fix | Delete
# Restrict non-ASCII characters above \x7f (0x80-0xff).
[253] Fix | Delete
_contains_disallowed_url_pchar_re = re.compile('[\x00-\x20\x7f-\xff]')
[254] Fix | Delete
# Arguably only these _should_ allowed:
[255] Fix | Delete
# _is_allowed_url_pchars_re = re.compile(r"^[/!$&'()*+,;=:@%a-zA-Z0-9._~-]+$")
[256] Fix | Delete
# We are more lenient for assumed real world compatibility purposes.
[257] Fix | Delete
[258] Fix | Delete
# These characters are not allowed within HTTP method names
[259] Fix | Delete
# to prevent http header injection.
[260] Fix | Delete
_contains_disallowed_method_pchar_re = re.compile('[\x00-\x1f]')
[261] Fix | Delete
[262] Fix | Delete
# We always set the Content-Length header for these methods because some
[263] Fix | Delete
# servers will otherwise respond with a 411
[264] Fix | Delete
_METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'}
[265] Fix | Delete
[266] Fix | Delete
[267] Fix | Delete
class HTTPMessage(mimetools.Message):
[268] Fix | Delete
[269] Fix | Delete
def addheader(self, key, value):
[270] Fix | Delete
"""Add header for field key handling repeats."""
[271] Fix | Delete
prev = self.dict.get(key)
[272] Fix | Delete
if prev is None:
[273] Fix | Delete
self.dict[key] = value
[274] Fix | Delete
else:
[275] Fix | Delete
combined = ", ".join((prev, value))
[276] Fix | Delete
self.dict[key] = combined
[277] Fix | Delete
[278] Fix | Delete
def addcontinue(self, key, more):
[279] Fix | Delete
"""Add more field data from a continuation line."""
[280] Fix | Delete
prev = self.dict[key]
[281] Fix | Delete
self.dict[key] = prev + "\n " + more
[282] Fix | Delete
[283] Fix | Delete
def readheaders(self):
[284] Fix | Delete
"""Read header lines.
[285] Fix | Delete
[286] Fix | Delete
Read header lines up to the entirely blank line that terminates them.
[287] Fix | Delete
The (normally blank) line that ends the headers is skipped, but not
[288] Fix | Delete
included in the returned list. If an invalid line is found in the
[289] Fix | Delete
header section, it is skipped, and further lines are processed.
[290] Fix | Delete
[291] Fix | Delete
The variable self.status is set to the empty string if all went well,
[292] Fix | Delete
otherwise it is an error message. The variable self.headers is a
[293] Fix | Delete
completely uninterpreted list of lines contained in the header (so
[294] Fix | Delete
printing them will reproduce the header exactly as it appears in the
[295] Fix | Delete
file).
[296] Fix | Delete
[297] Fix | Delete
If multiple header fields with the same name occur, they are combined
[298] Fix | Delete
according to the rules in RFC 2616 sec 4.2:
[299] Fix | Delete
[300] Fix | Delete
Appending each subsequent field-value to the first, each separated
[301] Fix | Delete
by a comma. The order in which header fields with the same field-name
[302] Fix | Delete
are received is significant to the interpretation of the combined
[303] Fix | Delete
field value.
[304] Fix | Delete
"""
[305] Fix | Delete
# XXX The implementation overrides the readheaders() method of
[306] Fix | Delete
# rfc822.Message. The base class design isn't amenable to
[307] Fix | Delete
# customized behavior here so the method here is a copy of the
[308] Fix | Delete
# base class code with a few small changes.
[309] Fix | Delete
[310] Fix | Delete
self.dict = {}
[311] Fix | Delete
self.unixfrom = ''
[312] Fix | Delete
self.headers = hlist = []
[313] Fix | Delete
self.status = ''
[314] Fix | Delete
headerseen = ""
[315] Fix | Delete
firstline = 1
[316] Fix | Delete
tell = None
[317] Fix | Delete
if not hasattr(self.fp, 'unread') and self.seekable:
[318] Fix | Delete
tell = self.fp.tell
[319] Fix | Delete
while True:
[320] Fix | Delete
if len(hlist) > _MAXHEADERS:
[321] Fix | Delete
raise HTTPException("got more than %d headers" % _MAXHEADERS)
[322] Fix | Delete
if tell:
[323] Fix | Delete
try:
[324] Fix | Delete
tell()
[325] Fix | Delete
except IOError:
[326] Fix | Delete
tell = None
[327] Fix | Delete
self.seekable = 0
[328] Fix | Delete
line = self.fp.readline(_MAXLINE + 1)
[329] Fix | Delete
if len(line) > _MAXLINE:
[330] Fix | Delete
raise LineTooLong("header line")
[331] Fix | Delete
if not line:
[332] Fix | Delete
self.status = 'EOF in headers'
[333] Fix | Delete
break
[334] Fix | Delete
# Skip unix From name time lines
[335] Fix | Delete
if firstline and line.startswith('From '):
[336] Fix | Delete
self.unixfrom = self.unixfrom + line
[337] Fix | Delete
continue
[338] Fix | Delete
firstline = 0
[339] Fix | Delete
if headerseen and line[0] in ' \t':
[340] Fix | Delete
# XXX Not sure if continuation lines are handled properly
[341] Fix | Delete
# for http and/or for repeating headers
[342] Fix | Delete
# It's a continuation line.
[343] Fix | Delete
hlist.append(line)
[344] Fix | Delete
self.addcontinue(headerseen, line.strip())
[345] Fix | Delete
continue
[346] Fix | Delete
elif self.iscomment(line):
[347] Fix | Delete
# It's a comment. Ignore it.
[348] Fix | Delete
continue
[349] Fix | Delete
elif self.islast(line):
[350] Fix | Delete
# Note! No pushback here! The delimiter line gets eaten.
[351] Fix | Delete
break
[352] Fix | Delete
headerseen = self.isheader(line)
[353] Fix | Delete
if headerseen:
[354] Fix | Delete
# It's a legal header line, save it.
[355] Fix | Delete
hlist.append(line)
[356] Fix | Delete
self.addheader(headerseen, line[len(headerseen)+1:].strip())
[357] Fix | Delete
elif headerseen is not None:
[358] Fix | Delete
# An empty header name. These aren't allowed in HTTP, but it's
[359] Fix | Delete
# probably a benign mistake. Don't add the header, just keep
[360] Fix | Delete
# going.
[361] Fix | Delete
pass
[362] Fix | Delete
else:
[363] Fix | Delete
# It's not a header line; skip it and try the next line.
[364] Fix | Delete
self.status = 'Non-header line where header expected'
[365] Fix | Delete
[366] Fix | Delete
[367] Fix | Delete
def _read_headers(fp):
[368] Fix | Delete
"""Reads potential header lines into a list from a file pointer.
[369] Fix | Delete
Length of line is limited by _MAXLINE, and number of
[370] Fix | Delete
headers is limited by _MAXHEADERS.
[371] Fix | Delete
"""
[372] Fix | Delete
headers = []
[373] Fix | Delete
while True:
[374] Fix | Delete
line = fp.readline(_MAXLINE + 1)
[375] Fix | Delete
if len(line) > _MAXLINE:
[376] Fix | Delete
raise LineTooLong("header line")
[377] Fix | Delete
headers.append(line)
[378] Fix | Delete
if len(headers) > _MAXHEADERS:
[379] Fix | Delete
raise HTTPException("got more than %d headers" % _MAXHEADERS)
[380] Fix | Delete
if line in (b'\r\n', b'\n', b''):
[381] Fix | Delete
break
[382] Fix | Delete
return headers
[383] Fix | Delete
[384] Fix | Delete
[385] Fix | Delete
class HTTPResponse:
[386] Fix | Delete
[387] Fix | Delete
# strict: If true, raise BadStatusLine if the status line can't be
[388] Fix | Delete
# parsed as a valid HTTP/1.0 or 1.1 status line. By default it is
[389] Fix | Delete
# false because it prevents clients from talking to HTTP/0.9
[390] Fix | Delete
# servers. Note that a response with a sufficiently corrupted
[391] Fix | Delete
# status line will look like an HTTP/0.9 response.
[392] Fix | Delete
[393] Fix | Delete
# See RFC 2616 sec 19.6 and RFC 1945 sec 6 for details.
[394] Fix | Delete
[395] Fix | Delete
def __init__(self, sock, debuglevel=0, strict=0, method=None, buffering=False):
[396] Fix | Delete
if buffering:
[397] Fix | Delete
# The caller won't be using any sock.recv() calls, so buffering
[398] Fix | Delete
# is fine and recommended for performance.
[399] Fix | Delete
self.fp = sock.makefile('rb')
[400] Fix | Delete
else:
[401] Fix | Delete
# The buffer size is specified as zero, because the headers of
[402] Fix | Delete
# the response are read with readline(). If the reads were
[403] Fix | Delete
# buffered the readline() calls could consume some of the
[404] Fix | Delete
# response, which make be read via a recv() on the underlying
[405] Fix | Delete
# socket.
[406] Fix | Delete
self.fp = sock.makefile('rb', 0)
[407] Fix | Delete
self.debuglevel = debuglevel
[408] Fix | Delete
self.strict = strict
[409] Fix | Delete
self._method = method
[410] Fix | Delete
[411] Fix | Delete
self.msg = None
[412] Fix | Delete
[413] Fix | Delete
# from the Status-Line of the response
[414] Fix | Delete
self.version = _UNKNOWN # HTTP-Version
[415] Fix | Delete
self.status = _UNKNOWN # Status-Code
[416] Fix | Delete
self.reason = _UNKNOWN # Reason-Phrase
[417] Fix | Delete
[418] Fix | Delete
self.chunked = _UNKNOWN # is "chunked" being used?
[419] Fix | Delete
self.chunk_left = _UNKNOWN # bytes left to read in current chunk
[420] Fix | Delete
self.length = _UNKNOWN # number of bytes left in response
[421] Fix | Delete
self.will_close = _UNKNOWN # conn will close at end of response
[422] Fix | Delete
[423] Fix | Delete
def _read_status(self):
[424] Fix | Delete
# Initialize with Simple-Response defaults
[425] Fix | Delete
line = self.fp.readline(_MAXLINE + 1)
[426] Fix | Delete
if len(line) > _MAXLINE:
[427] Fix | Delete
raise LineTooLong("header line")
[428] Fix | Delete
if self.debuglevel > 0:
[429] Fix | Delete
print "reply:", repr(line)
[430] Fix | Delete
if not line:
[431] Fix | Delete
# Presumably, the server closed the connection before
[432] Fix | Delete
# sending a valid response.
[433] Fix | Delete
raise BadStatusLine("No status line received - the server has closed the connection")
[434] Fix | Delete
try:
[435] Fix | Delete
[version, status, reason] = line.split(None, 2)
[436] Fix | Delete
except ValueError:
[437] Fix | Delete
try:
[438] Fix | Delete
[version, status] = line.split(None, 1)
[439] Fix | Delete
reason = ""
[440] Fix | Delete
except ValueError:
[441] Fix | Delete
# empty version will cause next test to fail and status
[442] Fix | Delete
# will be treated as 0.9 response.
[443] Fix | Delete
version = ""
[444] Fix | Delete
if not version.startswith('HTTP/'):
[445] Fix | Delete
if self.strict:
[446] Fix | Delete
self.close()
[447] Fix | Delete
raise BadStatusLine(line)
[448] Fix | Delete
else:
[449] Fix | Delete
# assume it's a Simple-Response from an 0.9 server
[450] Fix | Delete
self.fp = LineAndFileWrapper(line, self.fp)
[451] Fix | Delete
return "HTTP/0.9", 200, ""
[452] Fix | Delete
[453] Fix | Delete
# The status code is a three-digit number
[454] Fix | Delete
try:
[455] Fix | Delete
status = int(status)
[456] Fix | Delete
if status < 100 or status > 999:
[457] Fix | Delete
raise BadStatusLine(line)
[458] Fix | Delete
except ValueError:
[459] Fix | Delete
raise BadStatusLine(line)
[460] Fix | Delete
return version, status, reason
[461] Fix | Delete
[462] Fix | Delete
def begin(self):
[463] Fix | Delete
if self.msg is not None:
[464] Fix | Delete
# we've already started reading the response
[465] Fix | Delete
return
[466] Fix | Delete
[467] Fix | Delete
# read until we get a non-100 response
[468] Fix | Delete
while True:
[469] Fix | Delete
version, status, reason = self._read_status()
[470] Fix | Delete
if status != CONTINUE:
[471] Fix | Delete
break
[472] Fix | Delete
# skip the header from the 100 response
[473] Fix | Delete
skipped_headers = _read_headers(self.fp)
[474] Fix | Delete
if self.debuglevel > 0:
[475] Fix | Delete
print("headers:", skipped_headers)
[476] Fix | Delete
del skipped_headers
[477] Fix | Delete
[478] Fix | Delete
self.status = status
[479] Fix | Delete
self.reason = reason.strip()
[480] Fix | Delete
if version == 'HTTP/1.0':
[481] Fix | Delete
self.version = 10
[482] Fix | Delete
elif version.startswith('HTTP/1.'):
[483] Fix | Delete
self.version = 11 # use HTTP/1.1 code for HTTP/1.x where x>=1
[484] Fix | Delete
elif version == 'HTTP/0.9':
[485] Fix | Delete
self.version = 9
[486] Fix | Delete
else:
[487] Fix | Delete
raise UnknownProtocol(version)
[488] Fix | Delete
[489] Fix | Delete
if self.version == 9:
[490] Fix | Delete
self.length = None
[491] Fix | Delete
self.chunked = 0
[492] Fix | Delete
self.will_close = 1
[493] Fix | Delete
self.msg = HTTPMessage(StringIO())
[494] Fix | Delete
return
[495] Fix | Delete
[496] Fix | Delete
self.msg = HTTPMessage(self.fp, 0)
[497] Fix | Delete
if self.debuglevel > 0:
[498] Fix | Delete
for hdr in self.msg.headers:
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function