Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Private Attributes
_pyio.IncrementalNewlineDecoder Class Reference
Inheritance diagram for _pyio.IncrementalNewlineDecoder:
Inheritance graph
[legend]
Collaboration diagram for _pyio.IncrementalNewlineDecoder:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def decode
def getstate
def setstate
def reset
def newlines

Public Attributes

 translate
 decoder
 seennl
 pendingcr
 errors
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Private Attributes

int _LF = 1
int _CR = 2
int _CRLF = 4

Detailed Description

Definition at line 1363 of file _pyio.py.


Constructor & Destructor Documentation

def _pyio.IncrementalNewlineDecoder.__init__ (   self,
  decoder,
  translate,
  errors = 'strict' 
)

Definition at line 1370 of file _pyio.py.

01370 
01371     def __init__(self, decoder, translate, errors='strict'):
01372         codecs.IncrementalDecoder.__init__(self, errors=errors)
01373         self.translate = translate
01374         self.decoder = decoder
01375         self.seennl = 0
01376         self.pendingcr = False

Here is the caller graph for this function:


Member Function Documentation

def _pyio.IncrementalNewlineDecoder.decode (   self,
  input,
  final = False 
)
Decode input and returns the resulting object.

Reimplemented from codecs.IncrementalDecoder.

Definition at line 1377 of file _pyio.py.

01377 
01378     def decode(self, input, final=False):
01379         # decode input (with the eventual \r from a previous pass)
01380         if self.decoder is None:
01381             output = input
01382         else:
01383             output = self.decoder.decode(input, final=final)
01384         if self.pendingcr and (output or final):
01385             output = "\r" + output
01386             self.pendingcr = False
01387 
01388         # retain last \r even when not translating data:
01389         # then readline() is sure to get \r\n in one pass
01390         if output.endswith("\r") and not final:
01391             output = output[:-1]
01392             self.pendingcr = True
01393 
01394         # Record which newlines are read
01395         crlf = output.count('\r\n')
01396         cr = output.count('\r') - crlf
01397         lf = output.count('\n') - crlf
01398         self.seennl |= (lf and self._LF) | (cr and self._CR) \
01399                     | (crlf and self._CRLF)
01400 
01401         if self.translate:
01402             if crlf:
01403                 output = output.replace("\r\n", "\n")
01404             if cr:
01405                 output = output.replace("\r", "\n")
01406 
01407         return output

Here is the caller graph for this function:

Return the current state of the decoder.

This must be a (buffered_input, additional_state_info) tuple.
buffered_input must be a bytes object containing bytes that
were passed to decode() that have not yet been converted.
additional_state_info must be a non-negative integer
representing the state of the decoder WITHOUT yet having
processed the contents of buffered_input.  In the initial state
and after reset(), getstate() must return (b"", 0).

Reimplemented from codecs.IncrementalDecoder.

Definition at line 1408 of file _pyio.py.

01408 
01409     def getstate(self):
01410         if self.decoder is None:
01411             buf = b""
01412             flag = 0
01413         else:
01414             buf, flag = self.decoder.getstate()
01415         flag <<= 1
01416         if self.pendingcr:
01417             flag |= 1
01418         return buf, flag

Definition at line 1436 of file _pyio.py.

01436 
01437     def newlines(self):
01438         return (None,
01439                 "\n",
01440                 "\r",
01441                 ("\r", "\n"),
01442                 "\r\n",
01443                 ("\n", "\r\n"),
01444                 ("\r", "\r\n"),
01445                 ("\r", "\n", "\r\n")
01446                )[self.seennl]
01447 

Reset the decoder to the initial state.

Reimplemented from codecs.IncrementalDecoder.

Definition at line 1425 of file _pyio.py.

01425 
01426     def reset(self):
01427         self.seennl = 0
01428         self.pendingcr = False
01429         if self.decoder is not None:
01430             self.decoder.reset()

Here is the caller graph for this function:

def _pyio.IncrementalNewlineDecoder.setstate (   self,
  state 
)
Set the current state of the decoder.

state must have been returned by getstate().  The effect of
setstate((b"", 0)) must be equivalent to reset().

Reimplemented from codecs.IncrementalDecoder.

Definition at line 1419 of file _pyio.py.

01419 
01420     def setstate(self, state):
01421         buf, flag = state
01422         self.pendingcr = bool(flag & 1)
01423         if self.decoder is not None:
01424             self.decoder.setstate((buf, flag >> 1))


Member Data Documentation

Definition at line 1432 of file _pyio.py.

Definition at line 1433 of file _pyio.py.

Definition at line 1431 of file _pyio.py.

Definition at line 1373 of file _pyio.py.

Create a IncrementalDecoder instance.

The IncrementalDecoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.

Reimplemented in encodings.bz2_codec.IncrementalDecoder, encodings.zlib_codec.IncrementalDecoder, encodings.base64_codec.IncrementalDecoder, and encodings.hex_codec.IncrementalDecoder.

Definition at line 246 of file codecs.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 1375 of file _pyio.py.

Definition at line 1374 of file _pyio.py.

Definition at line 1372 of file _pyio.py.


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