polymatheia.data
The classes in the polymatheia.data package handle data input and output.
- class polymatheia.data.LimitingIterator(it, max_records)
The
LimitingIteratorlimits the number of records returned from a wrapped iterator.- __init__(it, max_records)
Create a new
LimitingIterator.- Parameters:
it – The wrapped iterator.
max_records (
number) – The maximum number of records to return.
- __iter__()
Return this
LimitingIteratoras the iterator.
- __next__()
Return the next value.
- Raises:
StopIteration – If no more values are available
- __weakref__
list of weak references to the object (if defined)
The
NavigableDictis adictsubclass that allows access via dot notation.>>> test = NavigableDict(one='1') >>> test.one 1 >>> test['one'] 1
The
NavigableDictworks like adictin any other respect.Delete the value with the given
key.- Raises:
KeyError – If no value exists for
key
Retrieve the value with the given
key.- Returns:
The value for the
key- Raises:
KeyError – If no value exists for
key
Initialise the
NavigableDict, ensuring that data is coerced.
Set the
valueforkey.This method automatically coerces any
dictvalueintoNavigableDict.- Parameters:
key (
string) – The key to set the value forvalue – The value to set
Return a pretty-printed JSON representation.
list of weak references to the object (if defined)
Get the value specified by the
path.The
pathcan either be astr, in which case it is split into its component parts. If it is alistthen it is used as is. The followingstrpathstructures are supported:x: Get the value with the key'x'x.y: Get the value with the key'x'and then within that the key'y'x.a: Get the list with the key'x'and in that returns thea-th element in the listx[a]: Get the list with the key'x'and in that returns thea-th element in the list
In general the
listformat is only needed if one of the parts used in thepathcontains a'.','[', or']'.This differs from just using attribute access, in how it handles lists. If a value is a list and the next path element is not a list index, then it will return a list, applying the remainder of the path to each element in the list.
- Parameters:
path (
stror[str, ...]) – The path to get the value fordefault – The default value to return if the
pathdoes not identify a value
- Returns:
The value identified by
pathor thedefaultvalue
Merge the
othervalues.Unlike the
update()method, this method does not immediately overwrite any existing values. Instead if both the new and existing value areNavigableDict, then the values from theotherNavigableDictare merged into the existingNavigableDict. Similarly, if both the new and existing value arelist, then the new existing list is extended with the new list. If neither of these conditions hold, then the existing value is overwritten by the new value.
Set the
valueat the location specified bypath.The
pathcan either be astr, in which case it is split into its component parts. If it is alistthen it is used as is. The followingstrpathstructures are supported:x: Set the value with the key'x'x.y: Set the value with the key'x'and then within that the key'y'x.a: Set the list with the key'x'and in that set thea-th element in the listx[a]: Set the list with the key'x'and in that set thea-th element in the list
In general the
listformat is only needed if one of the parts used in thepathcontains a'.','[', or']'.- Parameters:
path (
stror[str, ...]) – The path to set the value forvalue – The value to set
Update the content of this
NavigableDict.Any
dictpassed will be coerced intoNavigableDict
The
NavigableDictIteratormaps values toNavigableDict.If the iterator it wraps returns
dictobjects, then these are simply converted intoNavigableDictobjects. If amapperfunction is provided, then this function is called with each value and it must return adictobject that is then converted into aNavigableDictobject. Otherwise aNavigableDictis returned that has a single keyvalue, with the wrapped iterator value.Create a new
NavigableDictIterator.- Parameters:
it – The iterator that provides the values.
mapper – An optional mapping function converting a single iterator value into a
dictobject.
Return this
NavigableDictIteratoras the iterator.
Return the next
NavigableDict.- Raises:
StopIteration – If no more
NavigableDictare available
list of weak references to the object (if defined)
Convert the XML node to a dictionary.
Child
nodes are returned as keys of the dictionary. Where anodeoccurs multiple times, the key returns a list of dictionaries for the children. This means that the ordering information in the original XML document is lost. All attributes are available via the_attribkey. Thenode‘s text is available via the_textkey and any text that directly follows thenodeis available via the_tailkey.- Parameters:
node – The XML node to convert
- Returns:
The dictionary representation of the XML node
- Return type: