Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
StreamRecoder Class Reference

Public Member Functions

def __init__
 
def read
 
def readline
 
def readlines
 
def write
 
def writelines
 
def reset
 
def __getattr__
 

Data Fields

 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 358 of file codecs.py.

Constructor & Destructor Documentation

def __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 380 of file codecs.py.

381  errors='strict'):
382 
383  """ Creates a StreamRecoder instance which implements a two-way
384  conversion: encode and decode work on the frontend (the
385  input to .read() and output of .write()) while
386  Reader and Writer work on the backend (reading and
387  writing to the stream).
388 
389  You can use these objects to do transparent direct
390  recodings from e.g. latin-1 to utf-8 and back.
391 
392  stream must be a file-like object.
393 
394  encode, decode must adhere to the Codec interface, Reader,
395  Writer must be factory functions or classes providing the
396  StreamReader, StreamWriter interface resp.
397 
398  encode and decode are needed for the frontend translation,
399  Reader and Writer for the backend translation. Unicode is
400  used as intermediate encoding.
401 
402  Error handling is done in the same way as defined for the
403  StreamWriter/Readers.
404 
405  """
406  self.stream = stream
407  self.encode = encode
408  self.decode = decode
409  self.reader = Reader(stream, errors)
410  self.writer = Writer(stream, errors)
411  self.errors = errors

Member Function Documentation

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

Definition at line 453 of file codecs.py.

References StreamWriter.stream, StreamReader.stream, StreamReaderWriter.stream, and StreamRecoder.stream.

454  getattr=getattr):
455 
456  """ Inherit all other methods from the underlying stream.
457  """
458  return getattr(self.stream, name)
def read (   self,
  size = -1 
)

Definition at line 412 of file codecs.py.

References StreamRecoder.encode, StreamWriter.errors, StreamReader.errors, StreamReaderWriter.errors, and StreamRecoder.errors.

413  def read(self, size=-1):
414 
415  data = self.reader.read(size)
416  data, bytesencoded = self.encode(data, self.errors)
417  return data
def readline (   self,
  size = None 
)

Definition at line 418 of file codecs.py.

References StreamRecoder.encode, StreamWriter.errors, StreamReader.errors, StreamReaderWriter.errors, and StreamRecoder.errors.

419  def readline(self, size=None):
420 
421  if size is None:
422  data = self.reader.readline()
423  else:
424  data = self.reader.readline(size)
425  data, bytesencoded = self.encode(data, self.errors)
426  return data
def readlines (   self,
  sizehint = None 
)

Definition at line 427 of file codecs.py.

References StreamRecoder.encode, StreamWriter.errors, StreamReader.errors, StreamReaderWriter.errors, and StreamRecoder.errors.

428  def readlines(self, sizehint=None):
429 
430  if sizehint is None:
431  data = self.reader.read()
432  else:
433  data = self.reader.read(sizehint)
434  data, bytesencoded = self.encode(data, self.errors)
435  return data.splitlines(1)
def reset (   self)

Definition at line 447 of file codecs.py.

References StreamRecoder.__getattr__().

448  def reset(self):
449 
450  self.reader.reset()
451  self.writer.reset()
def write (   self,
  data 
)

Definition at line 436 of file codecs.py.

References StreamRecoder.decode, StreamWriter.errors, StreamReader.errors, StreamReaderWriter.errors, and StreamRecoder.errors.

437  def write(self, data):
438 
439  data, bytesdecoded = self.decode(data, self.errors)
440  return self.writer.write(data)
def writelines (   self,
  list 
)

Definition at line 441 of file codecs.py.

References StreamRecoder.decode, StreamWriter.errors, StreamReader.errors, StreamReaderWriter.errors, StreamRecoder.errors, and dospath.join().

442  def writelines(self, list):
443 
444  data = ''.join(list)
445  data, bytesdecoded = self.decode(data, self.errors)
446  return self.writer.write(data)

Field Documentation

string data_encoding = 'unknown'
static

Definition at line 376 of file codecs.py.

decode

Definition at line 407 of file codecs.py.

encode

Definition at line 406 of file codecs.py.

errors

Definition at line 410 of file codecs.py.

string file_encoding = 'unknown'
static

Definition at line 377 of file codecs.py.

reader

Definition at line 408 of file codecs.py.

stream

Definition at line 405 of file codecs.py.

writer

Definition at line 409 of file codecs.py.


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