| Home | Trees | Indices | Help |
|
|---|
|
|
The kenozooid.uddf module provides support for parsing, searching and manipulation of data stored in UDDF files.
The functions implemented in this module can be divided into the following categories
Searching functions use XPath expressions (queries) to find data. Each tag name in an query should be prefixed with 'uddf:' string to indicate UDDF namespace, i.e. 'uddf:diver', 'uddf:waypoint' - appropriate namespace mapping for this prefix is defined for each XPath call.
The result of parsing or search of data is usually iterator of XML nodes or data records (named tuples in Python terms).
Module lxml is used for XML parsing and querying with XPath. Full
capabilities of underlying libxml2 library is used by design. The
ElementTree XML data model is used for XML nodes.
| Classes | |
|
RangeError Error raised when a range cannot be parsed. |
|
|
NodeCopier UDDF dcument node copier. |
|
| Functions | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
| Variables | |
log = logging.getLogger('kenozooid.uddf')
|
|
FORMAT_ID = 'id-{}'
|
|
FMT_F = partial(str.format, '{0:.1f}')
|
|
FMT_F2 = partial(str.format, '{0:.2f}')
|
|
FMT_I = lambda v:
|
|
FMT_DT = lambda dt:
|
|
XPath = partial(et.XPath, namespaces= _NSMAP)
|
|
XP_DEFAULT_DIVE_DATA = XPath('uddf:informationbeforedive/uddf:
|
|
XP_DEFAULT_PROFILE_DATA = XPath('uddf:depth/text()'), XPath('u
|
|
XP_DEFAULT_GAS_DATA = XPath('@id'), XPath('uddf:name/text()'),
|
|
XP_WAYPOINT = XPath('./uddf:samples/uddf:waypoint')
|
|
XP_MIX = XPath('/uddf:uddf/uddf:gasdefinitions/uddf:mix')
|
|
XP_DEFAULT_DUMP_DATA = XPath('uddf:link/@ref'), XPath('../../u
|
|
XP_DEFAULT_BUDDY_DATA = XPath('@id'), XPath('uddf:personal/udd
|
|
XP_DEFAULT_SITE_DATA = XPath('@id'), XPath('uddf:name/text()')
|
|
XP_FIND_BUDDY = XPath('/uddf:uddf/uddf:diver/uddf:buddy[' '@id
|
|
XP_FIND_SITE = XPath('/uddf:uddf/uddf:divesite/uddf:site[' '@i
|
|
XP_FIND_DIVES = XPath('/uddf:uddf/uddf:profiledata' '/uddf:rep
|
|
XP_FIND_DIVE_GASES = XPath('/uddf:uddf/uddf:gasdefinitions' '/
|
|
ns = et.FunctionNamespace(None)
|
|
DEFAULT_FMT_DIVE_PROFILE = {'depth': lambda d: str.format('{0:
|
|
UDDF_BASIC = "
|
|
| Function Details |
Parse XML file and return document object. File to parse can be anything supported by lxml library. If file to parse is file name and ends with '.bz2', then it is treated as file compressed with bzip2.
|
Find XML nodes in UDDF file using XPath query.
UDDF file can be a file name, file object, URL and basically everything
what is supported by `lxml` library.
File to parse can be a file name ending with '.bz2'. It is treated as
file compressed with bzip2.
:Parameters:
f
UDDF file to parse.
query
XPath expression or XPath object.
params
XPath query parameters.
.. seealso:: :py:func:`XPath`, :py:func:`parse`
|
Find items with XPath query.
The query is performed using UDDF namespace.
Iterator of items (strings, nodes) found by query is returned.
:Parameters:
node
Document node or query starting node.
query
XPath query.
.. seealso::
lxml.etree.Element.xpath
|
Get first element found with XPath query.
The query is performed using UDDF namespace.
First element is returned or None if it is not found.
:Parameters:
node
Document node or query starting node.
query
XPath query.
.. seealso::
lxml.etree.Element.xpath
|
Get last element found with XPath query.
The query is performed using UDDF namespace.
Last element is returned or None if it is not found.
:Parameters:
node
Document node or query starting node.
query
XPath query.
.. seealso::
lxml.etree.Element.xpath
|
Find data records starting from specified XML node.
A record type (namedtuple) is created with specified fields. The data
of a record is retrieved with XPath expression objects, which is
converted from string to appropriate type using parsers.
A parser can be any type or function, i.e. `float`, `int` or
`dateutil.parser.parse`.
If XML node is too high to execture XPath expression objects, then the
basis for field queries can be relocated with `nquery` parameter. If
`nquery` parameter is not specified, then only one record is returned.
Otherwise it is generator of records.
The length of fields, field queries and field parsers should be the same.
:Parameters:
name
Name of the record to be created.
node
XML node.
fields
Names of fields to be created in a record.
queries
XPath expression objects for each field to retrieve its value.
parsers
Parsers of field values to be created in a record.
nquery
XPath expression object to relocate from node to more appropriate
position in XML document for record data retrieval.
.. seealso:: :py:func:`dive_data`, :py:func:`dive_profile`
|
Specialized function to return record of a dive data.
At the moment record of dive data contains dive start time only, by
default. It should be enhanced in the future to return more rich data
record.
Dive record data can be reconfigured with optional fields, field
queries and field parsers parameters.
:Parameters:
node
XML node.
fields
Names of fields to be created in a record.
queries
XPath expression object for each field to retrieve its value.
parsers
Parsers field values to be created in a record.
.. seealso:: :py:func:`find_data`
|
Specialized function to return generator of dive profiles records.
By default, dive profile record contains following fields
time
dive time in seconds
depth
dive depth in meters
temp
temperature in Kelvins
Dive profile record data can be reconfigured with optional fields,
field queries and field parsers parameters.
:Parameters:
node
XML node.
fields
Names of fields to be created in a record.
queries
XPath expression objects for each field to retrieve its value.
parsers
Parsers of field values to be created in a record.
.. seealso:: :py:func:`find_data`
|
Get dive computer dump data.
The following data is returned
dc_id
Dive computer id.
dc_model
Dive computer model information.
datetime
Date and time when dive computer dump was obtained.
data
Dive computer dump data.
:Parameters:
node
XML node.
fields
Names of fields to be created in a record.
queries
XPath expression objects for each field to retrieve its value.
parsers
Parsers of field values to be created in a record.
.. seealso:: :py:func:`find_data`
|
Get dive buddy data.
The following data is returned by default
id
Buddy id.
fname
Buddy first name.
mname
Buddy middle name.
lname
Buddy last name.
org
Organization, which a buddy is member of.
number
Member number id in the organisation.
:Parameters:
node
XML node.
fields
Names of fields to be created in a record.
queries
XPath expression objects for each field to retrieve its value.
parsers
Parsers of field values to be created in a record.
.. seealso:: :py:func:`find_data`
|
Get dive site data.
The following data is returned by default
id
Dive site id.
name
Dive site name.
location
Dive site location.
x
Dive site longitude.
y
Dive site latitude.
:Parameters:
node
XML node.
fields
Names of fields to be created in a record.
queries
XPath expression objects for each field to retrieve its value.
parsers
Parsers of field values to be created in a record.
.. seealso:: :py:func:`find_data`
|
Parse textual representation of number range into Python expression. Examples of a ranges >>> parse_range('1-3,5') '1 <= n and n <= 3 or n == 5' >>> parse_range('-3,10') 'n <= 3 or n == 10' Example of infinite range >>> parse_range('20-') '20 <= n'
|
XPath expression function to restrict position of a node to be within
numeric range.
:Parameters:
ctx
XPath context object.
pos
Node position.
nodes
Number range, i.e. "2-3".
.. seealso:: :py:func:`parse_range`
|
fixme: obsolete Create basic UDDF structure.
|
Set data of nodes or attributes using XPath queries relative to specified XML node. The data values are converted to string with formatters functions.
|
TODO: get rid of parent, does not make sense Create a hierarchy of nodes using XML nodes path specification. Path is a string of node names separated by slash character, i.e. a/b/c creates: <a><b><c/></b><a> If parent node is specified and some part of node hierarchy already exists then only non-existant nodes are created, i.e. if parent is 'x' node in <x><y/></x> then path 'x/z' modifies XML document as follows <x><y/><z/></x>
|
|
|
|
|
|
|
|
|
|
|
Save UDDF XML data into a file. If output file is file name ending with '.bz2', then it is compressed with bzip2. The UDDF XML data can be ElementTree XML object or iterable of strings. If output file exists then backup file with .bak extension is created.
|
|
fixme: obsolete Reorder and cleanup dives in UDDF document. Following operations are being performed
|
Generate id for a value. If value is specified then id is MD5 hash of value. If not specified, then id is generated with UUID 4. The returned id is a string prefixed with id- to make it XML compliant. |
|
Get major version of UDDF file. Tuple (major, minor) is returned, i.e. (3, 0), (3, 1), etc.
|
| Variables Details |
XP_DEFAULT_DIVE_DATA
|
XP_DEFAULT_PROFILE_DATA
|
XP_DEFAULT_GAS_DATA
|
XP_DEFAULT_DUMP_DATA
|
XP_DEFAULT_BUDDY_DATA
|
XP_DEFAULT_SITE_DATA
|
XP_FIND_BUDDY
|
XP_FIND_SITE
|
XP_FIND_DIVES
|
XP_FIND_DIVE_GASES
|
DEFAULT_FMT_DIVE_PROFILE
|
UDDF_BASIC
|
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Aug 16 20:40:50 2019 | http://epydoc.sourceforge.net |