Differences between revisions 3 and 4
Revision 3 as of 2007-04-02 21:08:39
Size: 737
Editor: cscfpc15
Comment:
Revision 4 as of 2007-04-02 21:13:14
Size: 849
Editor: cscfpc15
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
StreamWriter wraps (contains) a stream. It defines {{{write}}} and other respective methods to "encode" the data and pass the result to the stream. It exposes all other methods of the stream instance.
Line 3: Line 2:
Pseudocode of the {{{codecs.StreamWriter}}} definition in Python2.5: As of Python2.5, {{{StreamWriter}}} wraps (contains) a stream. It defines {{{write}}} and other respective methods to "encode" the data and pass the result to the stream. It exposes all other methods of the stream instance.

Pseudocode of the {{{codecs.StreamWriter}}} definition:
Line 11: Line 12:
    def write(data):     def write(self, data):
Line 15: Line 16:
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}}}:
The {{{encode}}} method normally converts values of type {{{unicode}}} to {{{str}}}s.

Codec modules will attach the {{{StreamWriter.encode}}} method to the class definition derived from StreamWriter during the initialization. An excerpt from {{{encodings.utf_8.StreamWriter}}}:

As of Python2.5, StreamWriter wraps (contains) a stream. It defines write and other respective methods to "encode" the data and pass the result to the stream. It exposes all other methods of the stream instance.

Pseudocode of the codecs.StreamWriter definition:

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

The encode method normally converts values of type unicode to strs.

Codec modules will attach the StreamWriter.encode method to the class definition derived from StreamWriter during the initialization. An excerpt from encodings.utf_8.StreamWriter:

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

StreamWriter (last edited 2008-11-15 14:00:59 by localhost)

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