[Python-Dev] Some thoughts on the codecs...

Fredrik Lundh fredrik@pythonware.com
Tue, 16 Nov 1999 09:39:20 +0100


Guido van Rossum <guido@CNRI.Reston.VA.US> wrote:
> I had thought something more like what Java does: an output stream
> codec's constructor takes a writable file object and the object
> returned by the constructor has a write() method, a flush() method and
> a close() method.  It acts like a buffering interface to the
> underlying file; this allows it to generate the minimal number of
> shift sequeuces.  Similar for input stream codecs.

note that the html/sgml/xml parsers generally
support the feed/close protocol.  to be able
to use these codecs in that context, we need

1) codes written according to the "data
   consumer model", instead of the "stream"
   model.

        class myDecoder:
            def __init__(self, target):
                self.target = target
                self.state = ...
            def feed(self, data):
                ... extract as much data as possible ...
                self.target.feed(extracted data)
            def close(self):
                ... extract what's left ...
                self.target.feed(additional data)
                self.target.close()

or

2) make threads mandatory, just like in Java.

or

3) add light-weight threads (ala stackless python)
   to the interpreter...

(I vote for alternative 3, but that's another story ;-)

</F>