itertree package¶
Indices and tables¶
Modules¶
The main itertree class¶
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the main iTree object
-
class
itertree.itree_main.
iTree
(tag=<class 'itertree.itree_helpers.NoTag'>, value=<class 'itertree.itree_helpers.NoValue'>, subtree=None, link=None, flags=0)[source]¶ Bases:
itertree.itree_private._iTreePrivate
-
__init__
(tag=<class 'itertree.itree_helpers.NoTag'>, value=<class 'itertree.itree_helpers.NoValue'>, subtree=None, link=None, flags=0)[source]¶ This is the main class related to itertree module. It represents the node in the nested tree structure.
In case the object contains a subtree this object is the parent of the children in the subtree and its inner children (children, sub-children, etc.). The ´iTree´-object itself can also be a child of a parent ´iTree´-object. If this is not the case the ´iTree´-object is the root of the tree.
Limitation: An ´iTree´-object can be integrated as a child in one ´iTree´ only (one parent only principle)!
Each ´iTree´-object contains a “tag”. The objects tag can be any hashable object.
Different as dictionaries it is allowed to put multiple items with the same tag inside the ´iTree´. Those items with the same tag are placed and ordered (enumerated) in the related tag-family. The specific items can be targeted via a zag_idx tuple (family-tag,family-index) which is the items unique key.
Linked ´iTree´-objects will behave a bit special. They have a read only structure (children) and they contain the children (tree) of the linked ´iTree´. The “local” attributes like tag, value, … can be set independent of the linked item (local properties).
To change the tree structure of such an object you can change the original link target. But an explicit reload ( ´load_links()´ ) is required to get the change active in the linked items.
Beside the linked item the user can add local items and mix them with the linked ones. But the general structure is always determined by the linked in children.
Beside the subtree the ´iTree´-object can also contain a value. The value can be any type of Python objects that is stored in the tree-node (comparable with the value of a dictionary). If it is required by the user to calculate the hash of the íTree´ via ´hash(item)´ some value objects might not be hashable and will raise an exception. But as long as the objects can be pickled a hash replacement will be found in the hash of ´iTree´. E.g. a dict placed as a value makes no troubles even if teh user likes to hash the tree.
As a helper the ´iTree´-object can be coupled with other objects (which might be helpful if you have a displayed tree in a GUI that is connected with the ´íTree´. Be aware that this helper function has only temporary character. It is not stored when dumping (standard dump) or considered in comparisons, etc. The coupled object is ignored by all internal functionalities. Also in linked items the coupled object is not taken over from the link and can be set independent.
The behavior of a íTree´ object can be influenced by specific properties or flags:
Read-only tree: An ´iTree´ object where the subtree is protected and cannot be changed
Read-only value: An ´iTree´ object where the value is protected and cannot be changed
The ´iTree´ object contains a large number of properties which should help the user to reach the required information as comfortable as possible. Especially the tree related information might be interesting:
mytree.tag -> family-tag of the item
mytree.idx -> absolute index of the object
mytree.tag_idx -> key tuple (family-tag, family-index)
mytree.idx_path -> tuple of absolute indexes from the root to the item
mytree.tag_idx_path -> tuple of key-tuples from the root to the item
mytree.parent -> parent item of the item
mytree.root -> root item of the item (highest level parent)
mytree.pre_item -> pre item (the children in the parent that is before this item)
mytree.post_item -> post item (the children in the parent that is after this item)
mytree.level -> How deep the item is in the tree related to the root
mytree.max_depth -> How deep the sub-items (nested) of the ´iTree´ go in maximum (deep levels)
In case the ´iTree´ object is not part of another ´iTree´ (is root) those attributes will deliver in most cases ´None´.
mytree.is_root -> True in case the item is a root ´iTree´)no parent)
mytree.is_tree_read_only -> True in case the subtree is protected and read-only
mytree.is_value_read_only -> True in case the item value is protected and read-only
mytree.is_linked -> True in case the item is a linked item (read_only)
mytree.is_link_root-> True in case the item is a root for a link to another ´iTree´
mytree.link_root-> Delivers the related link-root in case the item is linked
mytree.value-> Delivers the value object stored in the ´iTree´ item
There are different ways to access the children and sub-children in the tree of a ´iTree´ object.
The standard access for single items is via ´itree_obj[target]´ ( ´__getitem__(target)´) call. As targets the user has different options:
index - absolute target index integer (fastest operation)
key - key tuple (family_tag, family_index)
tag or tag sets- family_tag object targeting a whole family
target-list - absolute indexes or keys to be replaced (indexes and keys can be mixed)
index slice - slice of absolute indexes
key slice - tuple of (family_tag, family_index_slice)
filter-method - method to filtering specific children
Beside the first level functions the iTree-object contains the helper class .deep which contains the in-depth functionalities targeting all the nested sub-children of the object.
As the name itertree should suggest a wide range of iteration methods are available in the class. They can be combined with different kind of filters.
Note
As optional filter_method-parameter the user can give:
None- filter inactive
Callable delivering True/False related to a characteristic of the ìTree-object (iterated items)
Beside this the internal filtering is normally a hierarchical filtering (If the parent does not match to the filter all children are excluded too, even that they match to the filter). Some methods contain a switch for non-hierarchical filtering too. But most often the non-hierarchical filtering can be realized via the build-in filter() method and in this case the switch is not available.
Here the power of the iterators is obvious because cascaded filter queries can be constructed and finally in only one full iteration over all the items is required to get the results back (sometimes the full iteration is not required).
It’s recommended to have a look into itertools package for better usage of the delivered iteration-generators.
The design of the ´iTree´´ object is made for best possible performance even that it is pure Python. Some part of the code might look less good readable or in the iteration-generators you find the if else outside the iteration functionality which is not realized via sub-functions we have here redundant codings. But its is made to avoid conditions or function calls inside the loops which would be bad for the performance.
- Parameters
tag (Hashable) – family tag of the iTree object (any hashable object)
value (object) – value to be stored in the iTree object
subtree (Optional[Iterable]) – Iterable or Iterator containing the subtree items or an argument list (internal functionality)
link (Optional[iTLink]) – iTLink object targeting another iTree
flags (int) –
flags taken from iTFLAG class:
iTFLAG.READ_ONLY_TREE - mark the subtree of this iTree as read-only the subtree will be protected from changes in this case
iTFLAG.READ_ONLY_VALUE - mark the value of this iTree object as read-only
iTFLAG.LOAD_LINKS - load the links during instance automatically
Multiple flags can be combined via |
-
__iter__
¶
-
property
parent
¶ Property delivers current items parent-object.
- Return type
Union[iTree, None]
- Returns
iTree parent-object or None (in case no parent exists)
-
property
is_root
¶ Is this item a root-item (has no parent)?
- Return type
bool
- Returns
True - is root
False - is not root
-
property
root
¶ property delivers the root-item of the tree
In case the item has no parent it will deliver itself
- Return type
- Returns
iTree root item
-
property
tag
¶ This is the access to the object-tag. The tag gives the relation to the tag-family in iTree-objects.
The tag is comparable with a key in dictionaries but in iTrees the tag is not unique! For unique iTree identification the tag_idx property must be used.
Any hashable object can be used as a tag, but in case “exotic” objects are used and serialization is required the user may have to extend the functionality of the serializer.
- Return type
Hashable
- Returns
tag - hashable object giving the family relation
-
property
idx
¶ Index of this object in the iTree (related to the absolute order)
Method is very important for internal functionalities
Note
In general the item index is cached but in case of deleted items or reorder operations the cache might be outdated. In this case the index update based on a search might take longer.
- Return type
Union[int, None]
- Returns
unsigned integer representing the index (related to absolute order of iTree)
-
property
idx_path
¶ delivers a list of absolute indexes from the root to this item
For items with no parent (root_item) an empty tuple will be delivered
Note
We deliver here a tuple because it might be helpful if the object is hashable (usage as a dict key)
- Return type
tuple
- Returns
tuple of index integers (here we do not deliver an iterator!)
-
property
tag_idx
¶ The tag_idx is a unique identification of the item. It is represented by a tuple containing the family-tag and the family related index of the item.
If the item is not part of a parent-tree (root-item) in this case the result will be None.
- Return type
Union[tuple, None]
- Returns
tuple (family-tag, family-index) or None (if item has no parent)
-
property
tag_idx_path
¶ The path is a tuple of tag_idx tuples from root to this item. Each tag_idx is a tuple containing the pair family-tag and family-index.
For items with no parent (rooot_item) an empty tuple will be delivered
Note
We deliver here a tuple because it might be helpful if the object is hashable (usage as a dict key)
- Return type
tuple
- Returns
tuple of key tuples containing family-tag and family-index
-
force_cache_update
(idx=True, fam_keys=True, all_keys=True)[source]¶ Forces the update of the index and keys in cache
Normally this is not required the methode is mainly used for testing proposes
- Parameters
idx – True - update absolute-indexes
fam_keys – True - update this items family-indexes
all_keys – True - update all families faimily-indexes
-
property
pre_item
¶ Delivers the pre-item (predecessor) of this object in the parent-tree. If self is first item or there is no parent None will be delivered.
- Return type
Union[iTree,None]
- Returns
iTree predecessor or None (no match)
-
property
post_item
¶ Delivers the post-item (successor) of this object in the parent-tree. If self is first item or there is no parent None will be delivered.
- Return type
Union[iTree,None]
- Returns
iTree successor or None (no match)
-
property
level
¶ Delivers the distance (number of levels) to the root-item of the tree. Or in other words how deep in tree the item is positioned. In case item has no parent (is a root-item) this method will deliver 0.
- Return type
int
- Returns
integer - number of levels (outer direction)
-
property
max_depth
¶ Relative from this item the method measures the maximum depth of the tree and delivers the maximum number of levels that are found in this object.
If the user wants to now the maximum depth of the whole tree ensure that the property of the root-item is read. The user might use my_tree.root.max_depth to ensure this.
- Return type
int
- Returns
integer maximal number of levels that exists in the tree (inner direction)
-
property
tag_number
¶ property contains the number of tags (families) the itree contains :return: integer
-
property
deep
¶ Subclass containing the deep access to the nested structures of iTree :return:
-
property
flags
¶ Give the flags value of the object. The integer value stored in this property contains the bit flags related to the constants iTFLAG or _iTFLAG.
To see the details the user might use bin() or the helper property flags_repr which delivers a string containing all set flags.
;rtype: int :return: The flags set for this item
-
flags_repr
(public_only=True)[source]¶ String representation of flags for this item
- Parameters
public_only (bool) –
True - Consider only the public flags (given by the user) -> default
False - Show all flags (also linked and placeholder flags)
;rtype: str :return: String repr of the flags set for this item
-
property
is_tree_read_only
¶ Is the tree protection flag set? In this case the tree structure cannot be changed
This property targets the tree structure not the value!
- Return type
bool
- Returns
False - subtree can be changed (writeable)
True - subtree is protected (read-only)
-
set_tree_read_only
()[source]¶ Set the tree protection flag. If the flag is set the subtree structure can not be changed anymore.
Warning
Setting the structural protection is always a deep operation. In all children and sub-children the protection flag will be activated too! But when unset the behavior it is not automatically made as a deep operation`. Here the differentiation in between the two methods unset_tree_read_only() and unset_tree_read_only_deep() exists.
-
unset_tree_read_only
()[source]¶ Unset the tree protection flag on the item. Only the children structure of this item is made writable by this operation.
- Except
If the parent contains the tree protection flag a PermissionError will be raised
-
property
is_value_read_only
¶ Is iTree value read_only? Is the value protection flag iTFLAG.READ_ONLY_VALUE is set?
- Return type
bool
- Returns
True - read-only protection of value active False - value is writeable
-
set_value_read_only
()[source]¶ Set the write protection of the value (set flag: iTFLAG.READ_ONLY_VALUE)
-
unset_value_read_only
()[source]¶ Unset the write protection flag of the value (set flag: iTFLAG.READ_ONLY_VALUE). Value will be writeable afterwards
-
property
value
¶ Delivers the full value object stored in the iTree-object
- Return type
object
- Returns
value-object of the item
-
set_value
(value)[source]¶ Set/replace the value content of the iTree-object.
The method returns the previous stored value object that was replaced by the operation.
Note
If an iTValueModel is stored as value in the iTree by default the set_value() method will target the value which is stored inside the model. If the model itself should be exchanged the user must give the new model as value parameter of this method. To replace the model with another Python object the user must first delete the model via del_value() command and afterwards set the new value.
- Parameters
value (object) – data-object that should be placed as value or in case we have a iTValueModel already as value it is placed inside the model.
- Return type
object
- Returns
old value object that was stored in iTree before
-
set_key_value
(key, value)[source]¶ Depending on the already stored object this operation is a sub-replacement of a part only.
The method returns the previous stored value object that was replaced by the operation.
The user can influence the behavior by giving the key parameter. And it depends on the already stored value object (e.g. a list or dict ). Only the value of the related item will be replaced or in case the item did not exist yet the might object will be extended by the given value ( dict only).
Depending on given key parameter and the already stored object we have the following possible behaviours:
dict stored in value -> store the value in the dict with the key given in key_index
dict stored in value and matching item-value is a iTValueModel -> replace value inside the model
list stored in value -> key_index must be an index and replace the related item in the list with the value given
list stored in value and matching (index) item-value is a iTValueModel -> replace value inside the model
key == INF and list stored in value -> append given value in the list
Note
If an iTValueModel is stored as value in the iTree by default the mytree.set_value()-method will target the value which is stored inside the model. If the model itself should be exchanged the user must give a new model as value parameter of this method. To replace the model with another Python object the user must first delete the model via del mytree.value[key] command and afterwards set the new value or he sets the value directly via mytree.value[key]==new_value .
- Parameters
key (Optional[Hashable,int]) – key or index of the value object (depends on the object already stored in iTree ). if key==INF the value will be appended in case a list-like object is already stored in the iTree-object.
value (object,) – value object that should be placed as value or in case a key is given the sub-value in the iTree or in case we have a iTValueModel is used inside the model.
- Return type
object
- Returns
old value object that was stored in iTree before
-
get_value
()[source]¶ Delivers the value-object of the item or a sub-value in case key_index parameter is used and a matching object is stored in the iTree .
Note
If iTValueModel is stored in iTree the method will not target the model it will target the value inside. If the model itself is required the value-property of iTree must be used.
- Except
In case a key_index is given but the object is not a dict or a list like object an AttributeError will be raised ( __getitem__()`required). If no matching item is found an `IndexError or KeyError will be raised.
- Return type
object
- Returns
value object the iTree or iTValueModel (in case a model is stored in the iTree )
-
get_key_value
(key)[source]¶ Delivers the value-object of the item or a sub-value in case key_index parameter is used and a matching object is stored in the iTree .
In case the stored value is a dict-like object the key will be used as the key of the dict. In case the stored value is a list-like object the keyx will be used as the index of the list.
In case the target value is a iTValueModel the value inside will be targeted and not the model itself.
Note
If iTValueModel is stored in iTree the method will not target the model it will target the value inside. If the model itself is required the value-property of iTree must be used.
- Except
In case a key_index is given but the object is not a dict or list like object an AttributeError will be raised ( __getitem__()-method required). If no matching item is found an IndexError or KeyError will be raised.
- Parameters
key (Optional[Hashable,int]) – Optional key or index parameter
- Return type
object
- Returns
value object the iTree or iTValueModel (in case a model is stored in the iTree)
-
del_value
()[source]¶ Deletes the full value-object stored in ´iTree´ ( ´NoValue´ is stored in iTree).
This method will always delete the whole object stored in iTree even iTValueModel-objects are deleted. To delete the value content of a model mytree.value.clear() or ‘set_value(NoValue)’ might be used.
- Returns
deleted value
-
del_key_value
(key)[source]¶ If no parameter is given deletes the full value-object stored in ´iTree´ (store ´NoValue´ ).
In case a key or index is given and the value contains a matching object we will only pop out the related sub-item.
This method will always delete the whole targeted object even iTValueModel-objects are deleted. To delete the value content of a model mytree.value.clear() or ‘set_value(NoValue)’ might be used.
- Except
In case a key is given but the object is not dict or list like a TypeError or AttributeError will be raised ( __delitem__()-method is targeted); If the given key does not exist or an invalid parameter is given a KeyError or IndexError will be raised.
- Parameters
key (Optional[Hashable,int]) – Optional key or index to exchange just sub-items in the value
- Returns
deleted value
-
property
coupled_object
¶ The iTree-object can be coupled with another Python-object. The pointer to the object is stored and can be reached via this property. (E.g. this can be helpful when connecting the iTree with a visual item (hypertree-list item) in a GUI)
- Returns
pointer to coupled-object or None if no object is stored
-
set_coupled_object
(coupled_object)[source]¶ Couple another Python-object with this iTree-object.
Compared with the value the coupled-object is not tracked by any internal functions. We do not consider it in any relation (e.g. __contains__() and do not dump it in files, etc. Even in linked items the coupled-object is not protected. And in copies it is ignored and not taken over.
Note
E.g. The coupled-object might be an object in a GUI that is related to this item.
- Parameters
coupled_object – object pointer to the object that should be coupled with this iTree item
-
append
(item=<class 'itertree.itree_helpers.NoValue'>)[source]¶ Append the given iTree-object to the iTree (new last child) The append() method is the fastest way to add a single item to the end of the tree.
- Except
In case iTree-object has already a parent a RecursionError will be raised Other exceptions might come up in case the iTree is protected (tree read-only mode).
- Parameters
item (Union[iTree,object]) –
iTree-object to be appended
Warning
In case the given item-object is not a iTree-object the item is interpreted as a value and the iTree will be created implicit (with tag-family NoTag) in the way:
iTree(tag=NoTag, value=item) ~ ìTree(value=item) If no item is given an empty iTree is created tag=`NoTag`; value=`NoValue`.
>>> root=iTree('root') >>> root.append('myvalue') iTree(value='myvalue') >>> root.append() # append an empty iTree-object iTree()
- Return type
- Returns
Delivers the appended item itself (it might be useful for the user to get the updated information of the object).
-
appendleft
(item=<class 'itertree.itree_helpers.NoValue'>)[source]¶ Append the given iTree-object to the left of the parent-tree (new first child) The appendleft() method is the recommended method to add a new first item to iTree (quicker than insert(0,item) ). Compared to append() the method is slower and the cache index information gets invalid after the operation (will be automatically updated later on if required).
- Except
In case iTree-object has already a parent a RecursionError will be raised. Other exceptions might come up in case the iTree is protected (tree read-only mode).
- Parameters
item (Union[iTree,object]) –
iTree-object to be appended as first item.
Warning
As in append() in case the given item-object is not a iTree-object the item is interpreted as a value and the iTree will be created implicit.
- Return type
- Returns
Delivers the appended item itself (it might be useful for the user to get the updated information of the object).
-
insert
(target, item=<class 'itertree.itree_helpers.NoValue'>)[source]¶ Insert an item before a given target-position. The insertion works like in lists.
The insertion operation is slower as the append operations.
If target=None is given the operation inserts in the last position (== append()).
- Except
In case iTree-object has already a parent a RecursionError will be raised Other exceptions might come up in case the iTree is protected (tree read-only mode).
- Parameters
target (Union[Integer,tuple,iTree,None]) –
target position definition; target must target a single/unique item! Possible targets:
index - absolute target index integer, negative values supported too (count from the end).
key - key-tuple (family_tag, family_index) pair
item - iTree-item that is already a children (future successor)
None - if None is given we will append the item in the last position of the ´iTree´-object
item (Union[iTree,object]) –
iTree-object to be inserted in the tree.
Warning
As in append() in case the given item-object is not a iTree-object the item is interpreted as a value and the iTree will be created implicit.
- Return type
- Returns
Delivers the inserted item itself (it might be useful for the user to get the updated information of the object).
-
extend
(items)[source]¶ We extend the iTree with given items (multi append). The function is high performant and if you have to append a large number of items it is recommended to create an iterator of the items and feed them into this method. This is quicker compared to a loop doing multiple normal append() operations.
Note
In case the to be extended items have already a parent an implicit copy will be made. We do this because the internal copy can be created more effective. We accept also iTree-objects as extend_items parameter and the children which have a parent will be automatically copied to be integrated in this second tree. We have the same situation with a filtered iterator which might be used to extend this iTree too.
- Parameters
items (Iterable) –
iterable-object that contains iTree-objects as items it can be:
iterator or generator of iTree-objects (using next)
iTree-object (children will be copied and extended in this tree)
iterable of iTree-objects (list, tuple, …)
argument list for iTree-instance ( ´__init__()´ ) (created by ´get_init_args()´ or ´get_init_args_deep()´ ) -> this is most often an internal functionality.
iterator or generator of value-objects (using next) - implicit iTree-objects created
iterable of value-objects (list, tuple, …)- implicit iTree-objects created
-
extendleft
(items)[source]¶ Multy item append on left hand-side (at the beginning) of the ´iTree´.
The operation is slower than ´extend()´ because it requires a reordering of all items in the iTree.
Note
The order of extended items is kept in the operation. It’s comparable with: ´[1,2,3]+[4,5,6]=[1,2,3,4,5,6]´ but the result is not a new instance, self is kept.
Note
In case the to be extended items have already a parent an implicit copy will be made. We do this because the internal copy can be created more effective. We accept also iTree-objects as extend_items parameter and the children which have a parent will be automatically copied to be integrated in this second tree. We have the same situation with a filtered iterator which might be used to extend this iTree too.
- Parameters
items (Iterable) –
iterable-object that contains iTree-objects as items it can be:
iterator or generator of iTree-objects (using next)
iTree-object (children will be copied and extended in this tree
iterable of iTree-objects (list, tuple, …)
argument list for iTree-instance ( ´__init__()´ ) (created by ´get_init_args()´ or ´get_init_args_deep()´ )
iterator or generator of value-objects (using next) - implicit iTree-objects created
iterable of value-objects (list, tuple, …)- implicit iTree-objects created
-
__setitem__
(target, value)[source]¶ Replace an item with the given new item given in the value-parameter. The method handles also multiple replaces (rearrangements) like:
>>> mytree[1],mytree[0]=mytree[0],mytree[1]
Warning
Because of the parent only principle in rearrangements operations an implicit copy might be created.
Note
Linked items cannot be changed. If changes are required The user must change the link source tree items and afterwards actively rerun load_links() to reload the linked tree.
- Except
In case the target is not found or the iTree is protected (read-only tree).
- Parameters
target –
target object defining the replacement target; possible types are:
index - absolute target index integer (fastest operation)
key - key tuple (family_tag, family_index)
tag - Tag(family_tag) object targeting a whole family
target-list - absolute indexes or keys to be replaced (indexes and keys can be mixed)
index slice - slice of absolute indexes
key slice - tuple: (family_tag, family_index_slice)
For multi targets the given value must have a matching structure (item list with same length).
We have two special targets which are used for placing/replacing single items in the iTree:
Ellipsis … - new_items tag-family will be deleted and the new-item is placed in families first item position
items_tag - new_items tag-family will be delted and the new-item is placed in families last item position
If those two special targets are used and the new-items family does not exist yet, the method will just append the new item, no exception will be raised.
value – iTree object that should replace the target or in case of multi targets a tuple of items that should be used for replacements
- Returns
value added items (only for internal usage)
-
move
(target=None)[source]¶ Move this item in given target position (item will be positioned before the given target). The given target must be a unique item! If None is given the item will be moved in the last position of the iTree. If an ìTree`-object is given as target it must be a children of the same parent (sibling).
- Except
LookupError in case the target is not found or not unique!
- Parameters
target (Union[Integer,tuple,iTree,None]) –
target-object defining the replacement target; possible types are:
index - absolute target index integer, negative values supported too (count from the end).
key - key-tuple (family_tag, family_index) pair
item - iTree-item that is already a children (future successor)
None - if None is given we will move the item to the last position in the ´iTree´-object
- Returns
self (with updated indexes)
-
rename
(new_tag)[source]¶ give the item a new family tag
The renaming of the item implies a reordering of the items in the tree because the family order depends on the global/absolute order of items.
- Parameters
new_tag (Hashable) – new tag (any kind of hashable object)
- Return type
- Returns
Delivers the renamed item itself (it might be useful for the user to get the updated information of the object).
-
reverse
()[source]¶ Reverse the order of all children in the iTree.
If you do not want to change the object itself (in place operation) you might use the iterator reversed() instead.
-
rotate
(n=1)[source]¶ Rotate children of the iTree-object n times (n positions) (rotate 1 times means move last item to first position)
If no parameter is given we rotate by one position only.
The rotation can be made in negative direction too (give negative numbers).
In case zero is given the operation is neutral and nothing will be changed.
Note
There is no in-depth counterpart of this method available.
- Parameters
n (integer) – number of positions the items should be rotated
-
sort
(key=None, reverse=False)[source]¶ Sorting operation -> same behavior as sort of lists (parameter description is taken from list documentation).
Note
This is an “in place” operation which changes the content of the object the build-in sorted() might be use instead (if the original object should not be changed):
>>> a=iTree(subtree=[iTree(3),iTree(2),iTree(4),iTree(1)]) >>> a.render() iTree() > iTree(3) > iTree(2) > iTree(4) > iTree(1) >>> b=iTree(subtree=(a[i] for i in sorted(a.keys()))) iTree() > iTree(1) > iTree(2) > iTree(3) > iTree(4)
Internally in this operation a copied sorted list is created, and afterwards the whole structure is cleared and rebuild based on the sorted list.
The default-operation is to the sort based on the list of keys (tag-family, family_index) pair of the items. The base of the sorting can be modified by changing the target_type parameter.
- Parameters
key – specifies a function of one argument that is used to extract a comparison key from each list element (for example, key=str.lower). The key corresponding to each item in the list is calculated once and then used for the entire sorting process. The default value of None means that list items are sorted directly without calculating a separate key value.
reverse – is a boolean value. If set to True, then the list elements are sorted as if each comparison were reversed.
-
__delitem__
(target)[source]¶ The function deletes the targeted item in the tree.
- Except
In case the target is not found or the iTree is protected (read-only tree).
- Parameters
target (Union[int,tuple,Hashable,Iterable,slice]) –
target object defining the replacement target; possible types are:
index - absolute target index integer (fastest operation)
key - key tuple (family_tag, family_index)
tag - Tag(family_tag) object targeting a whole family
target-list - absolute indexes or keys to be replaced (indexes and keys can be mixed)
index-slice - slice of absolute indexes
key-slice - tuple of (family_tag, family_index_slice)
itree_filter - method (callable) for filtering the children of the object
- Returns
deleted item
-
clear
(keep_value=False, local_only=False)[source]¶ deletes all children and the value!
All flags stay unchanged, except the load_links flag!
- Parameters
keep_value (bool) –
True - value is not deleted
False - value will be replaced with NoValue
local_only (bool) –
True - clear only the local items
False - clear whole object (The object is reset to the no links loaded state and locals are deleted)
-
pop
(target=- 1)[source]¶ pop the item out of the tree, if no key is given the last item will be popped out
We do not have the method popleft because pop(0) does the same.
- Parameters
target (Union[int,tuple,Hashable,Iterable,slice,iTree]) –
target of popped item(s):
index - absolute target index integer (fastest operation)
key - key tuple (family_tag, family_index)
tag - Tag(family_tag) object targeting a whole family
target-list - absolute indexes or keys to be replaced (indexes and keys can be mixed)
index-slice - slice of absolute indexes
key-slice - tuple of (family_tag, family_index_slice)
itree_filter - method (callable) for filtering the children of the object
- Returns
popped out item(s) (parent will be set to None). In case multiple items are removed an iterator over the removed items is given.
-
remove
(item)[source]¶ With remove the given target is a iTree child that should be removed.
The method is only in because we like to be compatible with lists interface but the pop method target allows already to use a child as a target too.
- Except
If given item is not a child of the parent or the ìTree`-objects tree is protected
- Parameters
item (Union[iTree,Iterable]) – Child or iterable of children to be removed from the tree
- Returns
removed item(s) (parent will be set to None) - in case of multiple removes the method delivers a list no iterator because anyway a list is created
-
__getitem__
(target)[source]¶ Main common get method for children (first level items).
In case the given targets is a absolute index or a key (tag,family-index) pair the method will deliver a unique item back. This operation is prioritized over the other operations.
For all other targets the method will deliver a list with the targeted items as result.
In some cases an empty list might be delivered and no exception might be raised (e.g. filter query delivers no match).
In case user likes to have other return-types he might check the other available get methods ( get(), get.single(), get.iter()) or he might also use the itertree helper method getter_to_list() to convert any of the possible results into a list.
- Except
In case of no match (even if a part is not matching (e.g. one index in an index-list) the method will raise a KeyError (no matching target given); IndexError (no matching index given) or ValueError (no valid type of target given).
- Parameters
target (Union[int,tuple,list,slice]) –
target object targeting a child or multiple children in the ´iTree´. Possible types are:
index - absolute target index integer (fastest operation)
key - key tuple (family_tag, family_index)
index-slice - slice of absolute indexes
key-index-slice - tuple of (family_tag, family_index_slice)
target-list - absolute indexes or keys to be replaced (indexes and keys can be mixed)
key-index-list - tuple of (family_tag, family_index_list)
tag - family_tag object targeting a whole family
tag-set - a set of family-tags targeting the items of multiple families
itree_filter - method (callable) for filtering the children of the object
all-children - if build-in iter or …`(Ellipsis) is given a list of all children will be given (same like list(itree.__iter__()))
- Return type
Union[iTree,list]
- Returns
Target was index or key -> one iTree item will be given; for all other targets a list will be delivered.
-
copy_keep_value
()[source]¶ Create a copy of this item.
The difference in between normal copy() and this method is that the value objects are completely untouched in this operation (for immutable objects there is no difference in between the two copy operations).
- Returns
copied iTree object
-
copy
(*args, **kwargs)[source]¶ create a copy of this item
The difference in between copy() and deepcopy() for iTree is just that we do in deepcopy() a deepcopy of all value items. In copy() we just copy the value object not the items inside, the pointers to the original objects are kept (for immutable objects there is no difference).
- Returns
copied iTree object
-
deepcopy
(*args, **kwargs)[source]¶ create a deepcopy of this item
The difference in between copy() and deepcopy() for iTree is just that we do in deepcopy() a deepcopy of all value items. In copy() we just copy the value object not the items inside, the pointers to the original objects are kept (for immutable objects there is no difference).
- Returns
deep copied new iTree object
-
filtered_len
(filter_method)[source]¶ Calculates the number of filtered children.
- Parameters
filter_method (Callable) – filter method that checks for matching items and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches (see filter_method)
- Return type
int
- Returns
Number of matching items found
-
is_tag_in
(tag)[source]¶ Checks if a iTree contains the given family-tag (first-level only) :param tag: family tag :return: True/False
-
is_in
(item)[source]¶ Checks if the given object is child of the iTree. Different to ´__contains__()´ we check here for the instance (specific) object (is) and not based on ´__eq__()´.
- Parameters
item – iTree object to be searched for
- Returns
True - matching child is found
False - no matching item found
-
__eq__
(other)[source]¶ compares if the tag, value and children content of another item matches with this item
Note
If you like to check if it is really the same object you should use ´is´ instead of ´==´ operator
- Parameters
other – other iTree
- Returns
boolean match result (True match/False no match)
-
equal
(other, check_coupled=False, check_flags=False)[source]¶ compares if the data content of another item matches with this item
- Parameters
other – other iTree
check_coupled – check the couple object too? (Default False)
check_flags – check the flags of the objects? (Default False)
- Returns
boolean match result (True match/False no match)
-
count
(item)[source]¶ Counts how many equal (==) children are in the iTree-object.
- Parameters
item (iTree) – The iTree-items will be compared with this item
- Return type
int
- Returns
Number of matching items found
-
index
(item, start=None, stop=None)[source]¶ The index method allows to search for the absolute index of a matching item in the iTree. The item must be a iTree object and the index will deliver the first match. The comparison is made via == operator.
If item is not found a IndexError will be raised
Note
To get the index of a specific item instance the .idx- property should be used.
- Parameters
item (iTree) – iTree object to be searched for
start (Union[iTree,target_path]) – iTree item or start target_path where index search should be started (start item is included in search)
stop (Union[iTree,target_path]) – iTree item or stop target_path where index search should be stopped (stop item is not included in search)
;rtype: int :return: absolute index of the found item
-
keys
(filter_method=None)[source]¶ Iterates over all children and deliver the children tag-idx tuple (family-tag,family_index)
Note
This is a dict like iterator that delivers the unique keys for all children.
- Parameters
filter_method (Union[Callable,None]) –
filter method that checks the item and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches
If None is given filtering is inactive.
- Return type
Iterator
- Returns
iterator over the tag-idx of the children
-
values
(filter_method=None)[source]¶ Iterates over all children and deliver the children values
- Parameters
filter_method (Union[Callable,None]) –
filter method that checks for matching items and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches (see filter_method)
If None is given filtering is inactive.
- Return type
Iterator
- Returns
iterator over the values stored in the children
-
items
(filter_method=None, values_only=False)[source]¶ Iterates over all children and deliver the children item-tuples (key,item) or (key,value). As key we use the unique tag-idx: (tag-family,family-index).
The function is comparable with dicts items() function.
- Parameters
filter_method (Union[Callable,None]) –
filter method that checks for matching items and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches (see filter_method)
If None is given filtering is inactive.
values_only (bool) –
False (default) - in the key,value tuple the iterator put the iTree object as value in
True - in the key,value tuple the iterator put “only” the value object of the iTree-object in
- Return type
Generator
- Returns
iterator over the target keys and item value of the children
-
iter_families
(filter_method=None, order_last=False)[source]¶ This is a special iterator that iterates over the families in iTree. It delivers per family the tag and a list of the containing items. The order is defined by the absolute index of the first item in each family
Method will be reached via iTree.Families.iter()
- Parameters
filter_method (Union[Callable,None]) –
filter method that checks for matching items and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches (see filter_method)
If filter_method is None no filtering is performed
Note
An internal filtering is available because this may change the order of the delivered items. An external filter with same method might deliver a different result!
order_last (bool) –
False (default) - The tag-order is based on the order of the first items in the family
True - The tag-order is based on the order of the last items in the family
- Return type
Generator
- Returns
iterator over all families delivers tuples of (family-tag, family-item-list)
-
iter_family_items
(order_last=False)[source]¶ This is a special iterator that iterates over the families in iTree. It iters over the items of each family the ordered by the first or the last items of the families.
- Parameters
order_last (bool) –
False (default) - The tag-order is based on the order of the first items in the family
True - The tag-order is based on the order of the last items in the family
- Return type
Generator
- Returns
iterator over all families delivers tuples of (family-tag, family-item-list)
iters over all family-tags in level 1 (children). The order is based on first or last item in the family.
- Parameters
order_last (bool) –
False (default) - The tag-order is based on the order of the first items in the family
True - The tag-order is based on the order of the last items in the family
- Return type
Iterator
- Returns
tag iterator
-
renders
(filter_method=None, enumerate=None, renderer=<class 'itertree.itree_serializer.itree_renderer.iTreeRender'>)[source]¶ render the iTree into a string
- Parameters
filter_method (Union[Callable,None]) –
filter method that checks for matching items and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches (see filter_method)
If None is given filtering is inactive.
The method uses the given filter always as an hierachical filter.
enumerate (bool) –
True - Add an enumeration before the items
False (default) - Output without enumeration
renderer (class) – Give another renderer class for different formatting
- Return type
str
- Returns
Tree representation as string
-
render
(filter_method=None, enumerate=False, renderer=<class 'itertree.itree_serializer.itree_renderer.iTreeRender'>)[source]¶ Print the rendered string of the iTree-object to the console (stdout).
- Parameters
filter_method (Union[Callable,None]) – filter method that checks for matching items and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches. If None is given filtering is inactive.
enumerate – add an enumeration before the rendered items
renderer – Render to be used (The given render is stored and will be used until another renderer is given).
- Returns
-
get_init_args
(filter_method=None, _subtree_not_none=True)[source]¶ Method creates list of arguments that can be used as a pointer to create an equal instance of an iTree object. This is a method is used in most cases for internal functionalities (especially copy()).
- Parameters
filter_method (Union[Callable,None]) –
filter method that checks for matching items and delivers True/False. The filter_method targets always the iTree-child-object and checks a characteristic of this object for matches (see filter_method)
If None is given filtering is inactive.
_subtree_not_none – internal parameter controlling if the subtree is added or not
- Returns
-
loads
(data_str, check_hash=True, load_links=True, itree_serializer=<class 'itertree.itree_serializer.itree_json_serialize.iTStdJSONSerializer2'>)[source]¶ create an iTree object by loading from a string
If not overloaded or reinitialized the iTree Standard Serializer will be used. In this case we expect a matching JSON representation.
- Parameters
data_str – source string that contains the iTree information
check_hash – True the hash of the file will be checked and the loading will be stopped if it doesn’t match False - do not check the iTree hash
load_links – True - linked iTree objects will be loaded
itree_serializer – optional user defined serializer for iTree objects
- Returns
iTree object loaded from file
-
load
(file_path, check_hash=True, load_links=True, itree_serializer=<class 'itertree.itree_serializer.itree_json_serialize.iTStdJSONSerializer2'>)[source]¶ create an iTree object by loading from a file
If not overloaded or reinitialized the iTree Standard Serializer will be used. In this case we expect a matching JSON representation.
- Parameters
file_path – file path to the file that contains the iTree information
check_hash – True the hash of the file will be checked and the loading will be stopped if it doesn’t match False - do not check the iTree hash
load_links – True - linked iTree objects will be loaded
itree_serializer – optional user defined serializer for iTree objects
- Returns
iTree object loaded from file
-
dumps
(calc_hash=False, filter_method=None, itree_serializer=<class 'itertree.itree_serializer.itree_json_serialize.iTStdJSONSerializer2'>)[source]¶ serializes the iTree object to JSON (default serializer)
- Parameters
calc_hash – Tell if the hash should be calculated and stored in the header of string
itree_serializer – optional user defined serializer for iTree objects
- Returns
serialized string (JSON in case of default serializer)
-
dump
(target_path, pack=True, calc_hash=True, overwrite=False, filter_method=None, itree_serializer=<class 'itertree.itree_serializer.itree_json_serialize.iTStdJSONSerializer2'>)[source]¶ serializes the iTree object to JSON (default serializer) and store it in a file
- Parameters
target_path – target path of the file where the iTree should be stored in
pack – True - data will be packed via gzip before storage
calc_hash – True - create the hash information of iTree and store it in the header
overwrite – True - overwrite an existing file
itree_serializer – optional user defined serializer for iTree obbjects
- Returns
True if file is stored successful
-
property
is_placeholder
¶ Property shows that item is a placeholder class
Normally there should be no placeholder class in the iTree but in case a loaded link does no more contain the expected items it might happen that such a class artifact is still in the tree. In placeholders the value contains the family index in the linked class.
- Return type
bool
- Returns
True/False
-
property
is_link_cover
¶ If the item is local and covers a linked item the property is True
- Return type
bool
- Returns
True/False
-
property
is_linked
¶ In contrast to iTreeLinked class this is False
- Return type
bool
- Returns
True/False
-
property
is_link_loaded
¶
-
property
link_root
¶ delivers the highest level item that is linked in case item is not linked it delivers itself
- Return type
- Returns
highest level linked item found in the parents
-
property
is_link_root
¶ property that marks the iTree item as an item that contains a link
- Returns
True - is a link root item
False is no iTree link item
-
load_links
(force=False, delete_invalid_items=False, _items=None, _depth=0)[source]¶ Runs ove all children and sub children in case a ITreeLink object is found the linked items are load in
In case ´iTree´ is link root: load all linked items
- Parameters
force –
False (default) - load only if not already loaded
True - load even if already loaded (update)
delete_invalid_items –
False (default) - in case of invalid items we will raise an exception!
True - invalid items will be removed from parent no exception raised
_items – internal list parameter used for recursive calls of the function
_depth – Internal parameter related to current item depth
- Returns
True - success
False - load failed
-
make_local
(copy_subtree=True)[source]¶ make the current linked object a local object This is only possible if the parent is a iTree object is the link root-> only the first level children in a linked iTree can be made local The operation raises an SyntaxError in case it is used on a deeper level of the linked tree
- Returns
None
-
getitem_by_idx
¶
-
get
¶
-
itertree subclasses available in main¶
.get¶
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the specific get methods for the iTree object
The specific getters are quicker compared with the common ones we have in iTree (__getitem__(); get(); get_single())
.deep¶
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the main iTree object
itertree data classes¶
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the helper functions related to the iTree data attribute
-
class
itertree.itree_data.
iTValueModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
abc.ABC
This is the replacement for the old iTDataModel()-class.
This class can be used to define data models for the values that might be placed in the iTree.
The model should define min more detail which value objects are accepted or not and it defines also how not matching objects are handled:
Deny the value and raise a ValueError exception
Cast the value into a valid value object
But the definition of the data model allows limitations which goes far away from just data-type related topics. E.g. In the model the user can limit numerical values to a specific range (interval) or he might limit strings to specific characters.
All definitions related to checks and type casts must be defined by the user by overwriting the method check_and_cast_single_item(value_item) . The return of the method must e the checked and cast value. if the value does not match the method should raise a ValueError .
The method should always check and cast a single item, this is important. In case a list or an array like value should be stored in the model the base model will manage the required iteration over the sub-items and perform and utilize the single item check via the user defined method.
Note
In case a value like [1,2,3,45] is given each item in the list will be checked and/or casted.
This leads us to an important second definition functionality related to the model related to the size of dimensions (shape) of the value stored in the model. The definition of the shape is given as a parameter when the object is instanced. For the shape we expect a tuple with the dimension information. If a value object is given the maximum shape will be calculated and this will be compared with the expected one. The maximum is used because in nested lists the user can define sub-list with different length. Strings or bytes aare also seen as arrays in this case!
We have the following possibilities to define shapes:
shape=Any -> accept any shape of the given value (no check performed)
shape=tuple() -> empty tuple given no dimension expected model will accept single values only!
shape=(Any,) -> tuple containing one element which is the Any helper class; We will accept single values or any 1 dimensional object here (e.g. values like: 1; ‘abc’; [1,2,3,4] )
shape=(10,) -> tuple containing one element. We expect one dimensional values with a length lower or equal to the given integer number
shape=(INF,) -> tuple containing one element that is INF (infinite). We expect one dimensional values of any length
shape=(3,4) -> Two dimensions expected with fixed size (e.g. [[1],[2,3]] would match)
shape=(INF,4) -> Two dimensions expected with first length unlimited and second length limited to 3
shape=(4,ANY) -> Minimum one dimensions expected with first length limited to 4; here the user can also put infinite dimensions in (e.g [1]; [[1],[2]] ; [[[[888],[202,500]]]] would fit)
shape=(4,ANY,INF) -> 1 dimension or 3 dimensions accepted, 2 dimension will not be accepted
Note
The model base object iTValueModel() contains two checking levels. First the user defined check via method definition for checks and casts of single items given. In second step the model also checks the dimension (shape) of the given value.
In case a str or bytes objects are given the behavior related to the checks will be a bit different as for the other objects. The method check_and_cast_single_item(value_item) will target the whole string as a single item! But the shape check will be done also on the string as an object with a length.
This means a string is a 1 dimensional object and the user might limit the size of the string via a shape. (E.g.: The object “Hello” has the shape: (5,); the object [‘one’, ‘two’,’three’] has the shape: (3,5) ) The user might use the method ‘get_max_shape()’ to measure the shape of objects that is considered in the model base class.
During the instance of the object a formatter can be defined too. This might help the user e.g. do define if an integer value should be converted to a hex or binary representation during string conversion. The build-in command str() of this model class will deliver the formatted value only. The repr() will deliver the class definition.
To use the model the user should put the instanced model object as value in the iTree. The real value objects can be placed during object instance via the parameter value or later on via the set() method of the model (value exchange too). In case the value is not matching to the model definition an ValueError exception will be raised. If the user like to test first if the value is matching he can use the in keyword to check this. In case of no match the exception content might be picked via the last_exception property of the model in this case (might give a hint why the value is not accepted).
Standard Parameters:
- Parameters
value – value object to be stored in the model (must match to the model). In case no value is stored in the model (empty model) the value will be NoValue.
description – Description string
shape –
Define the dimensions the object should have:
None - shape is ignored object might have dimensions or not
tuple() - empty tuple or iterable - value object will have no size/dimension
(InfShape) - one dimensional value object with infinite size
one dimensional value object with max size of 100 items
(100,100) - two dimensional object with max size of 100 in each dimension
(InfShape,InfShape,InfShape) - three-dimensional object with infinite size in each dimension
…
Note
For multi-dimensional objects it’s recommended to use numpy arrays or objects which have the attribute shape representing the size for each dimension available instead of tuples or lists. If not the object performance might be worse (internal iterations required to measure the shape).
formatter – Formatter for the single item of the value object (see string formatting in python) In case no formatter is given str() will be used for creation of the item string representation.
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
set
(value)[source]¶ Set the value of the model in case the value does not match a ValueError exception will be raised
- Parameters
value – value to be placed inside the model
- Returns
old value stored in the model
-
get
()[source]¶ get the value that is placed inside the model
If no value is stored in the model the NoValue-object will be given back
- Returns
value stored in the model
-
property
value
¶ property delivering the value stored in the model
- Returns
value stored in the model
-
property
description
¶ optional description of the model
- Returns
description related to the model
-
set_description
(description)[source]¶ set/exchange the description of the model
- Parameters
description –
- Returns
old description
-
property
formatter
¶ get the formatter stored in the model
- Returns
formatter object
-
set_formatter
(formatter)[source]¶ set the formatter of the object
- Parameters
formatter – The formatter can be a callable method that delivers a str object or a string that contains teh formatting info
- Returns
old formatter
-
property
contains
¶ contains object stored in the model :return:
-
property
last_except
¶ get the last exception
- Returns
last exception raised by the model related the storage or check of a value
-
property
is_iTValueModel
¶ used for model identification
- Returns
True
-
get_init_args
(full=False, clear=False)[source]¶ deliver all initial arguments used to instance this model object
- Parameters
full – True give always full list False (default) list is shortened in case of default parameter values
clear – True - use NoValue object as value (ignore stored value) False - stored value is included in parameter tuple
- Returns
Tuple of initial parameters
-
class
itertree.itree_data.
iTAnyValueModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
Model that will take any python object without any restrictions
-
class
itertree.itree_data.
iTRoundIntModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
Model that would store integer values The model accepts any object that can be casted into a float and rounded to an integer to be stored as a int in the model
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
class
itertree.itree_data.
iTIntModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
This integer model allows only integers or strings containing a decimal integer to be stored in the model as int value
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
class
itertree.itree_data.
iTInt8Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
Integer model that limits the given values to int8 values
-
interval
= mSetInterval(mSetItem(-128), mSetItem(127))¶
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
get_init_args
(full=False, clear=False)[source]¶ deliver all initial arguments used to instance this model object
- Parameters
full – True give always full list False (default) list is shortened in case of default parameter values
clear – True - use NoValue object as value (ignore stored value) False - stored value is included in parameter tuple
- Returns
Tuple of initial parameters
-
-
class
itertree.itree_data.
iTUInt8Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTInt8Model
Integer model that limits the given values to uint8 values
-
interval
= mSetInterval(mSetItem(0), mSetItem(255))¶
-
-
class
itertree.itree_data.
iTInt16Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTInt8Model
Integer model that limits the given values to int16 values
-
interval
= mSetInterval(mSetItem(-32768), mSetItem(32767))¶
-
-
class
itertree.itree_data.
iTUInt16Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTInt8Model
Integer model that limits the given values to uint16 values
-
interval
= mSetInterval(mSetItem(0), mSetItem(65535))¶
-
-
class
itertree.itree_data.
iTInt32Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTInt8Model
Integer model that limits the given values to int32 values
-
interval
= mSetInterval(mSetItem(-2147483648), mSetItem(2147483647))¶
-
-
class
itertree.itree_data.
iTUInt32Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTInt8Model
Integer model that limits the given values to uint32 values
-
interval
= mSetInterval(mSetItem(0), mSetItem(4294967295))¶
-
-
class
itertree.itree_data.
iTInt64Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTInt8Model
Integer model that limits the given values to int64 values
-
interval
= mSetInterval(mSetItem(-9223372036854775808), mSetItem(9223372036854775807))¶
-
-
class
itertree.itree_data.
iTUInt64Model
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTInt8Model
Integer model that limits the given values to uint64 values
-
interval
= mSetInterval(mSetItem(0), mSetItem(18446744073709551615))¶
-
-
class
itertree.itree_data.
iTFloatModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
Float model that allows any float or string that can be casted to float to be stored in the model as float value
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
class
itertree.itree_data.
iTStrModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
A model to store a string
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
class
itertree.itree_data.
iTStrFnPatternModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, pattern=None, formatter=None)[source]¶ Bases:
itertree.itree_data.iTStrModel
A model to store a string that matches to the fnmatch pattern
-
property
pattern
¶
-
get_init_args
(full=False, clear=False)[source]¶ deliver all initial arguments used to instance this model object
- Parameters
full – True give always full list False (default) list is shortened in case of default parameter values
clear – True - use NoValue object as value (ignore stored value) False - stored value is included in parameter tuple
- Returns
Tuple of initial parameters
-
property
-
class
itertree.itree_data.
iTStrRegexPatternModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, pattern=None, formatter=None)[source]¶ Bases:
itertree.itree_data.iTStrModel
A string model that matches to the regex pattern
-
property
pattern
¶
-
get_init_args
(full=False, clear=False)[source]¶ deliver all initial arguments used to instance this model object
- Parameters
full – True give always full list False (default) list is shortened in case of default parameter values
clear – True - use NoValue object as value (ignore stored value) False - stored value is included in parameter tuple
- Returns
Tuple of initial parameters
-
property
-
class
itertree.itree_data.
iTASCIIStrModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
A string model that accepts only ASCII characters
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
class
itertree.itree_data.
iTUTF8StrModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTValueModel
A string model that accepts only UTF-8 characters
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
class
itertree.itree_data.
iTUTF16StrModel
(value=<class 'itertree.itree_helpers.NoValue'>, description=None, shape=<class 'itertree.itree_helpers.Any'>, contains=None, formatter=<class 'str'>)[source]¶ Bases:
itertree.itree_data.iTStrModel
A string model that accepts only UTF16 characters
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
class
itertree.itree_data.
iTEnumerateModel
(value=<class 'itertree.itree_helpers.NoValue'>, enumerate_dict={})[source]¶ Bases:
itertree.itree_data.iTValueModel
-
check_and_cast_single_item
(value_item)[source]¶ method that should be overwritten in the user models
Depending on the requirements the input value might be casted in a target type and he can be checked before or afterwards against check criteria for matches. In case of no match a ValueError should be raised
- Except
Raise ValueError in case given value does not match
- Parameters
value_item – The value given to the model
- Returns
casted and checked value
-
-
exception
itertree.itree_data.
iTDataValueError
[source]¶ Bases:
ValueError
Exception to be raised in case a validator finds a non matching value related to the iDataModel
-
exception
itertree.itree_data.
iTDataTypeError
[source]¶ Bases:
ValueError
Exception to be raised in case a validator finds a non matching value type related to the iDataModel
-
class
itertree.itree_data.
iTDataModel
(value=<class 'itertree.itree_helpers.NoValue'>)[source]¶ Bases:
abc.ABC
The default iTree data model class This the interface definition for specific data model classes that might be created using this superclass
The data model checks the given value for a specific data item. So that we can ensure that the given value matches to the expectations. We can check for types, shapes (length), limits, or matching patterns.
Besides the check we can also define a default formatter for the value that is used when it is translated into a string.
(see examples/itree_data_examples.py)
-
property
is_empty
¶ tells if the iTreeDataModel is empty or contains a value :return:
-
property
is_iTDataModel
¶
-
set
(value)[source]¶ put a specific value into the data model
- Except
raises an iTreeValidationError in case a not matching object is given
- Parameters
value – value object to be placed in the data model
-
property
value
¶ the stored value :return: object stored in value
-
check
(value)[source]¶ put a specific value into the data model
- Except
raises an iTreeValidationError in case a not matching object is given
- Parameters
value – value object to be placed in the data model
-
clear
()[source]¶ clears (deletes) the current value content and sets the state to “empty”
- Returns
returns the value object that was stored in the iTreeDataModel
-
abstract
validator
(value)[source]¶ This method should check the given value.
It should raise an iDataValueError Exception with a failure explanation in case the value is not matching to the iDataModel.
- ..warning:: The validator in an explicit iDataModel class must always return the value itself and it must raise
the iDataValueError in case of a no matching value. It should also call the super().validator() method or at least consider that NoValue is a no matching value.
- Except
iDataValueError in case value is not matching
- Parameters
value – to be checked against the model
- Returns
value (which might be casted)
-
abstract
formatter
(value=None)[source]¶ The formatter function allows us to create a specific string representation
Especially in case of numerical values this is interesting. You can define here that an integer should be represented always as hex, bin, … or for floats you can give digits.
The formatter can be created by using the classical format options of string but for enumerations we can put here also a table, etc.
- Returns
string representing the value
-
property
-
class
itertree.itree_data.
iTDataModelAny
(value=<class 'itertree.itree_helpers.NoValue'>)[source]¶ Bases:
itertree.itree_data.iTDataModel
Example iDataModel class that accepts any kind of value
-
validator
(value)[source]¶ This method should check the given value.
It should raise an iDataValueError Exception with a failure explanation in case the value is not matching to the iDataModel.
- ..warning:: The validator in an explicit iDataModel class must always return the value itself and it must raise
the iDataValueError in case of a no matching value. It should also call the super().validator() method or at least consider that NoValue is a no matching value.
- Except
iDataValueError in case value is not matching
- Parameters
value – to be checked against the model
- Returns
value (which might be casted)
-
formatter
(value=None)[source]¶ The formatter function allows us to create a specific string representation
Especially in case of numerical values this is interesting. You can define here that an integer should be represented always as hex, bin, … or for floats you can give digits.
The formatter can be created by using the classical format options of string but for enumerations we can put here also a table, etc.
- Returns
string representing the value
-
-
class
itertree.itree_data.
iTData
(seq=None, **kwargs)[source]¶ Bases:
dict
Standard itertree Data management object might be overloaded or changed by the user
-
GET_LOOK_UP_METHOD
= {0: <function iTData.<lambda>>, 1: <function iTData.<lambda>>, 2: <function iTData.<lambda>>}¶
-
update
(E=None, **F)[source]¶ function update of multiple items if one item is invalid the whole update will be skipped and an iDataValueError exception will thrown!
In case the replace_model flag is set the model will be exchanged.
Parameters taken from builtin dict:
Update D from dict/iterable E and F. If E is present and has a .keys() method, then does: If E is present and lacks a .keys() method, then does: In either case, this is followed by:
- Except
raises iDataValueError exception if a value in the given object is not matching to the data-model. The iData object will not be updated in this case.
- Parameters
E –
with .keys() method: for k in E: D[k] = E[k]
without .keys() method: for k, v in E: D[k] = v
**F –
we run: for k in F: D[k] = F[k]
replace_models –
True - Will replace the whole key related value (also iTDataModels are replaced)
- False (default) - All values are replaced in case of iTDataModel object the internal value will
be replaced
-
pop
(key=<class 'itertree.itree_helpers.NoKey'>, default=<class 'itertree.itree_helpers.NoKey'>, value_only=True)[source]¶ delete a stored value
- Except
will case KeyError if key is not found and default is not set
- Parameters
key – key where the item should be popped out
value_only – True - only value will be deleted model will be kept in iTreeData False - whole model will be popped out
- Default
define the value given back in case key is not found else KeyError will be raised
- Returns
deleted item or default
-
get
(key=<class 'itertree.itree_helpers.NoKey'>, default=None, return_type=0)[source]¶ get a specific data item by key
- Parameters
key – key of the data item (if not given __NOKEY__ is used)
default – default value that will be delivered in case of no match
_return_type – We can deliver different returns * VALUE - value object * FULL - iTreeDataModel (only if used else same as VALUE) * STR - formatted string representation of the data value
- Returns
requested value
-
fromkeys
(*args, **kwargs)[source]¶ create a new iData object based on given keys and optional value
real signature unknown
-
delete_item
(key, value_only=True)[source]¶ delete a item by key
- Except
KeyError is raised in case item key is unknown
- Parameters
key – key of the data item (if not given __NOKEY__ is used!
value_only –
- True - (default) in case of iDataModel items we delete only the internal value
not the model itself
False - we delete the value independent from the type (also iDataModel objects)
- Returns
deleted value
-
model_values
()[source]¶ iterator that takes in case of iDataModel values the value out of the model, in case of non iDataModel values the value is given directly as it is
- Returns
iterator
-
model_items
()[source]¶ iterator that takes in case of iDataModel values the value out of the model, in case of non iDataModel values the value is given directly as it is
- Returns
iterator
-
property
is_empty
¶ used for identification of this class :return: True
-
property
is_no_key_only
¶ used for identification of this class :return: True
-
property
is_iTData
¶
-
is_key_empty
(key=<class 'itertree.itree_helpers.NoKey'>)[source]¶ Function delivers a key empty state (it delivers True in case key is absent or value is __NOVALUE__ :param key: key to be check (delault is __NOKEY__ :return: True/False
-
-
class
itertree.itree_data.
iTDataReadOnly
(seq=None, **kwargs)[source]¶ Bases:
itertree.itree_data.iTData
Standard itertree Data management object might be overloaded or changed by the user
-
pop
(*arg, **kwargs)[source]¶ delete a stored value
- Except
will case KeyError if key is not found and default is not set
- Parameters
key – key where the item should be popped out
value_only – True - only value will be deleted model will be kept in iTreeData False - whole model will be popped out
- Default
define the value given back in case key is not found else KeyError will be raised
- Returns
deleted item or default
-
update
(*arg, **kwargs)[source]¶ function update of multiple items if one item is invalid the whole update will be skipped and an iDataValueError exception will thrown!
In case the replace_model flag is set the model will be exchanged.
Parameters taken from builtin dict:
Update D from dict/iterable E and F. If E is present and has a .keys() method, then does: If E is present and lacks a .keys() method, then does: In either case, this is followed by:
- Except
raises iDataValueError exception if a value in the given object is not matching to the data-model. The iData object will not be updated in this case.
- Parameters
E –
with .keys() method: for k in E: D[k] = E[k]
without .keys() method: for k, v in E: D[k] = v
**F –
we run: for k in F: D[k] = F[k]
replace_models –
True - Will replace the whole key related value (also iTDataModels are replaced)
- False (default) - All values are replaced in case of iTDataModel object the internal value will
be replaced
-
delete_item
(key, value_only=True)[source]¶ delete a item by key
- Except
KeyError is raised in case item key is unknown
- Parameters
key – key of the data item (if not given __NOKEY__ is used!
value_only –
- True - (default) in case of iDataModel items we delete only the internal value
not the model itself
False - we delete the value independent from the type (also iDataModel objects)
- Returns
deleted value
-
itertree filter classes¶
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the iTree filter classes
we use here lambda to create a method which is feed with an item and delivers then True/False depending on the given condition so that it can be used in filter iterators
-
itertree.itree_filters.
iter_items_over_filter_method
(filter_method, item_iter)[source]¶ helper function that delivers an iterator of True/False based on given filter_method and the item iterator given
- Parameters
filter_method – Item filter method
item_iter – iterable where each item should be checked against the filter
- Returns
iterator of True/False objects matches to filter or not
-
class
itertree.itree_filters.
has_item_flags
(flag_mask, invert=False)[source]¶ Bases:
object
Check the iTree flags for match to the given flag mask
- Parameters
item – iTree-item to be checked against the criteria of the method (for filtering out or not)
flag_mask – flag mask E.g. can be build like: iTFLAG.READ_ONLY_TREE|iTFLAG.READ_ONLY_VALUE
- Return type
bool
- Returns
True -> match
False -> no match
-
class
itertree.itree_filters.
is_item_tag
(target_tag, invert=False)[source]¶ Bases:
object
Check the iTree tag is equal to the given target_tag
- Parameters
target_tag – tag string do not give Tag() objects here! Use Tag().tag if really required
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_tag_fnmatch
(tag_match_pattern, invert=False)[source]¶ Bases:
object
Check the iTree tag is matching to given fnmatch match_pattern
- Parameters
match_pattern – str or bytes related to fnmatch pattern definitions
-
class
itertree.itree_filters.
has_item_value
(target_value, invert=False)[source]¶ Bases:
object
Check the iTree value is equal to given value
- Parameters
target_value – value object that should be equal with iTree.value
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_dict_value
(target_value, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a dict a value in the dict is equal to given value
- Parameters
target_value – value object that should be equal with iTree.value
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_list_value
(target_value, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a list a value in the list is equal to given value
- Parameters
target_value – value object that should be equal with iTree.value
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_fnmatch
(target_value_pattern, invert=False)[source]¶ Bases:
object
Check if value matches to the given fnmatch pattern
- Parameters
target_value_pattern – str or bytes related to fnmatch pattern definitions
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_dict_value_fnmatch
(target_value_pattern, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a dict a value in the dict matches to the given pattern
- Parameters
target_value_pattern – str or bytes related to fnmatch pattern definitions
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_list_item_fnmatch
(target_value_pattern, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a list a value in the list matches to the given pattern
- Parameters
target_value_pattern – str or bytes related to fnmatch pattern definitions
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
is_item_value_in
(target_value_interval, invert=False)[source]¶ Bases:
object
Check if iTree value is in the given iTInterval object, no numeric values will be ignored
- Parameters
target_key_interval – msetInterval object defining the range (any object that supports “in” can be used)
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_dict_value_in
(target_value_interval, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a dict a value in the dict is in the given iTInterval object, no numeric values will be ignored
- Parameters
target_key_interval – msetInterval object defining the range (any object that supports “in” can be used)
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_list_item_in
(target_value_interval, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a list a value in the list is in the given iTInterval object, non numeric values will be ignored
- Parameters
target_key_interval – msetInterval object defining the range (any object that supports “in” can be used)
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_dict_key
(target_key, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a dict a key in the dict is equal with the given target_key no numeric values will be ignored
- Parameters
target_key – dict key
-
class
itertree.itree_filters.
has_item_value_list_idx
(target_idx, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a list the given target_key is lower than list length (inside) no numeric values will be ignored
- Parameters
target_idx – target-index
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_dict_key_fnmatch
(target_key_pattern, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a dict a key in the dict matches to the given key pattern (fnmatch) no numeric values will be ignored
- Parameters
target_key_pattern – str or bytes related to fnmatch pattern definitions
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
-
class
itertree.itree_filters.
has_item_value_dict_key_in
(target_key_interval, invert=False)[source]¶ Bases:
object
Check if in case the iTree value is a dict a key in the dict is in the given iTInterval object range no numeric values will be ignored
- Parameters
target_key_interval – msetInterval object defining the range (any object that supports “in” can be used)
invert –
False (default) -> unchanged result
True -> invert the result True->False; False->True
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains helper classes used in DataTree object
-
class
itertree.itree_mathsets.
mSetItem
(value, complement=False, formatter=<class 'str'>)[source]¶ Bases:
object
item object to used in the different mSet objects Depending on the object it is a “normal” item (mSetRoster) or it is the lower or upper limit of the mSetInterval object. In first case complemented items will be ignored.
The object contains a formatting option to define how the string representation of the item should look like. Especially integer formatting is used to to create representations of the other base like hex or octal.
- Parameters
value (object) – numerical value to be stored in object or definition str the user can give also a variable-name here
complement (bool) – complement type item (only required for interval limits
formatter – explicit formatter user can give as formatter 1. formatter method (callable) 2. escape string for format() method 3 escape string for classical “%” replacement
-
property
is_mSetItem
¶ Property used for identification of the object
- Return type
bool
- Returns
True
-
property
is_complement
¶ property tells if the object is complement
- Return type
bool
- Returns
True/False
-
property
value
¶ property contains the value of the item :return: value of the object
-
property
formatter
¶ property delivers the formatter of the object
- Return type
Union[Callable,str]
- Returns
formatter object (Callable or string)
-
property
formatter_type
¶ property delivers the formatter type integer constant of the object formatter
- Return type
int
- Returns
formatter type integer ( `_CALL`~0;,`_FORMAT`~1; ,`_OLD`~2 )
-
property
is_var
¶ property returns if the value is a variable name or a normal numerical value
- Return type
bool
- Returns
True - is variable; False - normal numerical value
-
class
itertree.itree_mathsets.
mSetInterval
(*definition, lower=None, upper=None, int_only=False, complement=False)[source]¶ Bases:
itertree.itree_mathsets._mSetBase
Mathematical interval set object. Here the user can define a mathematical interval with closed or open boarders.
For more details related to mathematical intervals you may have a look here: https://en.wikipedia.org/wiki/Interval_(mathematics)
-
property
is_lower_closed
¶ do we have a closed lower limit “(” :return: True is closed, False is open
-
property
is_lower_open
¶ do we have a open lower limit “(” :return: True is open, False is closed
-
property
lower_value
¶ Property delivers the lower limit value :return: value of the lower limit
-
property
is_upper_closed
¶ do we have a closed upper limit “(” :return: True is closed, False is open
-
property
is_upper_open
¶ do we have a open upper limit “(” :return: True is open, False is closed
-
property
upper_value
¶ Property delivers the upper limit value :return: value of the upper limit
-
property
is_int_only
¶ Is this an integer number only interval? :return:
-
property
cardinality
¶ The cardinality is somehow the size of the set it delivers how many items the set contains. The result is not in all cases correct furthermore it is just an estimation!
In many cases in float intervals the user will find infinite as the result of the operation. :return: number of items integer or float(‘inf’) for infinite results
-
property
is_empty_set
¶ Is the interval same as an empty set (no item inside) :return: True is empty; False is not empty
-
property
is_empty_set_complement
¶ Is the complement interval same as an empty set (no item inside). If this is the case the set is the universal set (any item inside). But this is a relative definition to the “universe”. E.g. strings will never be found inside a numerical set they are not in the “universe”.
- Returns
True complement is empty; False complement is not empty
-
iter_in
(value, vars_dict=None)[source]¶ For each item in the given iterable value we check if the item is in this mSet object the result is a iterable over the single results :param value: to be checked iterable value (single item check) :param vars_dict: variable replacement dict :return: iterable True/False
-
filter
(value, vars_dict=None)[source]¶ For each item in the given iterable value we check if the item is in this mSet object or not in case it is in the item will be delivered back if not it is skipped
- Parameters
value – iterable value which items will be checked
vars_dict – variable replacement dict
- Returns
iterable of matching items
-
property
-
class
itertree.itree_mathsets.
mSetRoster
(*definition, items=None, complement=False)[source]¶ Bases:
itertree.itree_mathsets._mSetBase
-
property
cardinality
¶ The cardinality is somehow the size of the set it delivers how many items the set contains. The result is not in all cases correct furthermore it is just an estimation!
In many cases in float intervals the user will find infinite as the result of the operation. :return: number of items integer or float(‘inf’) for infinite results
-
property
is_empty_set
¶ For some set definition no matching item can be found! Then the set is equal to the empty set and this property will deliver True
- Return type
bool
- Returns
True is empty set; False set contains items
-
property
is_empty_set_complement
¶ Is the complement interval same as an empty set (no item inside). If this is the case the set is the universal set (any item inside). But this is a relative definition to the “universe”. E.g. strings will never be found inside a numerical set they are not in the “universe”.
- Returns
True complement is empty; False complement is not empty
-
iter_in
(value, vars_dict=None)[source]¶ For each item in the given iterable value we check if the item is in this mSet object the result is a iterable over the single results :param value: to be checked iterable value (single item check) :param vars_dict: variable replacement dict :return: iterable True/False
-
filter
(value, vars_dict=None)[source]¶ For each item in the given iterable value we check if the item is in this mSet object or not in case it is in the item will be delivered back if not it is skipped
- Parameters
value – iterable value which items will be checked
vars_dict – variable replacement dict
- Returns
iterable of matching items
-
property
-
class
itertree.itree_mathsets.
mSetCombine
(*definition, is_union=True, complement=False)[source]¶ Bases:
itertree.itree_mathsets._mSetBase
class where the user can combine different sets to unions
In this class the user can combine different types of sets (all objects with __contains__() and a length are allowed to be added.
If the object is used to check if a value is in it is sufficient if the value is in one of the subsets to create a positive response for a match
-
property
is_union
¶
-
property
is_intersection
¶
-
property
cardinality
¶ The cardinality is somehow the size of the set it delivers how many items the set contains. The result is not in all cases correct furthermore it is just an estimation!
Especially in this case the cardinally is really an estimation only. It’s not teh case that we check here for overlapping intervals which might reduce the cardinality. We create just an estimation based the cardinalities of the subitems
In many cases in float intervals the user will find infinite as the result of the operation. :return: number of items integer or float(‘inf’) for infinite results
-
property
is_empty_set
¶ For some set definition no matching item can be found! Then the set is equal to the empty set and this property will deliver True
- Return type
bool
- Returns
True is empty set; False set contains items
-
property
is_empty_set_complement
¶ Is the complement interval same as an empty set (no item inside). If this is the case the set is the universal set (any item inside). But this is a relative definition to the “universe”. E.g. strings will never be found inside a numerical set they are not in the “universe”.
- Returns
True complement is empty; False complement is not empty
-
math_repr
()[source]¶ mathematical representation of the object (we try to match as good as possible to the mathematical standards here but we avoid exotic characters! :return: mathematical representation string
-
iter_in
(value, vars_dict=None)[source]¶ For each item in the given iterable value we check if the item is in this mSet object the result is a iterable over the single results :param value: to be checked iterable value (single item check) :param vars_dict: variable replacement dict :return: iterable True/False
-
filter
(value, vars_dict=None)[source]¶ For each item in the given iterable value we check if the item is in this mSet object or not in case it is in the item will be delivered back if not it is skipped
- Parameters
value – iterable value which items will be checked
vars_dict – variable replacement dict
- Returns
iterable of matching items
-
property
itertree serializing¶
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the standard iTree serializers (JSON and rendering)
-
class
itertree.itree_serializer.itree_json_serialize.
iTStdJSONSerializer2
(itree_class)[source]¶ Bases:
object
This is the standard serializer for DataTree which translates the structure into the JSON format. Users might implement their own serializers using the interface methods defined in this serializer
-
not_linked_filter
()¶
-
ALL_TYPE
= 0¶
-
BYTE_TYPE
= 1¶
-
STR_TYPE
= 2¶
-
DICT_TYPE
= 3¶
-
ITER_TYPE
= 4¶
-
NP_TYPE
= 5¶
-
IT_TYPE
= 6¶
-
IT_LINK_TYPE
= 7¶
-
IT_CONST_TYPE
= 8¶
-
NO_VALUE
= 0¶
-
NO_TAG
= 1¶
-
ANY
= 2¶
-
NO_KEY
= 3¶
-
TRANSLATE_OBJ2KEY
= {<class 'itertree.itree_helpers.Any'>: 2, <class 'itertree.itree_helpers.NoValue'>: 0, <class 'itertree.itree_helpers.NoTag'>: 1, <class 'itertree.itree_helpers.NoKey'>: 3}¶
-
TRANSLATE_KEY2OBJ
= {0: <class 'itertree.itree_helpers.NoValue'>, 1: <class 'itertree.itree_helpers.NoTag'>, 2: <class 'itertree.itree_helpers.Any'>, 3: <class 'itertree.itree_helpers.NoKey'>}¶
-
CONVERT_MAP
= {<class 'collections.deque'>: <function iTStdJSONSerializer2.<lambda>>, <class 'str'>: <function iTStdJSONSerializer2.<lambda>>, <class 'float'>: <function iTStdJSONSerializer2.<lambda>>, <class 'collections.OrderedDict'>: <function iTStdJSONSerializer2.<lambda>>, <class 'type'>: <function iTStdJSONSerializer2.<lambda>>, <class 'set'>: <function iTStdJSONSerializer2.<lambda>>, <class 'list'>: <function iTStdJSONSerializer2.<lambda>>, <class 'int'>: <function iTStdJSONSerializer2.<lambda>>, <class 'bytes'>: <function iTStdJSONSerializer2.<lambda>>, <class 'dict'>: <function iTStdJSONSerializer2.<lambda>>, <class 'tuple'>: <function iTStdJSONSerializer2.<lambda>>}¶
-
CONVERT_FROM_JSON_MAP
= {0: <function iTStdJSONSerializer2.<lambda>>, 1: <function iTStdJSONSerializer2.<lambda>>, 3: <function iTStdJSONSerializer2.<lambda>>, 4: <function iTStdJSONSerializer2.<lambda>>, 5: <function iTStdJSONSerializer2.<lambda>>, 6: <function iTStdJSONSerializer2.<lambda>>, 8: <function iTStdJSONSerializer2.<lambda>>}¶
-
dumps
(o, add_header=False, calc_hash=False, filter_method=None)[source]¶ In JSON the iTree object is represented in the following form Item-> dict with all properties (Special keys used) Tree structure is stored in list
- Parameters
o – iTree object to be serialized
add_header – True - the header information will be added (containing Version info and hash) False - no header pure data
calc_hash – True - A sha1 hash is calculated over the data section of iTree and added in the header False - no hash will be calculated
- Return type
tuple
- Returns
hash,string containing the serialized data -> if no hash calculation requested hash will be None
-
dump
(o, file_path, pack=True, calc_hash=True, overwrite=False, filter_method=None)[source]¶ Serialize iTree object into a file
- Parameters
o – iTree object to be serialized
file_path – target file path where to store the data in
pack – True - gzip the data, False - do not zip
overwrite – True - an existing fie will be overwritten False (default) - in case the file exists an FileExistsError Exception will be raised
calc_hash – True - A sha1 hash is calculated over the data section of iTree and added in the header False - no hash will be calculated
- Returns
None
-
loads
(source_str, check_hash=True, load_links=True, _source=None)[source]¶ create an iTree object by loading from a string.
- Parameters
source_str – source string that contains the iTree information
check_hash – True the hash of the file will be checked and the loading will be stopped if it doesn’t match False - do not check the iTree hash
load_links – True - linked iTree objects will be loaded
_source – Path of a loaded source file (for internal use)
- Returns
iTree object loaded from file
-
load
(file_path, check_hash=True, load_links=True)[source]¶ create an iTree object by loading from a file
- Parameters
file_path – file path to the file that contains the iTree information
check_hash – True the hash of the file will be checked and the loading will be stopped if it doesn’t match False - do not check the iTree hash
load_links – True - linked iTree objects will be loaded
- Returns
iTree object loaded from file
-
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the standard iTree serializers (JSON and rendering)
-
class
itertree.itree_serializer.itree_renderer.
iTreeRender
[source]¶ Bases:
object
Standard renderer fr the iTree object for creating a very simple pretty print output
-
renders
(itree_object, filter_method=None, enumerate=False)[source]¶ creates a pretty print string from iTree object and returns it in a string
The rendered outputs can be filtered but only in hierarchical way.
- param itree_object
iTree object to be converted
- param filter_method
item filter method or filter-constant to filter specific items out Note:: The root of the object is not filtered and always in the outputs first line
- Parameters
enumerate –
add enumeration before the items
- return
string containing the pretty print output
-
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This is a class wihch translates an iTree in a dot graph
This part of code contains the standard iTree serializers (JSON and rendering)
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains the standard iTree serializers (JSON and rendering)
-
itertree.itree_serializer.itree_json_converter.
Converter_1_1_1_to_2_0_0
(src_path, check_hash=True)[source]¶
-
class
itertree.itree_serializer.itree_json_converter.
Converter_1_1_1_to_2_0_0_Cls
[source]¶ Bases:
object
This is the standard serializer for DataTree which translates the structure into the JSON format. Users might implement their own serializers using the interface methods defined in this serializer
-
ITREE_SERIALIZE_VERSION
= '1.1.1'¶
-
TREE
= 'iT'¶
-
DATA
= 'DT'¶
-
LINK
= 'LK'¶
-
TAG
= 'TG'¶
-
IDX
= 'IDX'¶
-
DATA_MODELL
= 'DM'¶
-
DTYPE
= 'TP'¶
-
DATA_CONTAINER
= 'DC'¶
-
ITREE_ITEMS_DECODE
= {'iT', 'iTI', 'iTPH', 'iTRO', 'iTl'}¶
-
itertree helper classes¶
This code is taken from the itertree package: https://pypi.org/project/itertree/ GIT Home: https://github.com/BR1py/itertree The documentation can be found here: https://itertree.readthedocs.io/en/latest/index.html
The code is published under MIT license incl. human protect patch:
The MIT License (MIT) incl. human protect patch Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Human protect patch: The program and its derivative work will neither be modified or executed to harm any human being nor through inaction permit any human being to be harmed.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information see: https://en.wikipedia.org/wiki/MIT_License
This part of code contains helper classes used in DataTree object
-
itertree.itree_helpers.
accu_iterator
(iterable, accu_method, initial_value=(None))[source]¶ A method that enables itertools accumulation over a method .. note:: This method is just needed because in python <3.8 itertools accumulation has no initial parameter! :param iterable: iterable :param accu_method: accumulation method (will be fet by two parameters cumulated and new item) :return: accumulated iterator
-
itertree.itree_helpers.
is_iterator_empty
(iterator)[source]¶ checks if the given iterator is empty
- Parameters
iterator – iterator to be checked
- Return type
tuple
- Returns
(True, iterator) - empty
(False, iterator) - item inside
-
itertree.itree_helpers.
rindex
(lst, value)[source]¶ find last occurance of a itme in the list :param lst: list :param value: search value :return:
-
class
itertree.itree_helpers.
iTLink
(file_path=None, target_path=None, link_item=None)[source]¶ Bases:
object
Definition of a link to an element in another DataTree
-
property
loaded
¶
-
property
is_loaded
¶
-
property
link_item
¶
-
property
file_path
¶
-
property
target_path
¶
-
property
link_tag
¶
-
property
link_data
¶
-
property
source_path
¶
-
property
file_crc
¶
-
property
-
class
itertree.itree_helpers.
iTFLAG
[source]¶ Bases:
object
public flags for setting the iTree behavior during `__init__()
-
READ_ONLY_TREE
= 1¶
-
READ_ONLY_VALUE
= 2¶
-
LOAD_LINKS
= 4¶
-
-
class
itertree.itree_helpers.
Any
[source]¶ Bases:
object
Helper class used for marking that the ìTree()-object is “empty” no value is stored inside.
If required use the class as it is, do not instance an object.
-
class
itertree.itree_helpers.
NoValue
[source]¶ Bases:
object
Helper class used for marking that the ìTree()-object is “empty” no value is stored inside.
If required use the class as it is, do not instance an object.
-
class
itertree.itree_helpers.
NoTag
[source]¶ Bases:
object
Helper class used for the NoTag-family tag which is automatically used in case no explicit tag is given during creation of the ìTree()-object.
If required use the class as it is, do not instance an object.
-
class
itertree.itree_helpers.
NoKey
[source]¶ Bases:
object
Helper class used for the NoKey entries in dicts stored as value object in the ìTree()-object.
If required use the class as it is, do not instance an object.
-
class
itertree.itree_helpers.
NoTarget
[source]¶ Bases:
object
Helper class used for the NoKey entries in dicts stored as value object in the ìTree()-object.
If required use the class as it is, do not instance an object.
-
class
itertree.itree_helpers.
Tag
(tag=<class 'itertree.itree_helpers.NoTag'>)[source]¶ Bases:
object
Helper class used in get-methods for marking that the given value is a family-tag and not an index or key, etc.
-
tag
¶
-
-
class
itertree.itree_helpers.
TagIdx
(tag, idx)¶ Bases:
tuple
-
property
tag
¶ Alias for field number 0
-
property
idx
¶ Alias for field number 1
-
property
-
itertree.itree_helpers.
getter_to_list
(get_result)[source]¶ Helper function that always creates a list from a `iTree`get-method result.
In case we have a iterator the list with the iterator items is created.
In case we have a single item a list [single_item] is created
In case we have no item or empty iterator an empty list is created.
- Parameters
get_result – result coming from a getter method
- Return type
list
- Returns
result list