treevalue.tree.common

TreeStorage

class treevalue.tree.common.TreeStorage

Note

Please refer to the source code for method details in this section of the documentation because adding method signatures will significantly decrease running speed.

clear()

Clear all the items in current storage.

contains(key)

Return true if key is exist in current storage, otherwise return false.

Parameters:

key – Key.

Returns:

key is exist or not.

del_(key)

Delete the item with given key.

Parameters:

key – Key of the item.

Raises:

KeyError – When key is not exist, raise KeyError.

empty()

Return true if current storage is empty (size is 0), otherwise return false.

Returns:

Empty or not.

get(key)

Get value of the given key.

Parameters:

key – Key of the item.

Returns:

Value of the item.

Raises:

KeyError – When key is not exist, raise KeyError.

get_or_default(key, default)

Get value of the given key, return default when not exist.

Parameters:
  • key – Key of the item.

  • default – Default value of the item.

Returns:

Value of the item if key is exist, otherwise return default.

iter_items()

Iterate items in current storage.

Returns:

Iterator of current items in normal order.

iter_keys()

Iterate keys in current storage.

Returns:

Iterator of current keys in normal order.

iter_rev_items()

Reversely iterate items in current storage.

Returns:

Iterator of current items in reversed order.

iter_rev_keys()

Reversely iterate keys in current storage.

Returns:

Iterator of current keys in reversed order.

iter_rev_values()

Reversely iterate values in current storage.

Returns:

Iterator of current values in reversed order.

iter_values()

Iterate values in current storage.

Returns:

Iterator of current values in normal order.

pop(key)

Pop the item with the given key, and return its value. After pop() method, the key will be no longer in current storage object.

Parameters:

key – Key of the item.

Returns:

Value of the item.

Raises:

KeyError – When key is not exist, raise KeyError.

pop_or_default(key, default)

Pop the item with the given key, return its value when exist, otherwise return default.

Parameters:
  • key – Key of the item.

  • default – Default value of the item.

Returns:

Value of the item if key is exist, otherwise return default.

popitem()

Pop one item from current storage.

Returns:

Tuple of the key and its value.

Raises:

KeyError – When current storage is empty, raise KeyError.

set(key, value)

Set value of given key in this storage object.

Parameters:
  • key – Key of the target item, should be a string.

  • value – Value of the target item, should be a native object, raw wrapped object or a delayed object.

setdefault(key, default)

Set value of given key if it is not exist yet.

Parameters:
  • key – Key of the target item, should be a string.

  • default – Default value of the target item, similar to value in method set().

Returns:

Value of the actual-exist item.

size()

Return the size of the current storage.

Returns:

Size of current storage.

create_storage

treevalue.tree.common.create_storage(value)

raw

treevalue.tree.common.raw(obj)
Overview:

Try wrap the given obj to raw wrapper.

Arguments:
  • obj (object): The original object.

Returns:
  • wrapped (object): Wrapped object, if the type is not necessary to be wrapped, the original object will be returned here.

unraw

treevalue.tree.common.unraw(wrapped)
Overview:

Try unwrap the given wrapped to original object.

Arguments:
  • wrapped (object): Wrapped object.

Returns:
  • obj (object): The original object.

RawWrapper

class treevalue.tree.common.RawWrapper

Wrapper class of the raw value.

__init__()

Initialize self. See help(type(self)) for accurate signature.

value()
Overview:

Get wrapped original value.

Returns:
  • obj: Original value.

delayed_partial

treevalue.tree.common.delayed_partial(func, *args, **kwargs)
Overview:

Build a delayed partial object. Similar to functools.partial().

Returns:
  • delayed: Delayed object.

undelay

treevalue.tree.common.undelay(p, is_final=True)
Overview:
Get the value of a given object, it can be a delayed proxy, a simple object or

a nested delayed proxy.

Arguments:
  • p (object): Given object to be undelay.

  • is_final (bool): Is final value getting or not, default is True.

Returns:
  • value (object): Actual value of the given ``p`.

DelayedProxy

class treevalue.tree.common.DelayedProxy
Overview:

Base class of all the delayed proxy class.

fvalue()
Overview:

Get value of the delayed proxy. Can be accessed in treevalue.tree.common.undelay() when is_final is True.

Returns:
  • value (object): Calculation result.

value()
Overview:

Get value of the delayed proxy. Should make sure the result is cached. Can be accessed in treevalue.tree.common.undelay() when is_final is False.

Returns:
  • value (object): Calculation result.

DelayedValueProxy

class treevalue.tree.common.DelayedValueProxy
Overview:

Simple function delayed proxy.

fvalue()
Overview:

Get value of the delayed proxy. Can be accessed in treevalue.tree.common.undelay() when is_final is True.

Returns:
  • value (object): Calculation result.

DelayedFuncProxy

class treevalue.tree.common.DelayedFuncProxy
Overview:

Simple function delayed proxy.

fvalue()
Overview:

Get value of the delayed proxy. Can be accessed in treevalue.tree.common.undelay() when is_final is True.

Returns:
  • value (object): Calculation result.