dip.io.codecs
The dip.io.codecs module implements support for specific data
encoders and decoders used with streaming storage.
-
class dip.io.codecs.XmlDecoder
Base class: Model
The XmlDecoder class implements an object decoder that decodes a
Model instance from XML.
-
decode(obj, source, location)
An object is decoded from an XML byte stream.
Parameters: |
- obj – is the object to populate from the decoded byte stream.
- source – is an iterator that will return the byte stream to be decoded.
- location – is the storage location where the encoded object is being read
from. It is mainly used for error reporting.
|
Returns: | the decoded object.
|
-
decode_attribute(obj, reader, source, location)
Decode the current element as an attribute.
Parameters: |
- obj – is the object to populate from the decoded byte stream.
- reader – is the QXmlStreamReader instance.
- source – is an iterator that will return the byte stream to be decoded.
- location – is the storage location where the encoded object is being read
from. It is mainly used for error reporting.
|
-
decode_document_element(obj, reader, location)
Decode the document element (i.e. the outermost element).
Parameters: |
- obj – is the object to populate from the decoded byte stream.
- reader – is the QXmlStreamReader instance.
- location – is the storage location where the encoded object is being read
from. It is mainly used for error reporting.
|
-
decode_model(obj, reader, source, location)
Decode the next element as a model.
Parameters: |
- obj – is the model to populate from the decoded byte stream.
- reader – is the QXmlStreamReader instance.
- source – is an iterator that will return the byte stream to be decoded.
- location – is the storage location where the encoded object is being read
from. It is mainly used for error reporting.
|
-
class dip.io.codecs.XmlEncoder
Base class: Model
The XmlEncoder class implements an object encoder that encodes a
Model instance as XML.
Note that, by default, pickle is used to encode any attributes that don’t
have a value corresponding to a fundamental Python type (i.e.
Int, List etc.). It is
recommended (but not required) that the object is defined fully in terms
of these fundamental types or that the encoder is sub-classed to handle
attributes with non-fundamental types explicitly.
-
declaration = Str('<?xml version="1.0" encoding="UTF-8"?>')
- The XML declaration.
-
document_start = Str()
- The text to open the outermost element.
-
document_end = Str('</DipModel>')
- The text to close the outermost element.
-
encoding = Str('utf8')
- The encoding to use.
-
exclude = List(Str())
- The list of names of attributes to exclude.
-
include = List(Str())
- The list of names of attributes to include. If this is empty then all
attributes are included unless they have been explicitly excluded.
-
indentation_spaces = Int(2)
- The number of spaces used for a single level of indentation.
-
encode(obj, location)
An object is encoded as an XML byte stream.
Parameters: |
- obj – is the object to encode.
- location – is the storage location where the encoded object will be written
to. It is mainly used for error reporting.
|
Returns: | the next section of the encoded XML byte stream.
|
-
encode_attribute(obj, name, value, attribute_type, location, indent_level)
A single attribute is encoded as an XML byte stream.
Parameters: |
- obj – is the object containing the attribute to encode.
- name – is the name of the attribute. It may be ‘’ if the value is a
member of a collection attribute.
- value – is the value of the attribute.
- attribute_type – is the type of the attribute.
- location – is the storage location where the encoded attribute will be
written to. It is mainly used for error reporting.
- indent_level – is the current indentation level as a number.
|
Returns: | the next section of the encoded XML byte stream.
|
-
encode_model(obj, location, indent_level)
A model is encoded as an XML byte stream.
Parameters: |
- obj – is the model to encode.
- location – is the storage location where the encoded model will be written
to. It is mainly used for error reporting.
- indent_level – is the current indentation level as a number.
|
-
static escape(value)
Replace any characters with their corresponding entities.
Parameter: | value – is the string to escape. |
Returns: | the escaped string. |
-
indentation(indent_level)
Return a string that will indent a line to a particular level.
Parameter: | indent_level – is the indentation level as a number. |
Returns: | the string. |