Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_io.StatefulIncrementalDecoder Class Reference
Inheritance diagram for test.test_io.StatefulIncrementalDecoder:
Inheritance graph
[legend]
Collaboration diagram for test.test_io.StatefulIncrementalDecoder:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __repr__
def reset
def getstate
def setstate
def decode
def process_word
def lookupTestDecoder

Public Attributes

 i
 o
 buffer
 errors
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 codecEnabled = False

Detailed Description

For testing seek/tell behavior with a stateful, buffering decoder.

Input is a sequence of words.  Words may be fixed-length (length set
by input) or variable-length (period-terminated).  In variable-length
mode, extra periods are ignored.  Possible words are:
  - 'i' followed by a number sets the input length, I (maximum 99).
    When I is set to 0, words are space-terminated.
  - 'o' followed by a number sets the output length, O (maximum 99).
  - Any other word is converted into a word followed by a period on
    the output.  The output word consists of the input word truncated
    or padded out with hyphens to make its length equal to O.  If O
    is 0, the word is output verbatim without truncating or padding.
I and O are initially set to 1.  When I changes, any buffered input is
re-scanned according to the new I.  EOF also terminates the last word.

Definition at line 1586 of file test_io.py.


Constructor & Destructor Documentation

def test.test_io.StatefulIncrementalDecoder.__init__ (   self,
  errors = 'strict' 
)
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 from codecs.IncrementalDecoder.

Definition at line 1604 of file test_io.py.

01604 
01605     def __init__(self, errors='strict'):
01606         codecs.IncrementalDecoder.__init__(self, errors)
01607         self.reset()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Definition at line 1608 of file test_io.py.

01608 
01609     def __repr__(self):
01610         return '<SID %x>' % id(self)

def test.test_io.StatefulIncrementalDecoder.decode (   self,
  input,
  final = False 
)
Decode input and returns the resulting object.

Reimplemented from codecs.IncrementalDecoder.

Definition at line 1626 of file test_io.py.

01626 
01627     def decode(self, input, final=False):
01628         output = ''
01629         for b in input:
01630             if self.i == 0: # variable-length, terminated with period
01631                 if b == ord('.'):
01632                     if self.buffer:
01633                         output += self.process_word()
01634                 else:
01635                     self.buffer.append(b)
01636             else: # fixed-length, terminate after self.i bytes
01637                 self.buffer.append(b)
01638                 if len(self.buffer) == self.i:
01639                     output += self.process_word()
01640         if final and self.buffer: # EOF terminates the last word
01641             output += self.process_word()
01642         return output

Here is the call 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 1616 of file test_io.py.

01616 
01617     def getstate(self):
01618         i, o = self.i ^ 1, self.o ^ 1 # so that flags = 0 after reset()
01619         return bytes(self.buffer), i*100 + o

Definition at line 1662 of file test_io.py.

01662 
01663     def lookupTestDecoder(cls, name):
01664         if cls.codecEnabled and name == 'test_decoder':
01665             latin1 = codecs.lookup('latin-1')
01666             return codecs.CodecInfo(
01667                 name='test_decoder', encode=latin1.encode, decode=None,
01668                 incrementalencoder=None,
01669                 streamreader=None, streamwriter=None,
01670                 incrementaldecoder=cls)
01671 
01672 # Register the previous decoder for testing.
01673 # Disabled by default, tests will enable it.
01674 codecs.register(StatefulIncrementalDecoder.lookupTestDecoder)
01675 

Definition at line 1643 of file test_io.py.

01643 
01644     def process_word(self):
01645         output = ''
01646         if self.buffer[0] == ord('i'):
01647             self.i = min(99, int(self.buffer[1:] or 0)) # set input length
01648         elif self.buffer[0] == ord('o'):
01649             self.o = min(99, int(self.buffer[1:] or 0)) # set output length
01650         else:
01651             output = self.buffer.decode('ascii')
01652             if len(output) < self.o:
01653                 output += '-'*self.o # pad out with hyphens
01654             if self.o:
01655                 output = output[:self.o] # truncate to output length
01656             output += '.'
01657         self.buffer = bytearray()
01658         return output

Here is the call graph for this function:

Here is the caller graph for this function:

Reset the decoder to the initial state.

Reimplemented from codecs.IncrementalDecoder.

Definition at line 1611 of file test_io.py.

01611 
01612     def reset(self):
01613         self.i = 1
01614         self.o = 1
01615         self.buffer = bytearray()

Here is the caller graph for this function:

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 1620 of file test_io.py.

01620 
01621     def setstate(self, state):
01622         buffer, io = state
01623         self.buffer = bytearray(buffer)
01624         i, o = divmod(io, 100)
01625         self.i, self.o = i ^ 1, o ^ 1

Here is the call graph for this function:


Member Data Documentation

Definition at line 1614 of file test_io.py.

Definition at line 1659 of file test_io.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 1612 of file test_io.py.

Definition at line 1613 of file test_io.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


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