From f44c7e8996d8115739b52fa52896f2f9f7d94142 Mon Sep 17 00:00:00 2001 From: Ka-Ping Yee Date: Tue, 18 Mar 2008 04:51:32 +0000 Subject: 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. --- Lib/codecs.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'Lib/codecs.py') diff --git a/Lib/codecs.py b/Lib/codecs.py index 6d8d5544ed..f05c4f7e2d 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -237,7 +237,7 @@ class IncrementalDecoder(object): """ def __init__(self, errors='strict'): """ - Creates a IncrementalDecoder instance. + Create a IncrementalDecoder instance. The IncrementalDecoder may use different error handling schemes by providing the errors keyword argument. See the module docstring @@ -247,28 +247,35 @@ class IncrementalDecoder(object): def decode(self, input, final=False): """ - Decodes input and returns the resulting object. + Decode input and returns the resulting object. """ raise NotImplementedError def reset(self): """ - Resets the decoder to the initial state. + Reset the decoder to the initial state. """ def getstate(self): """ - Return the current state of the decoder. This must be a - (buffered_input, additional_state_info) tuple. By convention, - additional_state_info should represent the state of the decoder - WITHOUT yet having processed the contents of buffered_input. + Return the current state of the decoder. + + This must be a (buffered_input, additional_state_info) tuple. + buffered_input must be a bytes object containing bytes that + were passed to decode() that have not yet been converted. + additional_state_info must be a non-negative integer + representing the state of the decoder WITHOUT yet having + processed the contents of buffered_input. In the initial state + and after reset(), getstate() must return (b"", 0). """ return (b"", 0) def setstate(self, state): """ - Set the current state of the decoder. state must have been - returned by getstate(). + Set the current state of the decoder. + + state must have been returned by getstate(). The effect of + setstate((b"", 0)) must be equivalent to reset(). """ class BufferedIncrementalDecoder(IncrementalDecoder): -- cgit v1.2.1