paws.core.models package

Submodules

paws.core.models.DictTree module

class paws.core.models.DictTree.DictTree(data={})[source]

Bases: object

A 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).

contains_uri(uri)[source]

Check if the uri represents an item in this DictTree.

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_unique(uri)[source]

Check for uniqueness of a uri.

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.

keys()[source]
make_unique_uri(prefix)[source]

Generate the next unique uri from prefix by appending ‘_x’ to it, where x is a minimal nonnegative integer.

print_tree(root_uri='', rowprefix='')[source]

Print the content of the tree rooted at root_uri, with each row of the string preceded by rowprefix.

root_keys()[source]
set_uri(uri='', val=None)[source]

Set the data at the given uri to provided value val.

subkeys(root_uri='')[source]
tag_error_message(tag)[source]

Provide a human-readable error message for bad tags.

uri_error_message(uri)[source]

Provide a human-readable error message for bad uris.

paws.core.models.ListModel module

paws.core.models.TreeItem module

class paws.core.models.TreeItem.TreeItem(parent_itm, tag)[source]

Bases: object

A 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.

build_uri()[source]

Return the TreeModel uri of this TreeItem by following its parents up to a root item.

n_children()[source]

paws.core.models.TreeModel module

class paws.core.models.TreeModel.TreeModel(default_flags={})[source]

Bases: object

This 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.

children_flagged(itm, flag_key)[source]
contains_uri(uri)[source]
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).

get_data_from_uri(uri)[source]
get_from_uri(uri)[source]
is_flagged(itm, flag_key)[source]
is_tag_valid(tag)[source]
is_uri_valid(uri)[source]
keys()[source]
make_unique_uri(prefix)[source]
n_children(parent_uri='')[source]
n_flags()[source]
remove_item(itm_uri)[source]
root_tags()[source]
set_all_flagged(flag_key, val, itm=None)[source]
set_flagged(itm, flag_key, val)[source]
set_item(itm_uri, itm_data=None)[source]
tag_error_message(tag)[source]
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.

Module contents