paws.core.models package¶
Submodules¶
paws.core.models.DictTree module¶
-
class
paws.core.models.DictTree.DictTree(data={})[source]¶ Bases:
objectA tree as an ordered dictionary (root), extended by embedding other objects that are amenable to tree storage. Fetches items by a uri string that is a sequence of dict keys, connected by ‘.’s.
Child items (end nodes of the tree) can be anything. Parent items, in order to index their children, must be either lists, dicts, or objects implementing keys(), __getitem__(key) and __setitem__(key,value).
-
delete_uri(uri='')[source]¶ Delete the given uri, i.e., remove the corresponding key, value pair from the embedded dict.
-
get_from_uri(uri='')[source]¶ Return the data stored at uri. Each data item in the lineage of the uri must implement __getitem__() with support for string-like keys, unless it is a list, in which case the key is cast as int(key) before using it as an index in the list.
-
is_tag_valid(tag)[source]¶ Check for validity of a tag. The conditions for a valid tag are the same as for a valid uri, except that a tag should not contain period (.) characters.
-
is_uri_valid(uri)[source]¶ Check for validity of a uri. Uris may contain upper case letters, lower case letters, numbers, dashes (-), and underscores (_). Periods (.) are used as delimiters between tags in the uri. Any whitespace or any character in the string.punctuation library (other than -, _, or .) results in an invalid uri.
-
make_unique_uri(prefix)[source]¶ Generate the next unique uri from prefix by appending ‘_x’ to it, where x is a minimal nonnegative integer.
-
paws.core.models.ListModel module¶
paws.core.models.TreeItem module¶
-
class
paws.core.models.TreeItem.TreeItem(parent_itm, tag)[source]¶ Bases:
objectA structured container for indexing a TreeModel. A TreeItem keeps references to a parent TreeItem and a list of child TreeItems. It is labeled by a tag (TreeItem.tag) which must be unique across its sibling TreeItems. A root TreeItem should have None as its parent item.
paws.core.models.TreeModel module¶
-
class
paws.core.models.TreeModel.TreeModel(default_flags={})[source]¶ Bases:
objectThis class indexes a DictTree with a set of TreeItems. TreeItems keep track of their lineage in the DictTree, and can be modified for additional functionality in subclasses of TreeModel by adding TreeItem.flags.
-
build_tree(x)[source]¶ TreeModel.build_tree is called on some object x before x is stored in the tree. For subclasses of TreeModel to build tree data for data types other than dicts and lists, build_tree should be reimplemented. If data types other than dicts and lists have child items that should be accessible by TreeModel uris, they should implement __getitem__(tag).
-
build_uri(itm)[source]¶ Build a URI for TreeItem itm by combining the tags of the lineage of itm, with ‘.’ as a delimiter.
-
create_tree_item(parent_itm, itm_tag)[source]¶ Build a TreeItem for use in this tree. Reimplement create_tree_item() in subclasses of TreeModel to add features to TreeItems, such as default values for TreeItem.flags. TreeModel implementation returns TreeItem(parent_itm,itm_tag).
-
tree_update(parent_itm, itm_tag, itm_data)[source]¶ Update the tree structure rooted at parent_itm.children[itm_tag], such that TreeItems get built to index all of the items in itm_data that are supported by self.build_tree(). Assume build_tree was called on itm_data before passing it as an argument, so only need to recurse if itm_data is a dict.
-