Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
codecs.StreamRecoder Class Reference
Collaboration diagram for codecs.StreamRecoder:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def read
def readline
def readlines
def __next__
def __iter__
def write
def writelines
def reset
def __getattr__
def __enter__
def __exit__

Public Attributes

 stream
 encode
 decode
 reader
 writer
 errors

Static Public Attributes

string data_encoding = 'unknown'
string file_encoding = 'unknown'

Detailed Description

StreamRecoder instances provide a frontend - backend
    view of encoding data.

    They use the complete set of APIs returned by the
    codecs.lookup() function to implement their task.

    Data written to the stream is first decoded into an
    intermediate format (which is dependent on the given codec
    combination) and then written to the stream using an instance
    of the provided Writer class.

    In the other direction, data is read from the stream using a
    Reader instance and then return encoded data to the caller.

Definition at line 733 of file codecs.py.


Constructor & Destructor Documentation

def codecs.StreamRecoder.__init__ (   self,
  stream,
  encode,
  decode,
  Reader,
  Writer,
  errors = 'strict' 
)
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 the
    StreamReader, StreamWriter interface resp.

    encode and decode are needed for the frontend translation,
    Reader and Writer for the backend translation. Unicode is
    used as intermediate encoding.

    Error handling is done in the same way as defined for the
    StreamWriter/Readers.

Definition at line 755 of file codecs.py.

00755 
00756                  errors='strict'):
00757 
00758         """ Creates a StreamRecoder instance which implements a two-way
00759             conversion: encode and decode work on the frontend (the
00760             input to .read() and output of .write()) while
00761             Reader and Writer work on the backend (reading and
00762             writing to the stream).
00763 
00764             You can use these objects to do transparent direct
00765             recodings from e.g. latin-1 to utf-8 and back.
00766 
00767             stream must be a file-like object.
00768 
00769             encode, decode must adhere to the Codec interface, Reader,
00770             Writer must be factory functions or classes providing the
00771             StreamReader, StreamWriter interface resp.
00772 
00773             encode and decode are needed for the frontend translation,
00774             Reader and Writer for the backend translation. Unicode is
00775             used as intermediate encoding.
00776 
00777             Error handling is done in the same way as defined for the
00778             StreamWriter/Readers.
00779 
00780         """
00781         self.stream = stream
00782         self.encode = encode
00783         self.decode = decode
00784         self.reader = Reader(stream, errors)
00785         self.writer = Writer(stream, errors)
00786         self.errors = errors

Here is the caller graph for this function:


Member Function Documentation

Definition at line 841 of file codecs.py.

00841 
00842     def __enter__(self):
00843         return self

def codecs.StreamRecoder.__exit__ (   self,
  type,
  value,
  tb 
)

Definition at line 844 of file codecs.py.

00844 
00845     def __exit__(self, type, value, tb):
00846         self.stream.close()

Here is the caller graph for this function:

def codecs.StreamRecoder.__getattr__ (   self,
  name,
  getattr = getattr 
)
Inherit all other methods from the underlying stream.

Definition at line 835 of file codecs.py.

00835 
00836                     getattr=getattr):
00837 
00838         """ Inherit all other methods from the underlying stream.
00839         """
00840         return getattr(self.stream, name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 815 of file codecs.py.

00815 
00816     def __iter__(self):
00817         return self

Return the next decoded line from the input stream.

Definition at line 808 of file codecs.py.

00808 
00809     def __next__(self):
00810 
00811         """ Return the next decoded line from the input stream."""
00812         data = next(self.reader)
00813         data, bytesencoded = self.encode(data, self.errors)
00814         return data

Here is the caller graph for this function:

def codecs.StreamRecoder.read (   self,
  size = -1 
)

Definition at line 787 of file codecs.py.

00787 
00788     def read(self, size=-1):
00789 
00790         data = self.reader.read(size)
00791         data, bytesencoded = self.encode(data, self.errors)
00792         return data

Here is the caller graph for this function:

def codecs.StreamRecoder.readline (   self,
  size = None 
)

Definition at line 793 of file codecs.py.

00793 
00794     def readline(self, size=None):
00795 
00796         if size is None:
00797             data = self.reader.readline()
00798         else:
00799             data = self.reader.readline(size)
00800         data, bytesencoded = self.encode(data, self.errors)
00801         return data

Here is the caller graph for this function:

def codecs.StreamRecoder.readlines (   self,
  sizehint = None 
)

Definition at line 802 of file codecs.py.

00802 
00803     def readlines(self, sizehint=None):
00804 
00805         data = self.reader.read()
00806         data, bytesencoded = self.encode(data, self.errors)
00807         return data.splitlines(1)

Definition at line 829 of file codecs.py.

00829 
00830     def reset(self):
00831 
00832         self.reader.reset()
00833         self.writer.reset()

Here is the call graph for this function:

Here is the caller graph for this function:

def codecs.StreamRecoder.write (   self,
  data 
)

Definition at line 818 of file codecs.py.

00818 
00819     def write(self, data):
00820 
00821         data, bytesdecoded = self.decode(data, self.errors)
00822         return self.writer.write(data)

def codecs.StreamRecoder.writelines (   self,
  list 
)

Definition at line 823 of file codecs.py.

00823 
00824     def writelines(self, list):
00825 
00826         data = ''.join(list)
00827         data, bytesdecoded = self.decode(data, self.errors)
00828         return self.writer.write(data)


Member Data Documentation

Definition at line 751 of file codecs.py.

Definition at line 782 of file codecs.py.

Definition at line 781 of file codecs.py.

Definition at line 785 of file codecs.py.

Definition at line 752 of file codecs.py.

Definition at line 783 of file codecs.py.

Definition at line 780 of file codecs.py.

Definition at line 784 of file codecs.py.


The documentation for this class was generated from the following file: