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

Skip to content

Commit f44c7e8

Browse files
committed
Make TextIOWrapper's seek/tell work properly with stateful decoders;
document and rename things to make seek/tell workings a little clearer. Add a weird decoder for testing TextIOWrapper's seek/tell methods. Document the getstate/setstate protocol conventions for IncrementalDecoders.
1 parent b5dc90b commit f44c7e8

3 files changed

Lines changed: 369 additions & 111 deletions

File tree

Lib/codecs.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class IncrementalDecoder(object):
237237
"""
238238
def __init__(self, errors='strict'):
239239
"""
240-
Creates a IncrementalDecoder instance.
240+
Create a IncrementalDecoder instance.
241241
242242
The IncrementalDecoder may use different error handling schemes by
243243
providing the errors keyword argument. See the module docstring
@@ -247,28 +247,35 @@ def __init__(self, errors='strict'):
247247

248248
def decode(self, input, final=False):
249249
"""
250-
Decodes input and returns the resulting object.
250+
Decode input and returns the resulting object.
251251
"""
252252
raise NotImplementedError
253253

254254
def reset(self):
255255
"""
256-
Resets the decoder to the initial state.
256+
Reset the decoder to the initial state.
257257
"""
258258

259259
def getstate(self):
260260
"""
261-
Return the current state of the decoder. This must be a
262-
(buffered_input, additional_state_info) tuple. By convention,
263-
additional_state_info should represent the state of the decoder
264-
WITHOUT yet having processed the contents of buffered_input.
261+
Return the current state of the decoder.
262+
263+
This must be a (buffered_input, additional_state_info) tuple.
264+
buffered_input must be a bytes object containing bytes that
265+
were passed to decode() that have not yet been converted.
266+
additional_state_info must be a non-negative integer
267+
representing the state of the decoder WITHOUT yet having
268+
processed the contents of buffered_input. In the initial state
269+
and after reset(), getstate() must return (b"", 0).
265270
"""
266271
return (b"", 0)
267272

268273
def setstate(self, state):
269274
"""
270-
Set the current state of the decoder. state must have been
271-
returned by getstate().
275+
Set the current state of the decoder.
276+
277+
state must have been returned by getstate(). The effect of
278+
setstate((b"", 0)) must be equivalent to reset().
272279
"""
273280

274281
class BufferedIncrementalDecoder(IncrementalDecoder):

0 commit comments

Comments
 (0)