[issue12171] Reset method of the incremental encoders of CJK codecs calls the decoder reset function

STINNER Victor report at bugs.python.org
Thu May 26 02:14:09 CEST 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

> I'm not sure what you mean by "discard the output".
> 
> Calling .reset() should still add the closing sequence to the output
> buffer, if needed.

Incremental encoders don't have any buffer.

Python 3.3a0 (default:3c7792ec4547+, May 26 2011, 00:24:51) 
>>> import codecs

>>> enc=codecs.lookup('hz').incrementalencoder()
>>> enc.encode('\u8000')
b'~{R+'
>>> enc.reset()

>>> enc.encode('\u8000')
b'~{R+'
>>> enc.encode('', final=True)
b'~}'

>>> import io
>>> buffer=io.BytesIO()
>>> enc=codecs.lookup('hz').streamwriter(buffer)
>>> enc.write('\u8000')
>>> buffer.getvalue()
b'~{R+'
>>> enc.reset()
>>> buffer.getvalue()
b'~{R+~}'

IncrementalEncoder.reset() may mention that the output is discarded:

   .. method:: reset()

      Reset the encoder to the initial state. The output is discarded: 
      use the ``encode('', final=True)`` method to reset the encoder 
      and to get the output.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12171>
_______________________________________


More information about the Python-bugs-list mailing list