Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca8a8d0

Browse files
committed
Make the BOM constants in codecs.py bytes.
Make the buffered input for decoders a bytes object. Fix some of the codec tests.
1 parent 3cc3452 commit ca8a8d0

2 files changed

Lines changed: 83 additions & 84 deletions

File tree

Lib/codecs.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@
3333
#
3434

3535
# UTF-8
36-
BOM_UTF8 = '\xef\xbb\xbf'
36+
BOM_UTF8 = b'\xef\xbb\xbf'
3737

3838
# UTF-16, little endian
39-
BOM_LE = BOM_UTF16_LE = '\xff\xfe'
39+
BOM_LE = BOM_UTF16_LE = b'\xff\xfe'
4040

4141
# UTF-16, big endian
42-
BOM_BE = BOM_UTF16_BE = '\xfe\xff'
42+
BOM_BE = BOM_UTF16_BE = b'\xfe\xff'
4343

4444
# UTF-32, little endian
45-
BOM_UTF32_LE = '\xff\xfe\x00\x00'
45+
BOM_UTF32_LE = b'\xff\xfe\x00\x00'
4646

4747
# UTF-32, big endian
48-
BOM_UTF32_BE = '\x00\x00\xfe\xff'
48+
BOM_UTF32_BE = b'\x00\x00\xfe\xff'
4949

5050
if sys.byteorder == 'little':
5151

@@ -261,7 +261,7 @@ def getstate(self):
261261
Return the current state of the decoder. This must be a
262262
(buffered_input, additional_state_info) tuple.
263263
"""
264-
return ("", 0)
264+
return (b"", 0)
265265

266266
def setstate(self, state):
267267
"""
@@ -278,7 +278,7 @@ class BufferedIncrementalDecoder(IncrementalDecoder):
278278
def __init__(self, errors='strict'):
279279
IncrementalDecoder.__init__(self, errors)
280280
# undecoded input that is kept between calls to decode()
281-
self.buffer = ""
281+
self.buffer = b""
282282

283283
def _buffer_decode(self, input, errors, final):
284284
# Overwrite this method in subclasses: It must decode input
@@ -295,7 +295,7 @@ def decode(self, input, final=False):
295295

296296
def reset(self):
297297
IncrementalDecoder.reset(self)
298-
self.buffer = ""
298+
self.buffer = b""
299299

300300
def getstate(self):
301301
# additional state info is always 0
@@ -402,7 +402,7 @@ def __init__(self, stream, errors='strict'):
402402
"""
403403
self.stream = stream
404404
self.errors = errors
405-
self.bytebuffer = ""
405+
self.bytebuffer = b""
406406
# For str->str decoding this will stay a str
407407
# For str->unicode decoding the first read will promote it to unicode
408408
self.charbuffer = ""
@@ -588,7 +588,7 @@ def reset(self):
588588
from decoding errors.
589589
590590
"""
591-
self.bytebuffer = ""
591+
self.bytebuffer = b""
592592
self.charbuffer = ""
593593
self.linebuffer = None
594594

@@ -1005,7 +1005,7 @@ def iterdecode(iterator, encoding, errors='strict', **kwargs):
10051005
output = decoder.decode(input)
10061006
if output:
10071007
yield output
1008-
output = decoder.decode("", True)
1008+
output = decoder.decode(b"", True)
10091009
if output:
10101010
yield output
10111011

0 commit comments

Comments
 (0)