[Python-Dev] Codecs and StreamCodecs

Guido van Rossum guido@CNRI.Reston.VA.US
Thu, 18 Nov 1999 11:37:08 -0500


> Like a path of search functions ? Not a bad idea... I will still
> want the internal dict for caching purposes though. I'm not sure
> how often these encodings will be, but even a few hundred function
> call will slow down the Unicode implementation quite a bit.

Of course.  (It's like sys.modules caching the results of an import).

[...]
>     def flush(self):
> 
> 	""" Flushed the codec buffers used for keeping state.
> 
> 	    Returns values are not defined. Implementations are free to
> 	    return None, raise an exception (in case there is pending
> 	    data in the buffers which could not be decoded) or
> 	    return any remaining data from the state buffers used.
> 
> 	"""

I don't know where this came from, but a flush() should work like
flush() on a file.  It doesn't return a value, it just sends any
remaining data to the underlying stream (for output).  For input it
shouldn't be supported at all.

The idea is that flush() should do the same to the encoder state that
close() followed by a reopen() would do.  Well, more or less.  But if
the process were to be killed right after a flush(), the data written
to disk should be a complete encoding, and not have a lingering shift
state.

--Guido van Rossum (home page: http://www.python.org/~guido/)