IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
4.8.1.2 IncrementalEncoder Objects


4.8.1.2 IncrementalEncoder Objects

New in version 2.5.

The IncrementalEncoder class is used for encoding an input in multiple steps. It defines the following methods which every incremental encoder must define in order to be compatible with the Python codec registry.

class IncrementalEncoder( [errors])
Constructor for an IncrementalEncoder instance.

All incremental encoders must provide this constructor interface. They are free to add additional keyword arguments, but only the ones defined here are used by the Python codec registry.

The IncrementalEncoder may implement different error handling schemes by providing the errors keyword argument. These parameters are predefined:

  • 'strict' Raise ValueError (or a subclass); this is the default.
  • '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.

The errors argument will be assigned to an attribute of the same name. Assigning to this attribute makes it possible to switch between different error handling strategies during the lifetime of the IncrementalEncoder object.

The set of allowed values for the errors argument can be extended with register_error().

encode( object[, final])
Encodes object (taking the current state of the encoder into account) and returns the resulting encoded object. If this is the last call to encode final must be true (the default is false).

reset( )
Reset the encoder to the initial state.

See About this document... for information on suggesting changes.