Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: codecs.py
""" codecs -- Python Codec Registry, API and helpers.
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
Written by Marc-Andre Lemburg (mal@lemburg.com).
[3] Fix | Delete
[4] Fix | Delete
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
[5] Fix | Delete
[6] Fix | Delete
"""
[7] Fix | Delete
[8] Fix | Delete
import builtins
[9] Fix | Delete
import sys
[10] Fix | Delete
[11] Fix | Delete
### Registry and builtin stateless codec functions
[12] Fix | Delete
[13] Fix | Delete
try:
[14] Fix | Delete
from _codecs import *
[15] Fix | Delete
except ImportError as why:
[16] Fix | Delete
raise SystemError('Failed to load the builtin codecs: %s' % why)
[17] Fix | Delete
[18] Fix | Delete
__all__ = ["register", "lookup", "open", "EncodedFile", "BOM", "BOM_BE",
[19] Fix | Delete
"BOM_LE", "BOM32_BE", "BOM32_LE", "BOM64_BE", "BOM64_LE",
[20] Fix | Delete
"BOM_UTF8", "BOM_UTF16", "BOM_UTF16_LE", "BOM_UTF16_BE",
[21] Fix | Delete
"BOM_UTF32", "BOM_UTF32_LE", "BOM_UTF32_BE",
[22] Fix | Delete
"CodecInfo", "Codec", "IncrementalEncoder", "IncrementalDecoder",
[23] Fix | Delete
"StreamReader", "StreamWriter",
[24] Fix | Delete
"StreamReaderWriter", "StreamRecoder",
[25] Fix | Delete
"getencoder", "getdecoder", "getincrementalencoder",
[26] Fix | Delete
"getincrementaldecoder", "getreader", "getwriter",
[27] Fix | Delete
"encode", "decode", "iterencode", "iterdecode",
[28] Fix | Delete
"strict_errors", "ignore_errors", "replace_errors",
[29] Fix | Delete
"xmlcharrefreplace_errors",
[30] Fix | Delete
"backslashreplace_errors", "namereplace_errors",
[31] Fix | Delete
"register_error", "lookup_error"]
[32] Fix | Delete
[33] Fix | Delete
### Constants
[34] Fix | Delete
[35] Fix | Delete
#
[36] Fix | Delete
# Byte Order Mark (BOM = ZERO WIDTH NO-BREAK SPACE = U+FEFF)
[37] Fix | Delete
# and its possible byte string values
[38] Fix | Delete
# for UTF8/UTF16/UTF32 output and little/big endian machines
[39] Fix | Delete
#
[40] Fix | Delete
[41] Fix | Delete
# UTF-8
[42] Fix | Delete
BOM_UTF8 = b'\xef\xbb\xbf'
[43] Fix | Delete
[44] Fix | Delete
# UTF-16, little endian
[45] Fix | Delete
BOM_LE = BOM_UTF16_LE = b'\xff\xfe'
[46] Fix | Delete
[47] Fix | Delete
# UTF-16, big endian
[48] Fix | Delete
BOM_BE = BOM_UTF16_BE = b'\xfe\xff'
[49] Fix | Delete
[50] Fix | Delete
# UTF-32, little endian
[51] Fix | Delete
BOM_UTF32_LE = b'\xff\xfe\x00\x00'
[52] Fix | Delete
[53] Fix | Delete
# UTF-32, big endian
[54] Fix | Delete
BOM_UTF32_BE = b'\x00\x00\xfe\xff'
[55] Fix | Delete
[56] Fix | Delete
if sys.byteorder == 'little':
[57] Fix | Delete
[58] Fix | Delete
# UTF-16, native endianness
[59] Fix | Delete
BOM = BOM_UTF16 = BOM_UTF16_LE
[60] Fix | Delete
[61] Fix | Delete
# UTF-32, native endianness
[62] Fix | Delete
BOM_UTF32 = BOM_UTF32_LE
[63] Fix | Delete
[64] Fix | Delete
else:
[65] Fix | Delete
[66] Fix | Delete
# UTF-16, native endianness
[67] Fix | Delete
BOM = BOM_UTF16 = BOM_UTF16_BE
[68] Fix | Delete
[69] Fix | Delete
# UTF-32, native endianness
[70] Fix | Delete
BOM_UTF32 = BOM_UTF32_BE
[71] Fix | Delete
[72] Fix | Delete
# Old broken names (don't use in new code)
[73] Fix | Delete
BOM32_LE = BOM_UTF16_LE
[74] Fix | Delete
BOM32_BE = BOM_UTF16_BE
[75] Fix | Delete
BOM64_LE = BOM_UTF32_LE
[76] Fix | Delete
BOM64_BE = BOM_UTF32_BE
[77] Fix | Delete
[78] Fix | Delete
[79] Fix | Delete
### Codec base classes (defining the API)
[80] Fix | Delete
[81] Fix | Delete
class CodecInfo(tuple):
[82] Fix | Delete
"""Codec details when looking up the codec registry"""
[83] Fix | Delete
[84] Fix | Delete
# Private API to allow Python 3.4 to blacklist the known non-Unicode
[85] Fix | Delete
# codecs in the standard library. A more general mechanism to
[86] Fix | Delete
# reliably distinguish test encodings from other codecs will hopefully
[87] Fix | Delete
# be defined for Python 3.5
[88] Fix | Delete
#
[89] Fix | Delete
# See http://bugs.python.org/issue19619
[90] Fix | Delete
_is_text_encoding = True # Assume codecs are text encodings by default
[91] Fix | Delete
[92] Fix | Delete
def __new__(cls, encode, decode, streamreader=None, streamwriter=None,
[93] Fix | Delete
incrementalencoder=None, incrementaldecoder=None, name=None,
[94] Fix | Delete
*, _is_text_encoding=None):
[95] Fix | Delete
self = tuple.__new__(cls, (encode, decode, streamreader, streamwriter))
[96] Fix | Delete
self.name = name
[97] Fix | Delete
self.encode = encode
[98] Fix | Delete
self.decode = decode
[99] Fix | Delete
self.incrementalencoder = incrementalencoder
[100] Fix | Delete
self.incrementaldecoder = incrementaldecoder
[101] Fix | Delete
self.streamwriter = streamwriter
[102] Fix | Delete
self.streamreader = streamreader
[103] Fix | Delete
if _is_text_encoding is not None:
[104] Fix | Delete
self._is_text_encoding = _is_text_encoding
[105] Fix | Delete
return self
[106] Fix | Delete
[107] Fix | Delete
def __repr__(self):
[108] Fix | Delete
return "<%s.%s object for encoding %s at %#x>" % \
[109] Fix | Delete
(self.__class__.__module__, self.__class__.__qualname__,
[110] Fix | Delete
self.name, id(self))
[111] Fix | Delete
[112] Fix | Delete
class Codec:
[113] Fix | Delete
[114] Fix | Delete
""" Defines the interface for stateless encoders/decoders.
[115] Fix | Delete
[116] Fix | Delete
The .encode()/.decode() methods may use different error
[117] Fix | Delete
handling schemes by providing the errors argument. These
[118] Fix | Delete
string values are predefined:
[119] Fix | Delete
[120] Fix | Delete
'strict' - raise a ValueError error (or a subclass)
[121] Fix | Delete
'ignore' - ignore the character and continue with the next
[122] Fix | Delete
'replace' - replace with a suitable replacement character;
[123] Fix | Delete
Python will use the official U+FFFD REPLACEMENT
[124] Fix | Delete
CHARACTER for the builtin Unicode codecs on
[125] Fix | Delete
decoding and '?' on encoding.
[126] Fix | Delete
'surrogateescape' - replace with private code points U+DCnn.
[127] Fix | Delete
'xmlcharrefreplace' - Replace with the appropriate XML
[128] Fix | Delete
character reference (only for encoding).
[129] Fix | Delete
'backslashreplace' - Replace with backslashed escape sequences.
[130] Fix | Delete
'namereplace' - Replace with \\N{...} escape sequences
[131] Fix | Delete
(only for encoding).
[132] Fix | Delete
[133] Fix | Delete
The set of allowed values can be extended via register_error.
[134] Fix | Delete
[135] Fix | Delete
"""
[136] Fix | Delete
def encode(self, input, errors='strict'):
[137] Fix | Delete
[138] Fix | Delete
""" Encodes the object input and returns a tuple (output
[139] Fix | Delete
object, length consumed).
[140] Fix | Delete
[141] Fix | Delete
errors defines the error handling to apply. It defaults to
[142] Fix | Delete
'strict' handling.
[143] Fix | Delete
[144] Fix | Delete
The method may not store state in the Codec instance. Use
[145] Fix | Delete
StreamWriter for codecs which have to keep state in order to
[146] Fix | Delete
make encoding efficient.
[147] Fix | Delete
[148] Fix | Delete
The encoder must be able to handle zero length input and
[149] Fix | Delete
return an empty object of the output object type in this
[150] Fix | Delete
situation.
[151] Fix | Delete
[152] Fix | Delete
"""
[153] Fix | Delete
raise NotImplementedError
[154] Fix | Delete
[155] Fix | Delete
def decode(self, input, errors='strict'):
[156] Fix | Delete
[157] Fix | Delete
""" Decodes the object input and returns a tuple (output
[158] Fix | Delete
object, length consumed).
[159] Fix | Delete
[160] Fix | Delete
input must be an object which provides the bf_getreadbuf
[161] Fix | Delete
buffer slot. Python strings, buffer objects and memory
[162] Fix | Delete
mapped files are examples of objects providing this slot.
[163] Fix | Delete
[164] Fix | Delete
errors defines the error handling to apply. It defaults to
[165] Fix | Delete
'strict' handling.
[166] Fix | Delete
[167] Fix | Delete
The method may not store state in the Codec instance. Use
[168] Fix | Delete
StreamReader for codecs which have to keep state in order to
[169] Fix | Delete
make decoding efficient.
[170] Fix | Delete
[171] Fix | Delete
The decoder must be able to handle zero length input and
[172] Fix | Delete
return an empty object of the output object type in this
[173] Fix | Delete
situation.
[174] Fix | Delete
[175] Fix | Delete
"""
[176] Fix | Delete
raise NotImplementedError
[177] Fix | Delete
[178] Fix | Delete
class IncrementalEncoder(object):
[179] Fix | Delete
"""
[180] Fix | Delete
An IncrementalEncoder encodes an input in multiple steps. The input can
[181] Fix | Delete
be passed piece by piece to the encode() method. The IncrementalEncoder
[182] Fix | Delete
remembers the state of the encoding process between calls to encode().
[183] Fix | Delete
"""
[184] Fix | Delete
def __init__(self, errors='strict'):
[185] Fix | Delete
"""
[186] Fix | Delete
Creates an IncrementalEncoder instance.
[187] Fix | Delete
[188] Fix | Delete
The IncrementalEncoder may use different error handling schemes by
[189] Fix | Delete
providing the errors keyword argument. See the module docstring
[190] Fix | Delete
for a list of possible values.
[191] Fix | Delete
"""
[192] Fix | Delete
self.errors = errors
[193] Fix | Delete
self.buffer = ""
[194] Fix | Delete
[195] Fix | Delete
def encode(self, input, final=False):
[196] Fix | Delete
"""
[197] Fix | Delete
Encodes input and returns the resulting object.
[198] Fix | Delete
"""
[199] Fix | Delete
raise NotImplementedError
[200] Fix | Delete
[201] Fix | Delete
def reset(self):
[202] Fix | Delete
"""
[203] Fix | Delete
Resets the encoder to the initial state.
[204] Fix | Delete
"""
[205] Fix | Delete
[206] Fix | Delete
def getstate(self):
[207] Fix | Delete
"""
[208] Fix | Delete
Return the current state of the encoder.
[209] Fix | Delete
"""
[210] Fix | Delete
return 0
[211] Fix | Delete
[212] Fix | Delete
def setstate(self, state):
[213] Fix | Delete
"""
[214] Fix | Delete
Set the current state of the encoder. state must have been
[215] Fix | Delete
returned by getstate().
[216] Fix | Delete
"""
[217] Fix | Delete
[218] Fix | Delete
class BufferedIncrementalEncoder(IncrementalEncoder):
[219] Fix | Delete
"""
[220] Fix | Delete
This subclass of IncrementalEncoder can be used as the baseclass for an
[221] Fix | Delete
incremental encoder if the encoder must keep some of the output in a
[222] Fix | Delete
buffer between calls to encode().
[223] Fix | Delete
"""
[224] Fix | Delete
def __init__(self, errors='strict'):
[225] Fix | Delete
IncrementalEncoder.__init__(self, errors)
[226] Fix | Delete
# unencoded input that is kept between calls to encode()
[227] Fix | Delete
self.buffer = ""
[228] Fix | Delete
[229] Fix | Delete
def _buffer_encode(self, input, errors, final):
[230] Fix | Delete
# Overwrite this method in subclasses: It must encode input
[231] Fix | Delete
# and return an (output, length consumed) tuple
[232] Fix | Delete
raise NotImplementedError
[233] Fix | Delete
[234] Fix | Delete
def encode(self, input, final=False):
[235] Fix | Delete
# encode input (taking the buffer into account)
[236] Fix | Delete
data = self.buffer + input
[237] Fix | Delete
(result, consumed) = self._buffer_encode(data, self.errors, final)
[238] Fix | Delete
# keep unencoded input until the next call
[239] Fix | Delete
self.buffer = data[consumed:]
[240] Fix | Delete
return result
[241] Fix | Delete
[242] Fix | Delete
def reset(self):
[243] Fix | Delete
IncrementalEncoder.reset(self)
[244] Fix | Delete
self.buffer = ""
[245] Fix | Delete
[246] Fix | Delete
def getstate(self):
[247] Fix | Delete
return self.buffer or 0
[248] Fix | Delete
[249] Fix | Delete
def setstate(self, state):
[250] Fix | Delete
self.buffer = state or ""
[251] Fix | Delete
[252] Fix | Delete
class IncrementalDecoder(object):
[253] Fix | Delete
"""
[254] Fix | Delete
An IncrementalDecoder decodes an input in multiple steps. The input can
[255] Fix | Delete
be passed piece by piece to the decode() method. The IncrementalDecoder
[256] Fix | Delete
remembers the state of the decoding process between calls to decode().
[257] Fix | Delete
"""
[258] Fix | Delete
def __init__(self, errors='strict'):
[259] Fix | Delete
"""
[260] Fix | Delete
Create an IncrementalDecoder instance.
[261] Fix | Delete
[262] Fix | Delete
The IncrementalDecoder may use different error handling schemes by
[263] Fix | Delete
providing the errors keyword argument. See the module docstring
[264] Fix | Delete
for a list of possible values.
[265] Fix | Delete
"""
[266] Fix | Delete
self.errors = errors
[267] Fix | Delete
[268] Fix | Delete
def decode(self, input, final=False):
[269] Fix | Delete
"""
[270] Fix | Delete
Decode input and returns the resulting object.
[271] Fix | Delete
"""
[272] Fix | Delete
raise NotImplementedError
[273] Fix | Delete
[274] Fix | Delete
def reset(self):
[275] Fix | Delete
"""
[276] Fix | Delete
Reset the decoder to the initial state.
[277] Fix | Delete
"""
[278] Fix | Delete
[279] Fix | Delete
def getstate(self):
[280] Fix | Delete
"""
[281] Fix | Delete
Return the current state of the decoder.
[282] Fix | Delete
[283] Fix | Delete
This must be a (buffered_input, additional_state_info) tuple.
[284] Fix | Delete
buffered_input must be a bytes object containing bytes that
[285] Fix | Delete
were passed to decode() that have not yet been converted.
[286] Fix | Delete
additional_state_info must be a non-negative integer
[287] Fix | Delete
representing the state of the decoder WITHOUT yet having
[288] Fix | Delete
processed the contents of buffered_input. In the initial state
[289] Fix | Delete
and after reset(), getstate() must return (b"", 0).
[290] Fix | Delete
"""
[291] Fix | Delete
return (b"", 0)
[292] Fix | Delete
[293] Fix | Delete
def setstate(self, state):
[294] Fix | Delete
"""
[295] Fix | Delete
Set the current state of the decoder.
[296] Fix | Delete
[297] Fix | Delete
state must have been returned by getstate(). The effect of
[298] Fix | Delete
setstate((b"", 0)) must be equivalent to reset().
[299] Fix | Delete
"""
[300] Fix | Delete
[301] Fix | Delete
class BufferedIncrementalDecoder(IncrementalDecoder):
[302] Fix | Delete
"""
[303] Fix | Delete
This subclass of IncrementalDecoder can be used as the baseclass for an
[304] Fix | Delete
incremental decoder if the decoder must be able to handle incomplete
[305] Fix | Delete
byte sequences.
[306] Fix | Delete
"""
[307] Fix | Delete
def __init__(self, errors='strict'):
[308] Fix | Delete
IncrementalDecoder.__init__(self, errors)
[309] Fix | Delete
# undecoded input that is kept between calls to decode()
[310] Fix | Delete
self.buffer = b""
[311] Fix | Delete
[312] Fix | Delete
def _buffer_decode(self, input, errors, final):
[313] Fix | Delete
# Overwrite this method in subclasses: It must decode input
[314] Fix | Delete
# and return an (output, length consumed) tuple
[315] Fix | Delete
raise NotImplementedError
[316] Fix | Delete
[317] Fix | Delete
def decode(self, input, final=False):
[318] Fix | Delete
# decode input (taking the buffer into account)
[319] Fix | Delete
data = self.buffer + input
[320] Fix | Delete
(result, consumed) = self._buffer_decode(data, self.errors, final)
[321] Fix | Delete
# keep undecoded input until the next call
[322] Fix | Delete
self.buffer = data[consumed:]
[323] Fix | Delete
return result
[324] Fix | Delete
[325] Fix | Delete
def reset(self):
[326] Fix | Delete
IncrementalDecoder.reset(self)
[327] Fix | Delete
self.buffer = b""
[328] Fix | Delete
[329] Fix | Delete
def getstate(self):
[330] Fix | Delete
# additional state info is always 0
[331] Fix | Delete
return (self.buffer, 0)
[332] Fix | Delete
[333] Fix | Delete
def setstate(self, state):
[334] Fix | Delete
# ignore additional state info
[335] Fix | Delete
self.buffer = state[0]
[336] Fix | Delete
[337] Fix | Delete
#
[338] Fix | Delete
# The StreamWriter and StreamReader class provide generic working
[339] Fix | Delete
# interfaces which can be used to implement new encoding submodules
[340] Fix | Delete
# very easily. See encodings/utf_8.py for an example on how this is
[341] Fix | Delete
# done.
[342] Fix | Delete
#
[343] Fix | Delete
[344] Fix | Delete
class StreamWriter(Codec):
[345] Fix | Delete
[346] Fix | Delete
def __init__(self, stream, errors='strict'):
[347] Fix | Delete
[348] Fix | Delete
""" Creates a StreamWriter instance.
[349] Fix | Delete
[350] Fix | Delete
stream must be a file-like object open for writing.
[351] Fix | Delete
[352] Fix | Delete
The StreamWriter may use different error handling
[353] Fix | Delete
schemes by providing the errors keyword argument. These
[354] Fix | Delete
parameters are predefined:
[355] Fix | Delete
[356] Fix | Delete
'strict' - raise a ValueError (or a subclass)
[357] Fix | Delete
'ignore' - ignore the character and continue with the next
[358] Fix | Delete
'replace'- replace with a suitable replacement character
[359] Fix | Delete
'xmlcharrefreplace' - Replace with the appropriate XML
[360] Fix | Delete
character reference.
[361] Fix | Delete
'backslashreplace' - Replace with backslashed escape
[362] Fix | Delete
sequences.
[363] Fix | Delete
'namereplace' - Replace with \\N{...} escape sequences.
[364] Fix | Delete
[365] Fix | Delete
The set of allowed parameter values can be extended via
[366] Fix | Delete
register_error.
[367] Fix | Delete
"""
[368] Fix | Delete
self.stream = stream
[369] Fix | Delete
self.errors = errors
[370] Fix | Delete
[371] Fix | Delete
def write(self, object):
[372] Fix | Delete
[373] Fix | Delete
""" Writes the object's contents encoded to self.stream.
[374] Fix | Delete
"""
[375] Fix | Delete
data, consumed = self.encode(object, self.errors)
[376] Fix | Delete
self.stream.write(data)
[377] Fix | Delete
[378] Fix | Delete
def writelines(self, list):
[379] Fix | Delete
[380] Fix | Delete
""" Writes the concatenated list of strings to the stream
[381] Fix | Delete
using .write().
[382] Fix | Delete
"""
[383] Fix | Delete
self.write(''.join(list))
[384] Fix | Delete
[385] Fix | Delete
def reset(self):
[386] Fix | Delete
[387] Fix | Delete
""" Flushes and resets the codec buffers used for keeping state.
[388] Fix | Delete
[389] Fix | Delete
Calling this method should ensure that the data on the
[390] Fix | Delete
output is put into a clean state, that allows appending
[391] Fix | Delete
of new fresh data without having to rescan the whole
[392] Fix | Delete
stream to recover state.
[393] Fix | Delete
[394] Fix | Delete
"""
[395] Fix | Delete
pass
[396] Fix | Delete
[397] Fix | Delete
def seek(self, offset, whence=0):
[398] Fix | Delete
self.stream.seek(offset, whence)
[399] Fix | Delete
if whence == 0 and offset == 0:
[400] Fix | Delete
self.reset()
[401] Fix | Delete
[402] Fix | Delete
def __getattr__(self, name,
[403] Fix | Delete
getattr=getattr):
[404] Fix | Delete
[405] Fix | Delete
""" Inherit all other methods from the underlying stream.
[406] Fix | Delete
"""
[407] Fix | Delete
return getattr(self.stream, name)
[408] Fix | Delete
[409] Fix | Delete
def __enter__(self):
[410] Fix | Delete
return self
[411] Fix | Delete
[412] Fix | Delete
def __exit__(self, type, value, tb):
[413] Fix | Delete
self.stream.close()
[414] Fix | Delete
[415] Fix | Delete
###
[416] Fix | Delete
[417] Fix | Delete
class StreamReader(Codec):
[418] Fix | Delete
[419] Fix | Delete
charbuffertype = str
[420] Fix | Delete
[421] Fix | Delete
def __init__(self, stream, errors='strict'):
[422] Fix | Delete
[423] Fix | Delete
""" Creates a StreamReader instance.
[424] Fix | Delete
[425] Fix | Delete
stream must be a file-like object open for reading.
[426] Fix | Delete
[427] Fix | Delete
The StreamReader may use different error handling
[428] Fix | Delete
schemes by providing the errors keyword argument. These
[429] Fix | Delete
parameters are predefined:
[430] Fix | Delete
[431] Fix | Delete
'strict' - raise a ValueError (or a subclass)
[432] Fix | Delete
'ignore' - ignore the character and continue with the next
[433] Fix | Delete
'replace'- replace with a suitable replacement character
[434] Fix | Delete
'backslashreplace' - Replace with backslashed escape sequences;
[435] Fix | Delete
[436] Fix | Delete
The set of allowed parameter values can be extended via
[437] Fix | Delete
register_error.
[438] Fix | Delete
"""
[439] Fix | Delete
self.stream = stream
[440] Fix | Delete
self.errors = errors
[441] Fix | Delete
self.bytebuffer = b""
[442] Fix | Delete
self._empty_charbuffer = self.charbuffertype()
[443] Fix | Delete
self.charbuffer = self._empty_charbuffer
[444] Fix | Delete
self.linebuffer = None
[445] Fix | Delete
[446] Fix | Delete
def decode(self, input, errors='strict'):
[447] Fix | Delete
raise NotImplementedError
[448] Fix | Delete
[449] Fix | Delete
def read(self, size=-1, chars=-1, firstline=False):
[450] Fix | Delete
[451] Fix | Delete
""" Decodes data from the stream self.stream and returns the
[452] Fix | Delete
resulting object.
[453] Fix | Delete
[454] Fix | Delete
chars indicates the number of decoded code points or bytes to
[455] Fix | Delete
return. read() will never return more data than requested,
[456] Fix | Delete
but it might return less, if there is not enough available.
[457] Fix | Delete
[458] Fix | Delete
size indicates the approximate maximum number of decoded
[459] Fix | Delete
bytes or code points to read for decoding. The decoder
[460] Fix | Delete
can modify this setting as appropriate. The default value
[461] Fix | Delete
-1 indicates to read and decode as much as possible. size
[462] Fix | Delete
is intended to prevent having to decode huge files in one
[463] Fix | Delete
step.
[464] Fix | Delete
[465] Fix | Delete
If firstline is true, and a UnicodeDecodeError happens
[466] Fix | Delete
after the first line terminator in the input only the first line
[467] Fix | Delete
will be returned, the rest of the input will be kept until the
[468] Fix | Delete
next call to read().
[469] Fix | Delete
[470] Fix | Delete
The method should use a greedy read strategy, meaning that
[471] Fix | Delete
it should read as much data as is allowed within the
[472] Fix | Delete
definition of the encoding and the given size, e.g. if
[473] Fix | Delete
optional encoding endings or state markers are available
[474] Fix | Delete
on the stream, these should be read too.
[475] Fix | Delete
"""
[476] Fix | Delete
# If we have lines cached, first merge them back into characters
[477] Fix | Delete
if self.linebuffer:
[478] Fix | Delete
self.charbuffer = self._empty_charbuffer.join(self.linebuffer)
[479] Fix | Delete
self.linebuffer = None
[480] Fix | Delete
[481] Fix | Delete
if chars < 0:
[482] Fix | Delete
# For compatibility with other read() methods that take a
[483] Fix | Delete
# single argument
[484] Fix | Delete
chars = size
[485] Fix | Delete
[486] Fix | Delete
# read until we get the required number of characters (if available)
[487] Fix | Delete
while True:
[488] Fix | Delete
# can the request be satisfied from the character buffer?
[489] Fix | Delete
if chars >= 0:
[490] Fix | Delete
if len(self.charbuffer) >= chars:
[491] Fix | Delete
break
[492] Fix | Delete
# we need more data
[493] Fix | Delete
if size < 0:
[494] Fix | Delete
newdata = self.stream.read()
[495] Fix | Delete
else:
[496] Fix | Delete
newdata = self.stream.read(size)
[497] Fix | Delete
# decode bytes (those remaining from the last call included)
[498] Fix | Delete
data = self.bytebuffer + newdata
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function