dip.io.codecs.unicode¶
The dip.io.codecs.unicode module implements support for Unicode
encoders and decoders used with streaming storage.
IUnicodeDecoder¶
-
class
dip.io.codecs.unicode.IUnicodeDecoder¶ Base class:
InterfaceThe IUnicodeDecoder interface defines the interface to be implemented by models being decoded by the
UnicodeCodeccodec.-
set_unicode(model, data)¶ Set the model data from an Python v3 str object or a Python v2 unicode object.
Parameters: - model – is the model.
- data – the encoded model data.
Returns: the decoded model. This may be the original model populated from the storage location, or it may be a different model (of an appropriate type) created from the storage location.
-
IUnicodeEncoder¶
-
class
dip.io.codecs.unicode.IUnicodeEncoder¶ Base class:
InterfaceThe IUnicodeEncoder interface defines the interface to be implemented by models being encoded by the
UnicodeCodeccodec.-
get_unicode(model)¶ Return the model data encoded as a Python v3 str object or a Python v2 unicode object.
Parameters: model – is the model. Returns: the encoded model data.
-
UnicodeCodec¶
-
class
dip.io.codecs.unicode.UnicodeCodec¶ Base class:
ModelThe UnicodeCodec class implements a codec that decodes and encodes models as Unicode. The codec does not set the
formatattribute. This should be defined in a sub-class or passed as an argument when the codec is created.-
decoder_interface = IUnicodeDecoder The decoder interface.
-
encoder_interface = IUnicodeEncoder The encoder interface.
-
encoding = Str('utf8') The Unicode encoding that is being used.
-
decode(model, source, location)¶ A model is decoded from a byte stream.
Parameters: - model – is the model.
- source – is an iterator that will return the byte stream to be decoded.
- location – is the storage location where the encoded model is being read from. It is mainly used for error reporting.
Returns: the decoded model. This may be the original model populated from the storage location, or it may be a different model (of an appropriate type) created from the storage location.
-
encode(model, location)¶ A model is encoded as a byte stream.
Parameters: - model – is the model.
- location – is the storage location where the encoded model will be written to. It is mainly used for error reporting.
Returns: a generator that will return sections of the encoded byte stream.
-