Copyright (C) 2000-2012 |
GNU Info (python2.1-lib.info)StreamRecoder ObjectsStreamRecoder Objects ..................... The `StreamRecoder' provide a frontend - backend view of encoding data which is sometimes useful when dealing with different encoding environments. The design is such that one can use the factory functions returned by the `lookup()' function to construct the instance. `StreamRecoder(stream, encode, decode, Reader, Writer, errors)' Creates a `StreamRecoder' instance which implements a two-way conversion: ENCODE and DECODE work on the frontend (the input to `read()' and output of `write()') while READER and WRITER work on the backend (reading and writing to the stream). You can use these objects to do transparent direct recodings from e.g. Latin-1 to UTF-8 and back. STREAM must be a file-like object. ENCODE, DECODE must adhere to the `Codec' interface, READER, WRITER must be factory functions or classes providing objects of the the `StreamReader' and `StreamWriter' interface respectively. ENCODE and DECODE are needed for the frontend translation, READER and WRITER for the backend translation. The intermediate format used is determined by the two sets of codecs, e.g. the Unicode codecs will use Unicode as intermediate encoding. Error handling is done in the same way as defined for the stream readers and writers. `StreamRecoder' instances define the combined interfaces of `StreamReader' and `StreamWriter' classes. They inherit all other methods and attribute from the underlying stream. automatically generated by info2www version 1.2.2.9 |