prance.util.iterators¶
This submodule contains specialty iterators over specs.
Functions¶
- prance.util.iterators.item_iterator(value, path=())[source]¶
Return item iterator over the a nested dict- or list-like object.
Returns each item value as the second item to unpack, and a tuple path to the item as the first value - in that, it behaves much like viewitems(). For list like values, the path is made up of numeric indices.
Given a spec such as this:
spec = { 'foo': 42, 'bar': { 'some': 'dict', }, 'baz': [ { 1: 2 }, { 3: 4 }, ] }
Here, (parts of) the yielded values would be:
item
path
[…]
(‘baz’,)
{ 1: 2 }
(‘baz’, 0)
2
(‘baz’, 0, 1)
- Parameters
value (dict/list) – The specifications to iterate over.
- Returns
An iterator over all items in the value.
- Return type
iterator
- prance.util.iterators.reference_iterator(specs, path=())[source]¶
Iterate through the given specs, returning only references.
- The iterator returns three values:
The key, mimicking the behaviour of other iterators, although it will always equal ‘$ref’
The value
The path to the item. This is a tuple of all the item’s ancestors, in sequence, so that you can reasonably easily find the containing item. It does not include the final ‘$ref’ key.
- Parameters
specs (dict) – The specifications to iterate over.
- Returns
An iterator over all references in the specs.
- Return type
iterator