API¶
This part of the documentation covers interfaces of axon.
Classes¶
-
class
axon.
Loader
¶ Loader from line oriented unicode text inputs.
-
line
¶ Current input unicode line
-
pos
¶ Position of current unicode character
-
lnum
¶ Number of current input unicode line
-
errto
¶ Name of file for reporting errors
-
Loader
(fd, readline, builder="safe", sbuilder="default", errto=None)¶ Parameters: - fd – File-like object with .readline() and .close() method
- mode – Specifies the method of building python objects for complex values
- errto – Name of file for reporting errors
-
load
()¶ Load all values.
-
next
¶
-
-
class
axon.
Dumper
¶ Dumper class
-
dump
()¶ Main dumping method.
Parameters: - seq – Sequence of values to dump
- pretty – Flag indicates whether to use pretty dumping mode. Default is False (i.e. no pretty dumping)
-
-
class
axon.
Empty
¶ Empty named complex value.
-
_name
¶
Name of complex value
-
_mapping
¶
Dictionary of attributes.
-
_sequence
¶
List of values.
-
-
class
axon.
Sequence
¶ Named sequence of values.
-
_name
¶
Name of sequence.
-
_mapping
¶
Empty dictionary of attributes.
-
_sequence
¶
List of values.
-
-
class
axon.
Mapping
¶ Named mapping containing pairs of name/value.
-
_name
¶
Name of mapping
-
_mapping
¶
Mapping containing pairs of name: value.
-
_sequence
¶
Empty list of values.
-
Functions¶
Loading and dumping¶
-
axon.
display
(text, pretty=1, braces=0, sorted=1, hsize=0, crossref=0)[source]¶ Display AXON text in formatted form for easy read.
Parameters: text – unicode AXON text Returns: formatted unicode AXON text
-
axon.
load
(fd, mode=u'safe', errto=None, encoding=u'utf-8', json=0)[source]¶ Load object from unicode text in AXON.
Parameters: - fd – input file name of file object opening as TextIO/StringIO
- mode – specifies the method of building python objects for complex values.
- errto – name of file for reporting errors
- encoding – encoding of input file (default utf-8)
- There are values of parameter mode:
- “safe” - use safe object builder
- “strict” - use unsafe builder with strict name resolution: if there is no registered name for building object builder return undef object
- “mixed” - use unsafe object builder with following rule: if there is no registered name for building object then use safe mode.
Parameters: json – if true then allow to load from json format Returns: list of values.
-
axon.
loads
(text, mode=u'safe', errto=None, json=0)[source]¶ Load values from unicode text.
Parameters: - text – unicode text in AXON.
- mode – specifies the method of building python objects for complex values (see .. py:func:load)
- errto – name of file for reporting errors
- json – if true then allow to load from json format
Returns: list of values.
-
axon.
iload
(fd, mode=u'safe', errto=None, encoding=u'utf-8', json=0)[source]¶ Iterative loading values from input file.
Arguments are same as in .. py:func:load.
Returns: iterator object.
-
axon.
iloads
(text, mode=u'safe', errto=None, json=0)[source]¶ Iterative loading values from unicode text.
Parameters: - text – unicode text in AXON.
- mode – specifies the method of building python objects for complex values (see .. py:func:load)
- errto – name of file for reporting errors
- json – if true then allow to load from json format
Returns: iterator object.
-
axon.
dump
(fpath, val, pretty=0, braces=0, sorted=1, hsize=0, crossref=0, encoding=u'utf-8')[source]¶ Same as
dumps()
but for dumping into a file.Parameters: fpath – path to file for dumping. For other parameters see
dumps()
.
-
axon.
dumps
(val, pretty=0, braces=0, sorted=1, hsize=0, crossref=0)[source]¶ Dump value into unicode text.
Parameters: - val – value to convert
- simple_dumpers – dictionary containing callables for text representation of values of simple types &em; int, float, decimal, boolean, unicode text, date/time/datetime &em; in form of type:dumper.
- type_reducers – dictionary containing callables, which returns reduced data for representation in AXON.
- pretty –
flag indicating pretty dumping:
- True - use pretty dumping
- False - do not use pretty dumping (default)
- crossref –
flag for crossreferece support in unsafe mode
- True - use crosserefernce support
- False - do not use crosserefernce support (default)
Returns: unicode string of AXON representation of val.
Factory functions for safe mode complex values¶
-
axon.
empty
()¶ Factory function for creating empty complex value.
Parameters: name – name of empty complex value.
-
axon.
mapping
()¶ Factory function for creating named mapping.
Parameters: - name – name of sequence.
- mapping – python dictionary containing pairs of name/value.
-
axon.
sequence
()¶ Factory function for creating named sequence.
Parameters: - name – name of the sequence.
- sequence – python sequence containing values.
-
axon.
element
()¶ Factory function for creating named element.
Parameters: - name – name of element.
- mapping – python dictionary containing pairs of name: value.
- sequence – python sequence containing child values.
-
axon.
instance
()¶ Factory function for creating named instance.
Parameters: - name – name of object.
- sequence – python sequence containing required values.
- mapping – python dictionary containing optional values in form of of name: value pairs.