Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../http
File: client.py
[1000] Fix | Delete
def _send_output(self, message_body=None, encode_chunked=False):
[1001] Fix | Delete
"""Send the currently buffered request and clear the buffer.
[1002] Fix | Delete
[1003] Fix | Delete
Appends an extra \\r\\n to the buffer.
[1004] Fix | Delete
A message_body may be specified, to be appended to the request.
[1005] Fix | Delete
"""
[1006] Fix | Delete
self._buffer.extend((b"", b""))
[1007] Fix | Delete
msg = b"\r\n".join(self._buffer)
[1008] Fix | Delete
del self._buffer[:]
[1009] Fix | Delete
self.send(msg)
[1010] Fix | Delete
[1011] Fix | Delete
if message_body is not None:
[1012] Fix | Delete
[1013] Fix | Delete
# create a consistent interface to message_body
[1014] Fix | Delete
if hasattr(message_body, 'read'):
[1015] Fix | Delete
# Let file-like take precedence over byte-like. This
[1016] Fix | Delete
# is needed to allow the current position of mmap'ed
[1017] Fix | Delete
# files to be taken into account.
[1018] Fix | Delete
chunks = self._read_readable(message_body)
[1019] Fix | Delete
else:
[1020] Fix | Delete
try:
[1021] Fix | Delete
# this is solely to check to see if message_body
[1022] Fix | Delete
# implements the buffer API. it /would/ be easier
[1023] Fix | Delete
# to capture if PyObject_CheckBuffer was exposed
[1024] Fix | Delete
# to Python.
[1025] Fix | Delete
memoryview(message_body)
[1026] Fix | Delete
except TypeError:
[1027] Fix | Delete
try:
[1028] Fix | Delete
chunks = iter(message_body)
[1029] Fix | Delete
except TypeError:
[1030] Fix | Delete
raise TypeError("message_body should be a bytes-like "
[1031] Fix | Delete
"object or an iterable, got %r"
[1032] Fix | Delete
% type(message_body))
[1033] Fix | Delete
else:
[1034] Fix | Delete
# the object implements the buffer interface and
[1035] Fix | Delete
# can be passed directly into socket methods
[1036] Fix | Delete
chunks = (message_body,)
[1037] Fix | Delete
[1038] Fix | Delete
for chunk in chunks:
[1039] Fix | Delete
if not chunk:
[1040] Fix | Delete
if self.debuglevel > 0:
[1041] Fix | Delete
print('Zero length chunk ignored')
[1042] Fix | Delete
continue
[1043] Fix | Delete
[1044] Fix | Delete
if encode_chunked and self._http_vsn == 11:
[1045] Fix | Delete
# chunked encoding
[1046] Fix | Delete
chunk = f'{len(chunk):X}\r\n'.encode('ascii') + chunk \
[1047] Fix | Delete
+ b'\r\n'
[1048] Fix | Delete
self.send(chunk)
[1049] Fix | Delete
[1050] Fix | Delete
if encode_chunked and self._http_vsn == 11:
[1051] Fix | Delete
# end chunked transfer
[1052] Fix | Delete
self.send(b'0\r\n\r\n')
[1053] Fix | Delete
[1054] Fix | Delete
def putrequest(self, method, url, skip_host=False,
[1055] Fix | Delete
skip_accept_encoding=False):
[1056] Fix | Delete
"""Send a request to the server.
[1057] Fix | Delete
[1058] Fix | Delete
`method' specifies an HTTP request method, e.g. 'GET'.
[1059] Fix | Delete
`url' specifies the object being requested, e.g. '/index.html'.
[1060] Fix | Delete
`skip_host' if True does not add automatically a 'Host:' header
[1061] Fix | Delete
`skip_accept_encoding' if True does not add automatically an
[1062] Fix | Delete
'Accept-Encoding:' header
[1063] Fix | Delete
"""
[1064] Fix | Delete
[1065] Fix | Delete
# if a prior response has been completed, then forget about it.
[1066] Fix | Delete
if self.__response and self.__response.isclosed():
[1067] Fix | Delete
self.__response = None
[1068] Fix | Delete
[1069] Fix | Delete
[1070] Fix | Delete
# in certain cases, we cannot issue another request on this connection.
[1071] Fix | Delete
# this occurs when:
[1072] Fix | Delete
# 1) we are in the process of sending a request. (_CS_REQ_STARTED)
[1073] Fix | Delete
# 2) a response to a previous request has signalled that it is going
[1074] Fix | Delete
# to close the connection upon completion.
[1075] Fix | Delete
# 3) the headers for the previous response have not been read, thus
[1076] Fix | Delete
# we cannot determine whether point (2) is true. (_CS_REQ_SENT)
[1077] Fix | Delete
#
[1078] Fix | Delete
# if there is no prior response, then we can request at will.
[1079] Fix | Delete
#
[1080] Fix | Delete
# if point (2) is true, then we will have passed the socket to the
[1081] Fix | Delete
# response (effectively meaning, "there is no prior response"), and
[1082] Fix | Delete
# will open a new one when a new request is made.
[1083] Fix | Delete
#
[1084] Fix | Delete
# Note: if a prior response exists, then we *can* start a new request.
[1085] Fix | Delete
# We are not allowed to begin fetching the response to this new
[1086] Fix | Delete
# request, however, until that prior response is complete.
[1087] Fix | Delete
#
[1088] Fix | Delete
if self.__state == _CS_IDLE:
[1089] Fix | Delete
self.__state = _CS_REQ_STARTED
[1090] Fix | Delete
else:
[1091] Fix | Delete
raise CannotSendRequest(self.__state)
[1092] Fix | Delete
[1093] Fix | Delete
self._validate_method(method)
[1094] Fix | Delete
[1095] Fix | Delete
# Save the method for use later in the response phase
[1096] Fix | Delete
self._method = method
[1097] Fix | Delete
[1098] Fix | Delete
url = url or '/'
[1099] Fix | Delete
self._validate_path(url)
[1100] Fix | Delete
[1101] Fix | Delete
request = '%s %s %s' % (method, url, self._http_vsn_str)
[1102] Fix | Delete
[1103] Fix | Delete
self._output(self._encode_request(request))
[1104] Fix | Delete
[1105] Fix | Delete
if self._http_vsn == 11:
[1106] Fix | Delete
# Issue some standard headers for better HTTP/1.1 compliance
[1107] Fix | Delete
[1108] Fix | Delete
if not skip_host:
[1109] Fix | Delete
# this header is issued *only* for HTTP/1.1
[1110] Fix | Delete
# connections. more specifically, this means it is
[1111] Fix | Delete
# only issued when the client uses the new
[1112] Fix | Delete
# HTTPConnection() class. backwards-compat clients
[1113] Fix | Delete
# will be using HTTP/1.0 and those clients may be
[1114] Fix | Delete
# issuing this header themselves. we should NOT issue
[1115] Fix | Delete
# it twice; some web servers (such as Apache) barf
[1116] Fix | Delete
# when they see two Host: headers
[1117] Fix | Delete
[1118] Fix | Delete
# If we need a non-standard port,include it in the
[1119] Fix | Delete
# header. If the request is going through a proxy,
[1120] Fix | Delete
# but the host of the actual URL, not the host of the
[1121] Fix | Delete
# proxy.
[1122] Fix | Delete
[1123] Fix | Delete
netloc = ''
[1124] Fix | Delete
if url.startswith('http'):
[1125] Fix | Delete
nil, netloc, nil, nil, nil = urlsplit(url)
[1126] Fix | Delete
[1127] Fix | Delete
if netloc:
[1128] Fix | Delete
try:
[1129] Fix | Delete
netloc_enc = netloc.encode("ascii")
[1130] Fix | Delete
except UnicodeEncodeError:
[1131] Fix | Delete
netloc_enc = netloc.encode("idna")
[1132] Fix | Delete
self.putheader('Host', netloc_enc)
[1133] Fix | Delete
else:
[1134] Fix | Delete
if self._tunnel_host:
[1135] Fix | Delete
host = self._tunnel_host
[1136] Fix | Delete
port = self._tunnel_port
[1137] Fix | Delete
else:
[1138] Fix | Delete
host = self.host
[1139] Fix | Delete
port = self.port
[1140] Fix | Delete
[1141] Fix | Delete
try:
[1142] Fix | Delete
host_enc = host.encode("ascii")
[1143] Fix | Delete
except UnicodeEncodeError:
[1144] Fix | Delete
host_enc = host.encode("idna")
[1145] Fix | Delete
[1146] Fix | Delete
# As per RFC 273, IPv6 address should be wrapped with []
[1147] Fix | Delete
# when used as Host header
[1148] Fix | Delete
[1149] Fix | Delete
if host.find(':') >= 0:
[1150] Fix | Delete
host_enc = b'[' + host_enc + b']'
[1151] Fix | Delete
[1152] Fix | Delete
if port == self.default_port:
[1153] Fix | Delete
self.putheader('Host', host_enc)
[1154] Fix | Delete
else:
[1155] Fix | Delete
host_enc = host_enc.decode("ascii")
[1156] Fix | Delete
self.putheader('Host', "%s:%s" % (host_enc, port))
[1157] Fix | Delete
[1158] Fix | Delete
# note: we are assuming that clients will not attempt to set these
[1159] Fix | Delete
# headers since *this* library must deal with the
[1160] Fix | Delete
# consequences. this also means that when the supporting
[1161] Fix | Delete
# libraries are updated to recognize other forms, then this
[1162] Fix | Delete
# code should be changed (removed or updated).
[1163] Fix | Delete
[1164] Fix | Delete
# we only want a Content-Encoding of "identity" since we don't
[1165] Fix | Delete
# support encodings such as x-gzip or x-deflate.
[1166] Fix | Delete
if not skip_accept_encoding:
[1167] Fix | Delete
self.putheader('Accept-Encoding', 'identity')
[1168] Fix | Delete
[1169] Fix | Delete
# we can accept "chunked" Transfer-Encodings, but no others
[1170] Fix | Delete
# NOTE: no TE header implies *only* "chunked"
[1171] Fix | Delete
#self.putheader('TE', 'chunked')
[1172] Fix | Delete
[1173] Fix | Delete
# if TE is supplied in the header, then it must appear in a
[1174] Fix | Delete
# Connection header.
[1175] Fix | Delete
#self.putheader('Connection', 'TE')
[1176] Fix | Delete
[1177] Fix | Delete
else:
[1178] Fix | Delete
# For HTTP/1.0, the server will assume "not chunked"
[1179] Fix | Delete
pass
[1180] Fix | Delete
[1181] Fix | Delete
def _encode_request(self, request):
[1182] Fix | Delete
# ASCII also helps prevent CVE-2019-9740.
[1183] Fix | Delete
return request.encode('ascii')
[1184] Fix | Delete
[1185] Fix | Delete
def _validate_method(self, method):
[1186] Fix | Delete
"""Validate a method name for putrequest."""
[1187] Fix | Delete
# prevent http header injection
[1188] Fix | Delete
match = _contains_disallowed_method_pchar_re.search(method)
[1189] Fix | Delete
if match:
[1190] Fix | Delete
raise ValueError(
[1191] Fix | Delete
f"method can't contain control characters. {method!r} "
[1192] Fix | Delete
f"(found at least {match.group()!r})")
[1193] Fix | Delete
[1194] Fix | Delete
def _validate_path(self, url):
[1195] Fix | Delete
"""Validate a url for putrequest."""
[1196] Fix | Delete
# Prevent CVE-2019-9740.
[1197] Fix | Delete
match = _contains_disallowed_url_pchar_re.search(url)
[1198] Fix | Delete
if match:
[1199] Fix | Delete
raise InvalidURL(f"URL can't contain control characters. {url!r} "
[1200] Fix | Delete
f"(found at least {match.group()!r})")
[1201] Fix | Delete
[1202] Fix | Delete
def _validate_host(self, host):
[1203] Fix | Delete
"""Validate a host so it doesn't contain control characters."""
[1204] Fix | Delete
# Prevent CVE-2019-18348.
[1205] Fix | Delete
match = _contains_disallowed_url_pchar_re.search(host)
[1206] Fix | Delete
if match:
[1207] Fix | Delete
raise InvalidURL(f"URL can't contain control characters. {host!r} "
[1208] Fix | Delete
f"(found at least {match.group()!r})")
[1209] Fix | Delete
[1210] Fix | Delete
def putheader(self, header, *values):
[1211] Fix | Delete
"""Send a request header line to the server.
[1212] Fix | Delete
[1213] Fix | Delete
For example: h.putheader('Accept', 'text/html')
[1214] Fix | Delete
"""
[1215] Fix | Delete
if self.__state != _CS_REQ_STARTED:
[1216] Fix | Delete
raise CannotSendHeader()
[1217] Fix | Delete
[1218] Fix | Delete
if hasattr(header, 'encode'):
[1219] Fix | Delete
header = header.encode('ascii')
[1220] Fix | Delete
[1221] Fix | Delete
if not _is_legal_header_name(header):
[1222] Fix | Delete
raise ValueError('Invalid header name %r' % (header,))
[1223] Fix | Delete
[1224] Fix | Delete
values = list(values)
[1225] Fix | Delete
for i, one_value in enumerate(values):
[1226] Fix | Delete
if hasattr(one_value, 'encode'):
[1227] Fix | Delete
values[i] = one_value.encode('latin-1')
[1228] Fix | Delete
elif isinstance(one_value, int):
[1229] Fix | Delete
values[i] = str(one_value).encode('ascii')
[1230] Fix | Delete
[1231] Fix | Delete
if _is_illegal_header_value(values[i]):
[1232] Fix | Delete
raise ValueError('Invalid header value %r' % (values[i],))
[1233] Fix | Delete
[1234] Fix | Delete
value = b'\r\n\t'.join(values)
[1235] Fix | Delete
header = header + b': ' + value
[1236] Fix | Delete
self._output(header)
[1237] Fix | Delete
[1238] Fix | Delete
def endheaders(self, message_body=None, *, encode_chunked=False):
[1239] Fix | Delete
"""Indicate that the last header line has been sent to the server.
[1240] Fix | Delete
[1241] Fix | Delete
This method sends the request to the server. The optional message_body
[1242] Fix | Delete
argument can be used to pass a message body associated with the
[1243] Fix | Delete
request.
[1244] Fix | Delete
"""
[1245] Fix | Delete
if self.__state == _CS_REQ_STARTED:
[1246] Fix | Delete
self.__state = _CS_REQ_SENT
[1247] Fix | Delete
else:
[1248] Fix | Delete
raise CannotSendHeader()
[1249] Fix | Delete
self._send_output(message_body, encode_chunked=encode_chunked)
[1250] Fix | Delete
[1251] Fix | Delete
def request(self, method, url, body=None, headers={}, *,
[1252] Fix | Delete
encode_chunked=False):
[1253] Fix | Delete
"""Send a complete request to the server."""
[1254] Fix | Delete
self._send_request(method, url, body, headers, encode_chunked)
[1255] Fix | Delete
[1256] Fix | Delete
def _send_request(self, method, url, body, headers, encode_chunked):
[1257] Fix | Delete
# Honor explicitly requested Host: and Accept-Encoding: headers.
[1258] Fix | Delete
header_names = frozenset(k.lower() for k in headers)
[1259] Fix | Delete
skips = {}
[1260] Fix | Delete
if 'host' in header_names:
[1261] Fix | Delete
skips['skip_host'] = 1
[1262] Fix | Delete
if 'accept-encoding' in header_names:
[1263] Fix | Delete
skips['skip_accept_encoding'] = 1
[1264] Fix | Delete
[1265] Fix | Delete
self.putrequest(method, url, **skips)
[1266] Fix | Delete
[1267] Fix | Delete
# chunked encoding will happen if HTTP/1.1 is used and either
[1268] Fix | Delete
# the caller passes encode_chunked=True or the following
[1269] Fix | Delete
# conditions hold:
[1270] Fix | Delete
# 1. content-length has not been explicitly set
[1271] Fix | Delete
# 2. the body is a file or iterable, but not a str or bytes-like
[1272] Fix | Delete
# 3. Transfer-Encoding has NOT been explicitly set by the caller
[1273] Fix | Delete
[1274] Fix | Delete
if 'content-length' not in header_names:
[1275] Fix | Delete
# only chunk body if not explicitly set for backwards
[1276] Fix | Delete
# compatibility, assuming the client code is already handling the
[1277] Fix | Delete
# chunking
[1278] Fix | Delete
if 'transfer-encoding' not in header_names:
[1279] Fix | Delete
# if content-length cannot be automatically determined, fall
[1280] Fix | Delete
# back to chunked encoding
[1281] Fix | Delete
encode_chunked = False
[1282] Fix | Delete
content_length = self._get_content_length(body, method)
[1283] Fix | Delete
if content_length is None:
[1284] Fix | Delete
if body is not None:
[1285] Fix | Delete
if self.debuglevel > 0:
[1286] Fix | Delete
print('Unable to determine size of %r' % body)
[1287] Fix | Delete
encode_chunked = True
[1288] Fix | Delete
self.putheader('Transfer-Encoding', 'chunked')
[1289] Fix | Delete
else:
[1290] Fix | Delete
self.putheader('Content-Length', str(content_length))
[1291] Fix | Delete
else:
[1292] Fix | Delete
encode_chunked = False
[1293] Fix | Delete
[1294] Fix | Delete
for hdr, value in headers.items():
[1295] Fix | Delete
self.putheader(hdr, value)
[1296] Fix | Delete
if isinstance(body, str):
[1297] Fix | Delete
# RFC 2616 Section 3.7.1 says that text default has a
[1298] Fix | Delete
# default charset of iso-8859-1.
[1299] Fix | Delete
body = _encode(body, 'body')
[1300] Fix | Delete
self.endheaders(body, encode_chunked=encode_chunked)
[1301] Fix | Delete
[1302] Fix | Delete
def getresponse(self):
[1303] Fix | Delete
"""Get the response from the server.
[1304] Fix | Delete
[1305] Fix | Delete
If the HTTPConnection is in the correct state, returns an
[1306] Fix | Delete
instance of HTTPResponse or of whatever object is returned by
[1307] Fix | Delete
the response_class variable.
[1308] Fix | Delete
[1309] Fix | Delete
If a request has not been sent or if a previous response has
[1310] Fix | Delete
not be handled, ResponseNotReady is raised. If the HTTP
[1311] Fix | Delete
response indicates that the connection should be closed, then
[1312] Fix | Delete
it will be closed before the response is returned. When the
[1313] Fix | Delete
connection is closed, the underlying socket is closed.
[1314] Fix | Delete
"""
[1315] Fix | Delete
[1316] Fix | Delete
# if a prior response has been completed, then forget about it.
[1317] Fix | Delete
if self.__response and self.__response.isclosed():
[1318] Fix | Delete
self.__response = None
[1319] Fix | Delete
[1320] Fix | Delete
# if a prior response exists, then it must be completed (otherwise, we
[1321] Fix | Delete
# cannot read this response's header to determine the connection-close
[1322] Fix | Delete
# behavior)
[1323] Fix | Delete
#
[1324] Fix | Delete
# note: if a prior response existed, but was connection-close, then the
[1325] Fix | Delete
# socket and response were made independent of this HTTPConnection
[1326] Fix | Delete
# object since a new request requires that we open a whole new
[1327] Fix | Delete
# connection
[1328] Fix | Delete
#
[1329] Fix | Delete
# this means the prior response had one of two states:
[1330] Fix | Delete
# 1) will_close: this connection was reset and the prior socket and
[1331] Fix | Delete
# response operate independently
[1332] Fix | Delete
# 2) persistent: the response was retained and we await its
[1333] Fix | Delete
# isclosed() status to become true.
[1334] Fix | Delete
#
[1335] Fix | Delete
if self.__state != _CS_REQ_SENT or self.__response:
[1336] Fix | Delete
raise ResponseNotReady(self.__state)
[1337] Fix | Delete
[1338] Fix | Delete
if self.debuglevel > 0:
[1339] Fix | Delete
response = self.response_class(self.sock, self.debuglevel,
[1340] Fix | Delete
method=self._method)
[1341] Fix | Delete
else:
[1342] Fix | Delete
response = self.response_class(self.sock, method=self._method)
[1343] Fix | Delete
[1344] Fix | Delete
try:
[1345] Fix | Delete
try:
[1346] Fix | Delete
response.begin()
[1347] Fix | Delete
except ConnectionError:
[1348] Fix | Delete
self.close()
[1349] Fix | Delete
raise
[1350] Fix | Delete
assert response.will_close != _UNKNOWN
[1351] Fix | Delete
self.__state = _CS_IDLE
[1352] Fix | Delete
[1353] Fix | Delete
if response.will_close:
[1354] Fix | Delete
# this effectively passes the connection to the response
[1355] Fix | Delete
self.close()
[1356] Fix | Delete
else:
[1357] Fix | Delete
# remember this, so we can tell when it is complete
[1358] Fix | Delete
self.__response = response
[1359] Fix | Delete
[1360] Fix | Delete
return response
[1361] Fix | Delete
except:
[1362] Fix | Delete
response.close()
[1363] Fix | Delete
raise
[1364] Fix | Delete
[1365] Fix | Delete
try:
[1366] Fix | Delete
import ssl
[1367] Fix | Delete
except ImportError:
[1368] Fix | Delete
pass
[1369] Fix | Delete
else:
[1370] Fix | Delete
class HTTPSConnection(HTTPConnection):
[1371] Fix | Delete
"This class allows communication via SSL."
[1372] Fix | Delete
[1373] Fix | Delete
default_port = HTTPS_PORT
[1374] Fix | Delete
[1375] Fix | Delete
# XXX Should key_file and cert_file be deprecated in favour of context?
[1376] Fix | Delete
[1377] Fix | Delete
def __init__(self, host, port=None, key_file=None, cert_file=None,
[1378] Fix | Delete
timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
[1379] Fix | Delete
source_address=None, *, context=None,
[1380] Fix | Delete
check_hostname=None, blocksize=8192):
[1381] Fix | Delete
super(HTTPSConnection, self).__init__(host, port, timeout,
[1382] Fix | Delete
source_address,
[1383] Fix | Delete
blocksize=blocksize)
[1384] Fix | Delete
if (key_file is not None or cert_file is not None or
[1385] Fix | Delete
check_hostname is not None):
[1386] Fix | Delete
import warnings
[1387] Fix | Delete
warnings.warn("key_file, cert_file and check_hostname are "
[1388] Fix | Delete
"deprecated, use a custom context instead.",
[1389] Fix | Delete
DeprecationWarning, 2)
[1390] Fix | Delete
self.key_file = key_file
[1391] Fix | Delete
self.cert_file = cert_file
[1392] Fix | Delete
if context is None:
[1393] Fix | Delete
context = ssl._create_default_https_context()
[1394] Fix | Delete
# enable PHA for TLS 1.3 connections if available
[1395] Fix | Delete
if context.post_handshake_auth is not None:
[1396] Fix | Delete
context.post_handshake_auth = True
[1397] Fix | Delete
will_verify = context.verify_mode != ssl.CERT_NONE
[1398] Fix | Delete
if check_hostname is None:
[1399] Fix | Delete
check_hostname = context.check_hostname
[1400] Fix | Delete
if check_hostname and not will_verify:
[1401] Fix | Delete
raise ValueError("check_hostname needs a SSL context with "
[1402] Fix | Delete
"either CERT_OPTIONAL or CERT_REQUIRED")
[1403] Fix | Delete
if key_file or cert_file:
[1404] Fix | Delete
context.load_cert_chain(cert_file, key_file)
[1405] Fix | Delete
# cert and key file means the user wants to authenticate.
[1406] Fix | Delete
# enable TLS 1.3 PHA implicitly even for custom contexts.
[1407] Fix | Delete
if context.post_handshake_auth is not None:
[1408] Fix | Delete
context.post_handshake_auth = True
[1409] Fix | Delete
self._context = context
[1410] Fix | Delete
if check_hostname is not None:
[1411] Fix | Delete
self._context.check_hostname = check_hostname
[1412] Fix | Delete
[1413] Fix | Delete
def connect(self):
[1414] Fix | Delete
"Connect to a host on a given (SSL) port."
[1415] Fix | Delete
[1416] Fix | Delete
super().connect()
[1417] Fix | Delete
[1418] Fix | Delete
if self._tunnel_host:
[1419] Fix | Delete
server_hostname = self._tunnel_host
[1420] Fix | Delete
else:
[1421] Fix | Delete
server_hostname = self.host
[1422] Fix | Delete
[1423] Fix | Delete
self.sock = self._context.wrap_socket(self.sock,
[1424] Fix | Delete
server_hostname=server_hostname)
[1425] Fix | Delete
[1426] Fix | Delete
__all__.append("HTTPSConnection")
[1427] Fix | Delete
[1428] Fix | Delete
class HTTPException(Exception):
[1429] Fix | Delete
# Subclasses that define an __init__ must call Exception.__init__
[1430] Fix | Delete
# or define self.args. Otherwise, str() will fail.
[1431] Fix | Delete
pass
[1432] Fix | Delete
[1433] Fix | Delete
class NotConnected(HTTPException):
[1434] Fix | Delete
pass
[1435] Fix | Delete
[1436] Fix | Delete
class InvalidURL(HTTPException):
[1437] Fix | Delete
pass
[1438] Fix | Delete
[1439] Fix | Delete
class UnknownProtocol(HTTPException):
[1440] Fix | Delete
def __init__(self, version):
[1441] Fix | Delete
self.args = version,
[1442] Fix | Delete
self.version = version
[1443] Fix | Delete
[1444] Fix | Delete
class UnknownTransferEncoding(HTTPException):
[1445] Fix | Delete
pass
[1446] Fix | Delete
[1447] Fix | Delete
class UnimplementedFileMode(HTTPException):
[1448] Fix | Delete
pass
[1449] Fix | Delete
[1450] Fix | Delete
class IncompleteRead(HTTPException):
[1451] Fix | Delete
def __init__(self, partial, expected=None):
[1452] Fix | Delete
self.args = partial,
[1453] Fix | Delete
self.partial = partial
[1454] Fix | Delete
self.expected = expected
[1455] Fix | Delete
def __repr__(self):
[1456] Fix | Delete
if self.expected is not None:
[1457] Fix | Delete
e = ', %i more expected' % self.expected
[1458] Fix | Delete
else:
[1459] Fix | Delete
e = ''
[1460] Fix | Delete
return '%s(%i bytes read%s)' % (self.__class__.__name__,
[1461] Fix | Delete
len(self.partial), e)
[1462] Fix | Delete
__str__ = object.__str__
[1463] Fix | Delete
[1464] Fix | Delete
class ImproperConnectionState(HTTPException):
[1465] Fix | Delete
pass
[1466] Fix | Delete
[1467] Fix | Delete
class CannotSendRequest(ImproperConnectionState):
[1468] Fix | Delete
pass
[1469] Fix | Delete
[1470] Fix | Delete
class CannotSendHeader(ImproperConnectionState):
[1471] Fix | Delete
pass
[1472] Fix | Delete
[1473] Fix | Delete
class ResponseNotReady(ImproperConnectionState):
[1474] Fix | Delete
pass
[1475] Fix | Delete
[1476] Fix | Delete
class BadStatusLine(HTTPException):
[1477] Fix | Delete
def __init__(self, line):
[1478] Fix | Delete
if not line:
[1479] Fix | Delete
line = repr(line)
[1480] Fix | Delete
self.args = line,
[1481] Fix | Delete
self.line = line
[1482] Fix | Delete
[1483] Fix | Delete
class LineTooLong(HTTPException):
[1484] Fix | Delete
def __init__(self, line_type):
[1485] Fix | Delete
HTTPException.__init__(self, "got more than %d bytes when reading %s"
[1486] Fix | Delete
% (_MAXLINE, line_type))
[1487] Fix | Delete
[1488] Fix | Delete
class RemoteDisconnected(ConnectionResetError, BadStatusLine):
[1489] Fix | Delete
def __init__(self, *pos, **kw):
[1490] Fix | Delete
BadStatusLine.__init__(self, "")
[1491] Fix | Delete
ConnectionResetError.__init__(self, *pos, **kw)
[1492] Fix | Delete
[1493] Fix | Delete
# for backwards compatibility
[1494] Fix | Delete
error = HTTPException
[1495] Fix | Delete
[1496] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function