| |
- __builtin__.object
-
- IncrementalDecoder
- IncrementalEncoder
- __builtin__.tuple(__builtin__.object)
-
- CodecInfo
- Codec
-
- StreamReader
- StreamWriter
- StreamReaderWriter
- StreamRecoder
class Codec |
|
Defines the interface for stateless encoders/decoders.
The .encode()/.decode() methods may use different error
handling schemes by providing the errors argument. These
string values are predefined:
'strict' - raise a ValueError error (or a subclass)
'ignore' - ignore the character and continue with the next
'replace' - replace with a suitable replacement character;
Python will use the official U+FFFD REPLACEMENT
CHARACTER for the builtin Unicode codecs on
decoding and '?' on encoding.
'xmlcharrefreplace' - Replace with the appropriate XML
character reference (only for encoding).
'backslashreplace' - Replace with backslashed escape sequences
(only for encoding).
The set of allowed values can be extended via register_error. |
|
Methods defined here:
- decode(self, input, errors='strict')
- 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.
- encode(self, input, errors='strict')
- 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.
|
class CodecInfo(__builtin__.tuple) |
| |
- Method resolution order:
- CodecInfo
- __builtin__.tuple
- __builtin__.object
Methods defined here:
- __repr__(self)
Static methods defined here:
- __new__(cls, encode, decode, streamreader=None, streamwriter=None, incrementalencoder=None, incrementaldecoder=None, name=None)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
Methods inherited from __builtin__.tuple:
- __add__(...)
- x.__add__(y) <==> x+y
- __contains__(...)
- x.__contains__(y) <==> y in x
- __eq__(...)
- x.__eq__(y) <==> x==y
- __ge__(...)
- x.__ge__(y) <==> x>=y
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __getitem__(...)
- x.__getitem__(y) <==> x[y]
- __getnewargs__(...)
- __getslice__(...)
- x.__getslice__(i, j) <==> x[i:j]
Use of negative indices is not supported.
- __gt__(...)
- x.__gt__(y) <==> x>y
- __hash__(...)
- x.__hash__() <==> hash(x)
- __iter__(...)
- x.__iter__() <==> iter(x)
- __le__(...)
- x.__le__(y) <==> x<=y
- __len__(...)
- x.__len__() <==> len(x)
- __lt__(...)
- x.__lt__(y) <==> x<y
- __mul__(...)
- x.__mul__(n) <==> x*n
- __ne__(...)
- x.__ne__(y) <==> x!=y
- __rmul__(...)
- x.__rmul__(n) <==> n*x
- count(...)
- T.count(value) -> integer -- return number of occurrences of value
- index(...)
- T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
|
class IncrementalDecoder(__builtin__.object) |
|
An IncrementalDecoder decodes an input in multiple steps. The input can be
passed piece by piece to the decode() method. The IncrementalDecoder
remembers the state of the decoding process between calls to decode(). |
|
Methods defined here:
- __init__(self, errors='strict')
- Creates 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.
- decode(self, input, final=False)
- Decodes input and returns the resulting object.
- getstate(self)
- 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).
- reset(self)
- Resets the decoder to the initial state.
- 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().
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class IncrementalEncoder(__builtin__.object) |
|
An IncrementalEncoder encodes an input in multiple steps. The input can be
passed piece by piece to the encode() method. The IncrementalEncoder remembers
the state of the Encoding process between calls to encode(). |
|
Methods defined here:
- __init__(self, errors='strict')
- Creates an IncrementalEncoder instance.
The IncrementalEncoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.
- encode(self, input, final=False)
- Encodes input and returns the resulting object.
- getstate(self)
- Return the current state of the encoder.
- reset(self)
- Resets the encoder to the initial state.
- setstate(self, state)
- Set the current state of the encoder. state must have been
returned by getstate().
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class StreamReader(Codec) |
| |
Methods defined here:
- __enter__(self)
- __exit__(self, type, value, tb)
- __getattr__(self, name, getattr=<built-in function getattr>)
- Inherit all other methods from the underlying stream.
- __init__(self, stream, errors='strict')
- Creates a StreamReader instance.
stream must be a file-like object open for reading
(binary) data.
The StreamReader may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character;
The set of allowed parameter values can be extended via
register_error.
- __iter__(self)
- decode(self, input, errors='strict')
- next(self)
- Return the next decoded line from the input stream.
- read(self, size=-1, chars=-1, firstline=False)
- 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.
- readline(self, size=None, keepends=True)
- Read one line from the input stream and return the
decoded data.
size, if given, is passed as size argument to the
read() method.
- readlines(self, sizehint=None, keepends=True)
- 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.
- reset(self)
- 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.
- seek(self, offset, whence=0)
- Set the input stream's current position.
Resets the codec buffers used for keeping state.
Methods inherited from Codec:
- encode(self, input, errors='strict')
- 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.
|
class StreamReaderWriter |
|
StreamReaderWriter instances allow wrapping streams which
work in both read and write modes.
The design is such that one can use the factory functions
returned by the codec.lookup() function to construct the
instance. |
|
Methods defined here:
- __enter__(self)
- __exit__(self, type, value, tb)
- __getattr__(self, name, getattr=<built-in function getattr>)
- Inherit all other methods from the underlying stream.
- __init__(self, stream, Reader, Writer, errors='strict')
- Creates a StreamReaderWriter instance.
stream must be a Stream-like object.
Reader, Writer must be factory functions or classes
providing the StreamReader, StreamWriter interface resp.
Error handling is done in the same way as defined for the
StreamWriter/Readers.
- __iter__(self)
- next(self)
- Return the next decoded line from the input stream.
- read(self, size=-1)
- readline(self, size=None)
- readlines(self, sizehint=None)
- reset(self)
- seek(self, offset, whence=0)
- write(self, data)
- writelines(self, list)
Data and other attributes defined here:
- encoding = 'unknown'
|
class StreamRecoder |
|
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. |
|
Methods defined here:
- __enter__(self)
- __exit__(self, type, value, tb)
- __getattr__(self, name, getattr=<built-in function getattr>)
- Inherit all other methods from the underlying stream.
- __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.
- __iter__(self)
- next(self)
- Return the next decoded line from the input stream.
- read(self, size=-1)
- readline(self, size=None)
- readlines(self, sizehint=None)
- reset(self)
- write(self, data)
- writelines(self, list)
Data and other attributes defined here:
- data_encoding = 'unknown'
- file_encoding = 'unknown'
|
class StreamWriter(Codec) |
| |
Methods defined here:
- __enter__(self)
- __exit__(self, type, value, tb)
- __getattr__(self, name, getattr=<built-in function getattr>)
- Inherit all other methods from the underlying stream.
- __init__(self, stream, errors='strict')
- Creates a StreamWriter instance.
stream must be a file-like object open for writing
(binary) data.
The StreamWriter may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character
'xmlcharrefreplace' - Replace with the appropriate XML
character reference.
'backslashreplace' - Replace with backslashed escape
sequences (only for encoding).
The set of allowed parameter values can be extended via
register_error.
- reset(self)
- Flushes and resets the codec buffers used for keeping state.
Calling this method should ensure that the data on the
output is put into a clean state, that allows appending
of new fresh data without having to rescan the whole
stream to recover state.
- seek(self, offset, whence=0)
- write(self, object)
- Writes the object's contents encoded to self.stream.
- writelines(self, list)
- Writes the concatenated list of strings to the stream
using .write().
Methods inherited from Codec:
- decode(self, input, errors='strict')
- 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.
- encode(self, input, errors='strict')
- 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.
| |