Package ClusterShell :: Module MsgTree :: Class MsgTree
[hide private]
[frames] | no frames]

Class MsgTree

source code


A MsgTree object maps key objects to multi-lines messages. MsgTree's are mutable objects. Keys are almost arbitrary values (must be hashable). Message lines are organized as a tree internally. MsgTree provides low memory consumption especially on a cluster when all nodes return similar messages. Also, the gathering of messages is done automatically.

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
clear(self)
Remove all items from the MsgTree.
source code
 
__len__(self)
Return the number of keys contained in the MsgTree.
source code
 
__getitem__(self, key)
Return the message of MsgTree with specified key.
source code
 
get(self, key, default=None)
Return the message for key if key is in the MsgTree, else default.
source code
 
add(self, key, msgline)
Add a message line associated with the given key to the MsgTree.
source code
 
keys(self)
Return an iterator over MsgTree's keys.
source code
 
__iter__(self)
Return an iterator over MsgTree's keys.
source code
 
messages(self, match=None)
Return an iterator over MsgTree's messages.
source code
 
items(self, match=None, mapper=None)
Return (key, message) for each key of the MsgTree.
source code
 
_depth(self)
Return the depth of the MsgTree, ie.
source code
 
walk(self, match=None, mapper=None)
Walk the tree.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

__getitem__(self, key)
(Indexing operator)

source code 

Return the message of MsgTree with specified key. Raises a KeyError if key is not in the MsgTree.

get(self, key, default=None)

source code 

Return the message for key if key is in the MsgTree, else default. If default is not given, it defaults to None, so that this method never raises a KeyError.

_depth(self)

source code 

Return the depth of the MsgTree, ie. the max number of lines per message. Added for debugging.

walk(self, match=None, mapper=None)

source code 

Walk the tree. Optionally filter keys on match parameter, and optionally map resulting keys with mapper function. Return an iterator of (message, keys) tuples for each different message in the tree.