Revision 2 as of 2007-04-02 21:04:49

Clear message

StreamWriter wraps (contains) a stream. It overrides write and other respective methods to "encode" the data and pass the result to the stream.

Pseudocode of the codecs.StreamWriter definition in Python2.5:

   1 class StreamWriter(Codec):
   2     def __init__(self, stream):
   3         ....
   4 
   5     def write(data):
   6         return stream.write(self.encode(data))

The StreamWriter.encode method is attached to the derived codec-specific class definitions at the time of the codec initialization. An excerpt from encodings.utf_8.StreamWriter:

   1 class StreamWriter(codecs.StreamWriter):
   2     encode = codecs.utf_8_encode

Unable to edit the page? See the FrontPage for instructions.