Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../http
File: client.py
# connection, and the user is reading more bytes than will be provided
[500] Fix | Delete
# (for example, reading in 1k chunks)
[501] Fix | Delete
n = self.fp.readinto(b)
[502] Fix | Delete
if not n and b:
[503] Fix | Delete
# Ideally, we would raise IncompleteRead if the content-length
[504] Fix | Delete
# wasn't satisfied, but it might break compatibility.
[505] Fix | Delete
self._close_conn()
[506] Fix | Delete
elif self.length is not None:
[507] Fix | Delete
self.length -= n
[508] Fix | Delete
if not self.length:
[509] Fix | Delete
self._close_conn()
[510] Fix | Delete
return n
[511] Fix | Delete
[512] Fix | Delete
def _read_next_chunk_size(self):
[513] Fix | Delete
# Read the next chunk size from the file
[514] Fix | Delete
line = self.fp.readline(_MAXLINE + 1)
[515] Fix | Delete
if len(line) > _MAXLINE:
[516] Fix | Delete
raise LineTooLong("chunk size")
[517] Fix | Delete
i = line.find(b";")
[518] Fix | Delete
if i >= 0:
[519] Fix | Delete
line = line[:i] # strip chunk-extensions
[520] Fix | Delete
try:
[521] Fix | Delete
return int(line, 16)
[522] Fix | Delete
except ValueError:
[523] Fix | Delete
# close the connection as protocol synchronisation is
[524] Fix | Delete
# probably lost
[525] Fix | Delete
self._close_conn()
[526] Fix | Delete
raise
[527] Fix | Delete
[528] Fix | Delete
def _read_and_discard_trailer(self):
[529] Fix | Delete
# read and discard trailer up to the CRLF terminator
[530] Fix | Delete
### note: we shouldn't have any trailers!
[531] Fix | Delete
while True:
[532] Fix | Delete
line = self.fp.readline(_MAXLINE + 1)
[533] Fix | Delete
if len(line) > _MAXLINE:
[534] Fix | Delete
raise LineTooLong("trailer line")
[535] Fix | Delete
if not line:
[536] Fix | Delete
# a vanishingly small number of sites EOF without
[537] Fix | Delete
# sending the trailer
[538] Fix | Delete
break
[539] Fix | Delete
if line in (b'\r\n', b'\n', b''):
[540] Fix | Delete
break
[541] Fix | Delete
[542] Fix | Delete
def _get_chunk_left(self):
[543] Fix | Delete
# return self.chunk_left, reading a new chunk if necessary.
[544] Fix | Delete
# chunk_left == 0: at the end of the current chunk, need to close it
[545] Fix | Delete
# chunk_left == None: No current chunk, should read next.
[546] Fix | Delete
# This function returns non-zero or None if the last chunk has
[547] Fix | Delete
# been read.
[548] Fix | Delete
chunk_left = self.chunk_left
[549] Fix | Delete
if not chunk_left: # Can be 0 or None
[550] Fix | Delete
if chunk_left is not None:
[551] Fix | Delete
# We are at the end of chunk, discard chunk end
[552] Fix | Delete
self._safe_read(2) # toss the CRLF at the end of the chunk
[553] Fix | Delete
try:
[554] Fix | Delete
chunk_left = self._read_next_chunk_size()
[555] Fix | Delete
except ValueError:
[556] Fix | Delete
raise IncompleteRead(b'')
[557] Fix | Delete
if chunk_left == 0:
[558] Fix | Delete
# last chunk: 1*("0") [ chunk-extension ] CRLF
[559] Fix | Delete
self._read_and_discard_trailer()
[560] Fix | Delete
# we read everything; close the "file"
[561] Fix | Delete
self._close_conn()
[562] Fix | Delete
chunk_left = None
[563] Fix | Delete
self.chunk_left = chunk_left
[564] Fix | Delete
return chunk_left
[565] Fix | Delete
[566] Fix | Delete
def _readall_chunked(self):
[567] Fix | Delete
assert self.chunked != _UNKNOWN
[568] Fix | Delete
value = []
[569] Fix | Delete
try:
[570] Fix | Delete
while True:
[571] Fix | Delete
chunk_left = self._get_chunk_left()
[572] Fix | Delete
if chunk_left is None:
[573] Fix | Delete
break
[574] Fix | Delete
value.append(self._safe_read(chunk_left))
[575] Fix | Delete
self.chunk_left = 0
[576] Fix | Delete
return b''.join(value)
[577] Fix | Delete
except IncompleteRead:
[578] Fix | Delete
raise IncompleteRead(b''.join(value))
[579] Fix | Delete
[580] Fix | Delete
def _readinto_chunked(self, b):
[581] Fix | Delete
assert self.chunked != _UNKNOWN
[582] Fix | Delete
total_bytes = 0
[583] Fix | Delete
mvb = memoryview(b)
[584] Fix | Delete
try:
[585] Fix | Delete
while True:
[586] Fix | Delete
chunk_left = self._get_chunk_left()
[587] Fix | Delete
if chunk_left is None:
[588] Fix | Delete
return total_bytes
[589] Fix | Delete
[590] Fix | Delete
if len(mvb) <= chunk_left:
[591] Fix | Delete
n = self._safe_readinto(mvb)
[592] Fix | Delete
self.chunk_left = chunk_left - n
[593] Fix | Delete
return total_bytes + n
[594] Fix | Delete
[595] Fix | Delete
temp_mvb = mvb[:chunk_left]
[596] Fix | Delete
n = self._safe_readinto(temp_mvb)
[597] Fix | Delete
mvb = mvb[n:]
[598] Fix | Delete
total_bytes += n
[599] Fix | Delete
self.chunk_left = 0
[600] Fix | Delete
[601] Fix | Delete
except IncompleteRead:
[602] Fix | Delete
raise IncompleteRead(bytes(b[0:total_bytes]))
[603] Fix | Delete
[604] Fix | Delete
def _safe_read(self, amt):
[605] Fix | Delete
"""Read the number of bytes requested.
[606] Fix | Delete
[607] Fix | Delete
This function should be used when <amt> bytes "should" be present for
[608] Fix | Delete
reading. If the bytes are truly not available (due to EOF), then the
[609] Fix | Delete
IncompleteRead exception can be used to detect the problem.
[610] Fix | Delete
"""
[611] Fix | Delete
data = self.fp.read(amt)
[612] Fix | Delete
if len(data) < amt:
[613] Fix | Delete
raise IncompleteRead(data, amt-len(data))
[614] Fix | Delete
return data
[615] Fix | Delete
[616] Fix | Delete
def _safe_readinto(self, b):
[617] Fix | Delete
"""Same as _safe_read, but for reading into a buffer."""
[618] Fix | Delete
amt = len(b)
[619] Fix | Delete
n = self.fp.readinto(b)
[620] Fix | Delete
if n < amt:
[621] Fix | Delete
raise IncompleteRead(bytes(b[:n]), amt-n)
[622] Fix | Delete
return n
[623] Fix | Delete
[624] Fix | Delete
def read1(self, n=-1):
[625] Fix | Delete
"""Read with at most one underlying system call. If at least one
[626] Fix | Delete
byte is buffered, return that instead.
[627] Fix | Delete
"""
[628] Fix | Delete
if self.fp is None or self._method == "HEAD":
[629] Fix | Delete
return b""
[630] Fix | Delete
if self.chunked:
[631] Fix | Delete
return self._read1_chunked(n)
[632] Fix | Delete
if self.length is not None and (n < 0 or n > self.length):
[633] Fix | Delete
n = self.length
[634] Fix | Delete
result = self.fp.read1(n)
[635] Fix | Delete
if not result and n:
[636] Fix | Delete
self._close_conn()
[637] Fix | Delete
elif self.length is not None:
[638] Fix | Delete
self.length -= len(result)
[639] Fix | Delete
return result
[640] Fix | Delete
[641] Fix | Delete
def peek(self, n=-1):
[642] Fix | Delete
# Having this enables IOBase.readline() to read more than one
[643] Fix | Delete
# byte at a time
[644] Fix | Delete
if self.fp is None or self._method == "HEAD":
[645] Fix | Delete
return b""
[646] Fix | Delete
if self.chunked:
[647] Fix | Delete
return self._peek_chunked(n)
[648] Fix | Delete
return self.fp.peek(n)
[649] Fix | Delete
[650] Fix | Delete
def readline(self, limit=-1):
[651] Fix | Delete
if self.fp is None or self._method == "HEAD":
[652] Fix | Delete
return b""
[653] Fix | Delete
if self.chunked:
[654] Fix | Delete
# Fallback to IOBase readline which uses peek() and read()
[655] Fix | Delete
return super().readline(limit)
[656] Fix | Delete
if self.length is not None and (limit < 0 or limit > self.length):
[657] Fix | Delete
limit = self.length
[658] Fix | Delete
result = self.fp.readline(limit)
[659] Fix | Delete
if not result and limit:
[660] Fix | Delete
self._close_conn()
[661] Fix | Delete
elif self.length is not None:
[662] Fix | Delete
self.length -= len(result)
[663] Fix | Delete
return result
[664] Fix | Delete
[665] Fix | Delete
def _read1_chunked(self, n):
[666] Fix | Delete
# Strictly speaking, _get_chunk_left() may cause more than one read,
[667] Fix | Delete
# but that is ok, since that is to satisfy the chunked protocol.
[668] Fix | Delete
chunk_left = self._get_chunk_left()
[669] Fix | Delete
if chunk_left is None or n == 0:
[670] Fix | Delete
return b''
[671] Fix | Delete
if not (0 <= n <= chunk_left):
[672] Fix | Delete
n = chunk_left # if n is negative or larger than chunk_left
[673] Fix | Delete
read = self.fp.read1(n)
[674] Fix | Delete
self.chunk_left -= len(read)
[675] Fix | Delete
if not read:
[676] Fix | Delete
raise IncompleteRead(b"")
[677] Fix | Delete
return read
[678] Fix | Delete
[679] Fix | Delete
def _peek_chunked(self, n):
[680] Fix | Delete
# Strictly speaking, _get_chunk_left() may cause more than one read,
[681] Fix | Delete
# but that is ok, since that is to satisfy the chunked protocol.
[682] Fix | Delete
try:
[683] Fix | Delete
chunk_left = self._get_chunk_left()
[684] Fix | Delete
except IncompleteRead:
[685] Fix | Delete
return b'' # peek doesn't worry about protocol
[686] Fix | Delete
if chunk_left is None:
[687] Fix | Delete
return b'' # eof
[688] Fix | Delete
# peek is allowed to return more than requested. Just request the
[689] Fix | Delete
# entire chunk, and truncate what we get.
[690] Fix | Delete
return self.fp.peek(chunk_left)[:chunk_left]
[691] Fix | Delete
[692] Fix | Delete
def fileno(self):
[693] Fix | Delete
return self.fp.fileno()
[694] Fix | Delete
[695] Fix | Delete
def getheader(self, name, default=None):
[696] Fix | Delete
'''Returns the value of the header matching *name*.
[697] Fix | Delete
[698] Fix | Delete
If there are multiple matching headers, the values are
[699] Fix | Delete
combined into a single string separated by commas and spaces.
[700] Fix | Delete
[701] Fix | Delete
If no matching header is found, returns *default* or None if
[702] Fix | Delete
the *default* is not specified.
[703] Fix | Delete
[704] Fix | Delete
If the headers are unknown, raises http.client.ResponseNotReady.
[705] Fix | Delete
[706] Fix | Delete
'''
[707] Fix | Delete
if self.headers is None:
[708] Fix | Delete
raise ResponseNotReady()
[709] Fix | Delete
headers = self.headers.get_all(name) or default
[710] Fix | Delete
if isinstance(headers, str) or not hasattr(headers, '__iter__'):
[711] Fix | Delete
return headers
[712] Fix | Delete
else:
[713] Fix | Delete
return ', '.join(headers)
[714] Fix | Delete
[715] Fix | Delete
def getheaders(self):
[716] Fix | Delete
"""Return list of (header, value) tuples."""
[717] Fix | Delete
if self.headers is None:
[718] Fix | Delete
raise ResponseNotReady()
[719] Fix | Delete
return list(self.headers.items())
[720] Fix | Delete
[721] Fix | Delete
# We override IOBase.__iter__ so that it doesn't check for closed-ness
[722] Fix | Delete
[723] Fix | Delete
def __iter__(self):
[724] Fix | Delete
return self
[725] Fix | Delete
[726] Fix | Delete
# For compatibility with old-style urllib responses.
[727] Fix | Delete
[728] Fix | Delete
def info(self):
[729] Fix | Delete
'''Returns an instance of the class mimetools.Message containing
[730] Fix | Delete
meta-information associated with the URL.
[731] Fix | Delete
[732] Fix | Delete
When the method is HTTP, these headers are those returned by
[733] Fix | Delete
the server at the head of the retrieved HTML page (including
[734] Fix | Delete
Content-Length and Content-Type).
[735] Fix | Delete
[736] Fix | Delete
When the method is FTP, a Content-Length header will be
[737] Fix | Delete
present if (as is now usual) the server passed back a file
[738] Fix | Delete
length in response to the FTP retrieval request. A
[739] Fix | Delete
Content-Type header will be present if the MIME type can be
[740] Fix | Delete
guessed.
[741] Fix | Delete
[742] Fix | Delete
When the method is local-file, returned headers will include
[743] Fix | Delete
a Date representing the file's last-modified time, a
[744] Fix | Delete
Content-Length giving file size, and a Content-Type
[745] Fix | Delete
containing a guess at the file's type. See also the
[746] Fix | Delete
description of the mimetools module.
[747] Fix | Delete
[748] Fix | Delete
'''
[749] Fix | Delete
return self.headers
[750] Fix | Delete
[751] Fix | Delete
def geturl(self):
[752] Fix | Delete
'''Return the real URL of the page.
[753] Fix | Delete
[754] Fix | Delete
In some cases, the HTTP server redirects a client to another
[755] Fix | Delete
URL. The urlopen() function handles this transparently, but in
[756] Fix | Delete
some cases the caller needs to know which URL the client was
[757] Fix | Delete
redirected to. The geturl() method can be used to get at this
[758] Fix | Delete
redirected URL.
[759] Fix | Delete
[760] Fix | Delete
'''
[761] Fix | Delete
return self.url
[762] Fix | Delete
[763] Fix | Delete
def getcode(self):
[764] Fix | Delete
'''Return the HTTP status code that was sent with the response,
[765] Fix | Delete
or None if the URL is not an HTTP URL.
[766] Fix | Delete
[767] Fix | Delete
'''
[768] Fix | Delete
return self.status
[769] Fix | Delete
[770] Fix | Delete
class HTTPConnection:
[771] Fix | Delete
[772] Fix | Delete
_http_vsn = 11
[773] Fix | Delete
_http_vsn_str = 'HTTP/1.1'
[774] Fix | Delete
[775] Fix | Delete
response_class = HTTPResponse
[776] Fix | Delete
default_port = HTTP_PORT
[777] Fix | Delete
auto_open = 1
[778] Fix | Delete
debuglevel = 0
[779] Fix | Delete
[780] Fix | Delete
@staticmethod
[781] Fix | Delete
def _is_textIO(stream):
[782] Fix | Delete
"""Test whether a file-like object is a text or a binary stream.
[783] Fix | Delete
"""
[784] Fix | Delete
return isinstance(stream, io.TextIOBase)
[785] Fix | Delete
[786] Fix | Delete
@staticmethod
[787] Fix | Delete
def _get_content_length(body, method):
[788] Fix | Delete
"""Get the content-length based on the body.
[789] Fix | Delete
[790] Fix | Delete
If the body is None, we set Content-Length: 0 for methods that expect
[791] Fix | Delete
a body (RFC 7230, Section 3.3.2). We also set the Content-Length for
[792] Fix | Delete
any method if the body is a str or bytes-like object and not a file.
[793] Fix | Delete
"""
[794] Fix | Delete
if body is None:
[795] Fix | Delete
# do an explicit check for not None here to distinguish
[796] Fix | Delete
# between unset and set but empty
[797] Fix | Delete
if method.upper() in _METHODS_EXPECTING_BODY:
[798] Fix | Delete
return 0
[799] Fix | Delete
else:
[800] Fix | Delete
return None
[801] Fix | Delete
[802] Fix | Delete
if hasattr(body, 'read'):
[803] Fix | Delete
# file-like object.
[804] Fix | Delete
return None
[805] Fix | Delete
[806] Fix | Delete
try:
[807] Fix | Delete
# does it implement the buffer protocol (bytes, bytearray, array)?
[808] Fix | Delete
mv = memoryview(body)
[809] Fix | Delete
return mv.nbytes
[810] Fix | Delete
except TypeError:
[811] Fix | Delete
pass
[812] Fix | Delete
[813] Fix | Delete
if isinstance(body, str):
[814] Fix | Delete
return len(body)
[815] Fix | Delete
[816] Fix | Delete
return None
[817] Fix | Delete
[818] Fix | Delete
def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
[819] Fix | Delete
source_address=None, blocksize=8192):
[820] Fix | Delete
self.timeout = timeout
[821] Fix | Delete
self.source_address = source_address
[822] Fix | Delete
self.blocksize = blocksize
[823] Fix | Delete
self.sock = None
[824] Fix | Delete
self._buffer = []
[825] Fix | Delete
self.__response = None
[826] Fix | Delete
self.__state = _CS_IDLE
[827] Fix | Delete
self._method = None
[828] Fix | Delete
self._tunnel_host = None
[829] Fix | Delete
self._tunnel_port = None
[830] Fix | Delete
self._tunnel_headers = {}
[831] Fix | Delete
[832] Fix | Delete
(self.host, self.port) = self._get_hostport(host, port)
[833] Fix | Delete
[834] Fix | Delete
self._validate_host(self.host)
[835] Fix | Delete
[836] Fix | Delete
# This is stored as an instance variable to allow unit
[837] Fix | Delete
# tests to replace it with a suitable mockup
[838] Fix | Delete
self._create_connection = socket.create_connection
[839] Fix | Delete
[840] Fix | Delete
def set_tunnel(self, host, port=None, headers=None):
[841] Fix | Delete
"""Set up host and port for HTTP CONNECT tunnelling.
[842] Fix | Delete
[843] Fix | Delete
In a connection that uses HTTP CONNECT tunneling, the host passed to the
[844] Fix | Delete
constructor is used as a proxy server that relays all communication to
[845] Fix | Delete
the endpoint passed to `set_tunnel`. This done by sending an HTTP
[846] Fix | Delete
CONNECT request to the proxy server when the connection is established.
[847] Fix | Delete
[848] Fix | Delete
This method must be called before the HTTP connection has been
[849] Fix | Delete
established.
[850] Fix | Delete
[851] Fix | Delete
The headers argument should be a mapping of extra HTTP headers to send
[852] Fix | Delete
with the CONNECT request.
[853] Fix | Delete
"""
[854] Fix | Delete
[855] Fix | Delete
if self.sock:
[856] Fix | Delete
raise RuntimeError("Can't set up tunnel for established connection")
[857] Fix | Delete
[858] Fix | Delete
self._tunnel_host, self._tunnel_port = self._get_hostport(host, port)
[859] Fix | Delete
if headers:
[860] Fix | Delete
self._tunnel_headers = headers
[861] Fix | Delete
else:
[862] Fix | Delete
self._tunnel_headers.clear()
[863] Fix | Delete
[864] Fix | Delete
def _get_hostport(self, host, port):
[865] Fix | Delete
if port is None:
[866] Fix | Delete
i = host.rfind(':')
[867] Fix | Delete
j = host.rfind(']') # ipv6 addresses have [...]
[868] Fix | Delete
if i > j:
[869] Fix | Delete
try:
[870] Fix | Delete
port = int(host[i+1:])
[871] Fix | Delete
except ValueError:
[872] Fix | Delete
if host[i+1:] == "": # http://foo.com:/ == http://foo.com/
[873] Fix | Delete
port = self.default_port
[874] Fix | Delete
else:
[875] Fix | Delete
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
[876] Fix | Delete
host = host[:i]
[877] Fix | Delete
else:
[878] Fix | Delete
port = self.default_port
[879] Fix | Delete
if host and host[0] == '[' and host[-1] == ']':
[880] Fix | Delete
host = host[1:-1]
[881] Fix | Delete
[882] Fix | Delete
return (host, port)
[883] Fix | Delete
[884] Fix | Delete
def set_debuglevel(self, level):
[885] Fix | Delete
self.debuglevel = level
[886] Fix | Delete
[887] Fix | Delete
def _tunnel(self):
[888] Fix | Delete
connect_str = "CONNECT %s:%d HTTP/1.0\r\n" % (self._tunnel_host,
[889] Fix | Delete
self._tunnel_port)
[890] Fix | Delete
connect_bytes = connect_str.encode("ascii")
[891] Fix | Delete
self.send(connect_bytes)
[892] Fix | Delete
for header, value in self._tunnel_headers.items():
[893] Fix | Delete
header_str = "%s: %s\r\n" % (header, value)
[894] Fix | Delete
header_bytes = header_str.encode("latin-1")
[895] Fix | Delete
self.send(header_bytes)
[896] Fix | Delete
self.send(b'\r\n')
[897] Fix | Delete
[898] Fix | Delete
response = self.response_class(self.sock, method=self._method)
[899] Fix | Delete
(version, code, message) = response._read_status()
[900] Fix | Delete
[901] Fix | Delete
if code != http.HTTPStatus.OK:
[902] Fix | Delete
self.close()
[903] Fix | Delete
raise OSError("Tunnel connection failed: %d %s" % (code,
[904] Fix | Delete
message.strip()))
[905] Fix | Delete
while True:
[906] Fix | Delete
line = response.fp.readline(_MAXLINE + 1)
[907] Fix | Delete
if len(line) > _MAXLINE:
[908] Fix | Delete
raise LineTooLong("header line")
[909] Fix | Delete
if not line:
[910] Fix | Delete
# for sites which EOF without sending a trailer
[911] Fix | Delete
break
[912] Fix | Delete
if line in (b'\r\n', b'\n', b''):
[913] Fix | Delete
break
[914] Fix | Delete
[915] Fix | Delete
if self.debuglevel > 0:
[916] Fix | Delete
print('header:', line.decode())
[917] Fix | Delete
[918] Fix | Delete
def connect(self):
[919] Fix | Delete
"""Connect to the host and port specified in __init__."""
[920] Fix | Delete
self.sock = self._create_connection(
[921] Fix | Delete
(self.host,self.port), self.timeout, self.source_address)
[922] Fix | Delete
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
[923] Fix | Delete
[924] Fix | Delete
if self._tunnel_host:
[925] Fix | Delete
self._tunnel()
[926] Fix | Delete
[927] Fix | Delete
def close(self):
[928] Fix | Delete
"""Close the connection to the HTTP server."""
[929] Fix | Delete
self.__state = _CS_IDLE
[930] Fix | Delete
try:
[931] Fix | Delete
sock = self.sock
[932] Fix | Delete
if sock:
[933] Fix | Delete
self.sock = None
[934] Fix | Delete
sock.close() # close it manually... there may be other refs
[935] Fix | Delete
finally:
[936] Fix | Delete
response = self.__response
[937] Fix | Delete
if response:
[938] Fix | Delete
self.__response = None
[939] Fix | Delete
response.close()
[940] Fix | Delete
[941] Fix | Delete
def send(self, data):
[942] Fix | Delete
"""Send `data' to the server.
[943] Fix | Delete
``data`` can be a string object, a bytes object, an array object, a
[944] Fix | Delete
file-like object that supports a .read() method, or an iterable object.
[945] Fix | Delete
"""
[946] Fix | Delete
[947] Fix | Delete
if self.sock is None:
[948] Fix | Delete
if self.auto_open:
[949] Fix | Delete
self.connect()
[950] Fix | Delete
else:
[951] Fix | Delete
raise NotConnected()
[952] Fix | Delete
[953] Fix | Delete
if self.debuglevel > 0:
[954] Fix | Delete
print("send:", repr(data))
[955] Fix | Delete
if hasattr(data, "read") :
[956] Fix | Delete
if self.debuglevel > 0:
[957] Fix | Delete
print("sendIng a read()able")
[958] Fix | Delete
encode = self._is_textIO(data)
[959] Fix | Delete
if encode and self.debuglevel > 0:
[960] Fix | Delete
print("encoding file using iso-8859-1")
[961] Fix | Delete
while 1:
[962] Fix | Delete
datablock = data.read(self.blocksize)
[963] Fix | Delete
if not datablock:
[964] Fix | Delete
break
[965] Fix | Delete
if encode:
[966] Fix | Delete
datablock = datablock.encode("iso-8859-1")
[967] Fix | Delete
self.sock.sendall(datablock)
[968] Fix | Delete
return
[969] Fix | Delete
try:
[970] Fix | Delete
self.sock.sendall(data)
[971] Fix | Delete
except TypeError:
[972] Fix | Delete
if isinstance(data, collections.abc.Iterable):
[973] Fix | Delete
for d in data:
[974] Fix | Delete
self.sock.sendall(d)
[975] Fix | Delete
else:
[976] Fix | Delete
raise TypeError("data should be a bytes-like object "
[977] Fix | Delete
"or an iterable, got %r" % type(data))
[978] Fix | Delete
[979] Fix | Delete
def _output(self, s):
[980] Fix | Delete
"""Add a line of output to the current request buffer.
[981] Fix | Delete
[982] Fix | Delete
Assumes that the line does *not* end with \\r\\n.
[983] Fix | Delete
"""
[984] Fix | Delete
self._buffer.append(s)
[985] Fix | Delete
[986] Fix | Delete
def _read_readable(self, readable):
[987] Fix | Delete
if self.debuglevel > 0:
[988] Fix | Delete
print("sendIng a read()able")
[989] Fix | Delete
encode = self._is_textIO(readable)
[990] Fix | Delete
if encode and self.debuglevel > 0:
[991] Fix | Delete
print("encoding file using iso-8859-1")
[992] Fix | Delete
while True:
[993] Fix | Delete
datablock = readable.read(self.blocksize)
[994] Fix | Delete
if not datablock:
[995] Fix | Delete
break
[996] Fix | Delete
if encode:
[997] Fix | Delete
datablock = datablock.encode("iso-8859-1")
[998] Fix | Delete
yield datablock
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function