Differences between revisions 1 and 2
Revision 1 as of 2007-04-02 21:27:08
Size: 841
Editor: cscfpc15
Comment:
Revision 2 as of 2007-04-02 21:28:42
Size: 883
Editor: cscfpc15
Comment:
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
Codec modules will attach the {{{StreamReader.decode}}} method to the class definition derived from {{{StreamReader}}} during the initialization. An excerpt from {{{encodings.utf_8.StreamReader}}}: Codec modules will attach the {{{decode}}} method to the class definition derived from {{{StreamReader}}} during the initialization. An excerpt from {{{encodings.utf_8.StreamReader}}}:
Line 25: Line 25:

----
See also: StreamWriter
----
CategoryUnicode

As of Python2.5, StreamReader wraps (contains) a stream. It defines read and other respective methods to read the data from the stream and "decode" them. The class exposes all other methods of the stream instance.

Pseudocode of the codecs.StreamReader definition:

   1 class StreamReader(Codec):
   2     def __init__(self, stream):
   3         ....
   4 
   5     def read(self):
   6         return self.decode(stream.read())

The decode method normally converts values of type str to unicode.

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

   1 class StreamReader(codecs.StreamReader):
   2     decode = codecs.utf_8_decode


See also: StreamWriter


CategoryUnicode

StreamReader (last edited 2008-11-15 14:00:34 by localhost)

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