Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
encodings.iso8859_15.StreamReader Class Reference
Inheritance diagram for encodings.iso8859_15.StreamReader:
Inheritance graph
[legend]
Collaboration diagram for encodings.iso8859_15.StreamReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def encode
def decode
def decode
def read
def readline
def readlines
def reset
def seek
def __next__
def __iter__
def __getattr__
def __enter__
def __exit__

Public Attributes

 stream
 errors
 bytebuffer
 charbuffer
 linebuffer

Static Public Attributes

 charbuffertype = str

Detailed Description

Definition at line 28 of file iso8859_15.py.


Member Function Documentation

def codecs.StreamReader.__enter__ (   self) [inherited]

Definition at line 638 of file codecs.py.

00638 
00639     def __enter__(self):
00640         return self

def codecs.StreamReader.__exit__ (   self,
  type,
  value,
  tb 
) [inherited]

Definition at line 641 of file codecs.py.

00641 
00642     def __exit__(self, type, value, tb):
00643         self.stream.close()

Here is the caller graph for this function:

def codecs.StreamReader.__getattr__ (   self,
  name,
  getattr = getattr 
) [inherited]
Inherit all other methods from the underlying stream.

Definition at line 632 of file codecs.py.

00632 
00633                     getattr=getattr):
00634 
00635         """ Inherit all other methods from the underlying stream.
00636         """
00637         return getattr(self.stream, name)

Here is the call graph for this function:

Here is the caller graph for this function:

def codecs.StreamReader.__iter__ (   self) [inherited]

Definition at line 628 of file codecs.py.

00628 
00629     def __iter__(self):
00630         return self

Here is the call graph for this function:

def codecs.StreamReader.__next__ (   self) [inherited]
Return the next decoded line from the input stream.

Definition at line 620 of file codecs.py.

00620 
00621     def __next__(self):
00622 
00623         """ Return the next decoded line from the input stream."""
00624         line = self.readline()
00625         if line:
00626             return line
00627         raise StopIteration

Here is the call graph for this function:

Here is the caller graph for this function:

def encodings.iso8859_15.Codec.decode (   self,
  input,
  errors = 'strict' 
) [inherited]
Decodes the object input and returns a tuple (output
    object, length consumed).

    input must be an object which provides the bf_getreadbuf
    buffer slot. Python strings, buffer objects and memory
    mapped files are examples of objects providing this slot.

    errors defines the error handling to apply. It defaults to
    'strict' handling.

    The method may not store state in the Codec instance. Use
    StreamCodec for codecs which have to keep state in order to
    make encoding/decoding efficient.

    The decoder must be able to handle zero length input and
    return an empty object of the output object type in this
    situation.

Reimplemented from codecs.Codec.

Definition at line 14 of file iso8859_15.py.

00014 
00015     def decode(self,input,errors='strict'):
00016         return codecs.charmap_decode(input,errors,decoding_table)

Here is the caller graph for this function:

def codecs.StreamReader.decode (   self,
  input,
  errors = 'strict' 
) [inherited]
Decodes the object input and returns a tuple (output
    object, length consumed).

    input must be an object which provides the bf_getreadbuf
    buffer slot. Python strings, buffer objects and memory
    mapped files are examples of objects providing this slot.

    errors defines the error handling to apply. It defaults to
    'strict' handling.

    The method may not store state in the Codec instance. Use
    StreamCodec for codecs which have to keep state in order to
    make encoding/decoding efficient.

    The decoder must be able to handle zero length input and
    return an empty object of the output object type in this
    situation.

Reimplemented from codecs.Codec.

Reimplemented in encodings.utf_16.StreamReader, encodings.utf_32.StreamReader, encodings.utf_8_sig.StreamReader, and encodings.charmap.StreamReader.

Definition at line 426 of file codecs.py.

00426 
00427     def decode(self, input, errors='strict'):
00428         raise NotImplementedError

Here is the caller graph for this function:

def encodings.iso8859_15.Codec.encode (   self,
  input,
  errors = 'strict' 
) [inherited]
Encodes the object input and returns a tuple (output
    object, length consumed).

    errors defines the error handling to apply. It defaults to
    'strict' handling.

    The method may not store state in the Codec instance. Use
    StreamCodec for codecs which have to keep state in order to
    make encoding/decoding efficient.

    The encoder must be able to handle zero length input and
    return an empty object of the output object type in this
    situation.

Reimplemented from codecs.Codec.

Definition at line 11 of file iso8859_15.py.

00011 
00012     def encode(self,input,errors='strict'):
00013         return codecs.charmap_encode(input,errors,encoding_table)

Here is the caller graph for this function:

def codecs.StreamReader.read (   self,
  size = -1,
  chars = -1,
  firstline = False 
) [inherited]
Decodes data from the stream self.stream and returns the
    resulting object.

    chars indicates the number of characters to read from the
    stream. read() will never return more than chars
    characters, but it might return less, if there are not enough
    characters available.

    size indicates the approximate maximum number of bytes to
    read from the stream for decoding purposes. The decoder
    can modify this setting as appropriate. The default value
    -1 indicates to read and decode as much as possible.  size
    is intended to prevent having to decode huge files in one
    step.

    If firstline is true, and a UnicodeDecodeError happens
    after the first line terminator in the input only the first line
    will be returned, the rest of the input will be kept until the
    next call to read().

    The method should use a greedy read strategy meaning that
    it should read as much data as is allowed within the
    definition of the encoding and the given size, e.g.  if
    optional encoding endings or state markers are available
    on the stream, these should be read too.

Definition at line 429 of file codecs.py.

00429 
00430     def read(self, size=-1, chars=-1, firstline=False):
00431 
00432         """ Decodes data from the stream self.stream and returns the
00433             resulting object.
00434 
00435             chars indicates the number of characters to read from the
00436             stream. read() will never return more than chars
00437             characters, but it might return less, if there are not enough
00438             characters available.
00439 
00440             size indicates the approximate maximum number of bytes to
00441             read from the stream for decoding purposes. The decoder
00442             can modify this setting as appropriate. The default value
00443             -1 indicates to read and decode as much as possible.  size
00444             is intended to prevent having to decode huge files in one
00445             step.
00446 
00447             If firstline is true, and a UnicodeDecodeError happens
00448             after the first line terminator in the input only the first line
00449             will be returned, the rest of the input will be kept until the
00450             next call to read().
00451 
00452             The method should use a greedy read strategy meaning that
00453             it should read as much data as is allowed within the
00454             definition of the encoding and the given size, e.g.  if
00455             optional encoding endings or state markers are available
00456             on the stream, these should be read too.
00457         """
00458         # If we have lines cached, first merge them back into characters
00459         if self.linebuffer:
00460             self.charbuffer = self._empty_charbuffer.join(self.linebuffer)
00461             self.linebuffer = None
00462 
00463         # read until we get the required number of characters (if available)
00464         while True:
00465             # can the request can be satisfied from the character buffer?
00466             if chars < 0:
00467                 if size < 0:
00468                     if self.charbuffer:
00469                         break
00470                 elif len(self.charbuffer) >= size:
00471                     break
00472             else:
00473                 if len(self.charbuffer) >= chars:
00474                     break
00475             # we need more data
00476             if size < 0:
00477                 newdata = self.stream.read()
00478             else:
00479                 newdata = self.stream.read(size)
00480             # decode bytes (those remaining from the last call included)
00481             data = self.bytebuffer + newdata
00482             try:
00483                 newchars, decodedbytes = self.decode(data, self.errors)
00484             except UnicodeDecodeError as exc:
00485                 if firstline:
00486                     newchars, decodedbytes = \
00487                         self.decode(data[:exc.start], self.errors)
00488                     lines = newchars.splitlines(True)
00489                     if len(lines)<=1:
00490                         raise
00491                 else:
00492                     raise
00493             # keep undecoded bytes until the next call
00494             self.bytebuffer = data[decodedbytes:]
00495             # put new characters in the character buffer
00496             self.charbuffer += newchars
00497             # there was no data available
00498             if not newdata:
00499                 break
00500         if chars < 0:
00501             # Return everything we've got
00502             result = self.charbuffer
00503             self.charbuffer = self._empty_charbuffer
00504         else:
00505             # Return the first chars characters
00506             result = self.charbuffer[:chars]
00507             self.charbuffer = self.charbuffer[chars:]
00508         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def codecs.StreamReader.readline (   self,
  size = None,
  keepends = True 
) [inherited]
Read one line from the input stream and return the
    decoded data.

    size, if given, is passed as size argument to the
    read() method.

Definition at line 509 of file codecs.py.

00509 
00510     def readline(self, size=None, keepends=True):
00511 
00512         """ Read one line from the input stream and return the
00513             decoded data.
00514 
00515             size, if given, is passed as size argument to the
00516             read() method.
00517 
00518         """
00519         # If we have lines cached from an earlier read, return
00520         # them unconditionally
00521         if self.linebuffer:
00522             line = self.linebuffer[0]
00523             del self.linebuffer[0]
00524             if len(self.linebuffer) == 1:
00525                 # revert to charbuffer mode; we might need more data
00526                 # next time
00527                 self.charbuffer = self.linebuffer[0]
00528                 self.linebuffer = None
00529             if not keepends:
00530                 line = line.splitlines(False)[0]
00531             return line
00532 
00533         readsize = size or 72
00534         line = self._empty_charbuffer
00535         # If size is given, we call read() only once
00536         while True:
00537             data = self.read(readsize, firstline=True)
00538             if data:
00539                 # If we're at a "\r" read one extra character (which might
00540                 # be a "\n") to get a proper line ending. If the stream is
00541                 # temporarily exhausted we return the wrong line ending.
00542                 if (isinstance(data, str) and data.endswith("\r")) or \
00543                    (isinstance(data, bytes) and data.endswith(b"\r")):
00544                     data += self.read(size=1, chars=1)
00545 
00546             line += data
00547             lines = line.splitlines(True)
00548             if lines:
00549                 if len(lines) > 1:
00550                     # More than one line result; the first line is a full line
00551                     # to return
00552                     line = lines[0]
00553                     del lines[0]
00554                     if len(lines) > 1:
00555                         # cache the remaining lines
00556                         lines[-1] += self.charbuffer
00557                         self.linebuffer = lines
00558                         self.charbuffer = None
00559                     else:
00560                         # only one remaining line, put it back into charbuffer
00561                         self.charbuffer = lines[0] + self.charbuffer
00562                     if not keepends:
00563                         line = line.splitlines(False)[0]
00564                     break
00565                 line0withend = lines[0]
00566                 line0withoutend = lines[0].splitlines(False)[0]
00567                 if line0withend != line0withoutend: # We really have a line end
00568                     # Put the rest back together and keep it until the next call
00569                     self.charbuffer = self._empty_charbuffer.join(lines[1:]) + \
00570                                       self.charbuffer
00571                     if keepends:
00572                         line = line0withend
00573                     else:
00574                         line = line0withoutend
00575                     break
00576             # we didn't get anything or this was our only try
00577             if not data or size is not None:
00578                 if line and not keepends:
00579                     line = line.splitlines(False)[0]
00580                 break
00581             if readsize < 8000:
00582                 readsize *= 2
00583         return line

Here is the call graph for this function:

Here is the caller graph for this function:

def codecs.StreamReader.readlines (   self,
  sizehint = None,
  keepends = True 
) [inherited]
Read all lines available on the input stream
    and return them as list of lines.

    Line breaks are implemented using the codec's decoder
    method and are included in the list entries.

    sizehint, if given, is ignored since there is no efficient
    way to finding the true end-of-line.

Definition at line 584 of file codecs.py.

00584 
00585     def readlines(self, sizehint=None, keepends=True):
00586 
00587         """ Read all lines available on the input stream
00588             and return them as list of lines.
00589 
00590             Line breaks are implemented using the codec's decoder
00591             method and are included in the list entries.
00592 
00593             sizehint, if given, is ignored since there is no efficient
00594             way to finding the true end-of-line.
00595 
00596         """
00597         data = self.read()
00598         return data.splitlines(keepends)

Here is the call graph for this function:

def codecs.StreamReader.reset (   self) [inherited]
Resets the codec buffers used for keeping state.

    Note that no stream repositioning should take place.
    This method is primarily intended to be able to recover
    from decoding errors.

Reimplemented in encodings.utf_16.StreamReader, encodings.utf_32.StreamReader, and encodings.utf_8_sig.StreamReader.

Definition at line 599 of file codecs.py.

00599 
00600     def reset(self):
00601 
00602         """ Resets the codec buffers used for keeping state.
00603 
00604             Note that no stream repositioning should take place.
00605             This method is primarily intended to be able to recover
00606             from decoding errors.
00607 
00608         """
00609         self.bytebuffer = b""
00610         self.charbuffer = self._empty_charbuffer
00611         self.linebuffer = None

Here is the caller graph for this function:

def codecs.StreamReader.seek (   self,
  offset,
  whence = 0 
) [inherited]
Set the input stream's current position.

    Resets the codec buffers used for keeping state.

Definition at line 612 of file codecs.py.

00612 
00613     def seek(self, offset, whence=0):
00614         """ Set the input stream's current position.
00615 
00616             Resets the codec buffers used for keeping state.
00617         """
00618         self.stream.seek(offset, whence)
00619         self.reset()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 421 of file codecs.py.

Definition at line 423 of file codecs.py.

codecs.StreamReader.charbuffertype = str [static, inherited]

Definition at line 420 of file codecs.py.

Definition at line 424 of file codecs.py.

Definition at line 419 of file codecs.py.


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