1.1.2.1. gnr.core.gnrbag- Bags and Struct

Last page update: November 23, 2011

Note

It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures. – Alan J. Perlis, Epigrams on Programming

Main classes:

Other classes:

Complete reference:

1.1.2.1.2. BagNode

1.1.2.1.3. BagCbResolver

1.1.2.1.4. BagFormula

1.1.2.1.8. UrlResolver

1.1.2.1.9. gnr.core.gnrbag - The complete reference list

The gnrbag module contains a single class intended to be used: Bag.

A Bag is a generic container object, similar to a dictionary, with some useful properties:

  • it is ordered
  • accessibility by key
  • iterability
  • it is hierarchic

A Bag can store any kind of python object with a label in an ordered list. It can also store attributes about any value stored: Bag attributes are metadata that are an addition to the stored object without distrurbing the stored data.

A Bag can be loaded and saved in some ways:

  • saved to and loaded from pikle files or strings: the object stored in the bag must be picklable of course
  • saved to and loaded from xml files or strings with a specific syntax: the object stored in the Bag must be strings, numbers or dates
  • loaded from a generic xml file preserving the whole hierarchical structure and the attributes: all values will be of type string of course
  • loaded from a generic html file: requires tidy.

Another class you could have to deal with is BagNode (a Bag is a list of BagNode-s).

BagNode is not intended to be instanced directly, it is used internally by Bag, however in some cases is useful to interact with BagNode instances inside a Bag.

Note

The square brackets around some parameters in the following method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Genro Library Reference

Note

Some methods have the “square-brackets notation”: it is a shorter notation for the method

synopsis:the foundamental data structure in GenroPy
class gnr.core.gnrbag.Bag(source=None, **kwargs)

A container object like a dictionary, but ordered.

Nested elements can be accessed with a path of keys joined with dots

addItem(item_path, item_value, _attributes=None, _position='>', _validators=None, **kwargs)

Add an item to the current Bag using a path in the form “label1.label2. ... .labelN”, returning the current Bag. If the path already exists, this method replicates the path keeping both the old values and the new value

Parameters:
  • item_path – the path of the given item
  • item_value – the value to set
  • _attributes – it specifies the attributes of the value to set
  • _position

    allow to set a new value at a particular position among its brothers Default value is >. You can use one of the following types:

    Position’s attributes Description
    '<' Set the value as the first value of the Bag
    '>' Set the value as the last value of the Bag
    '<label' Set the value in the previous position respect to the labelled one
    '>label' Set the value in the position next to the labelled one
    '<#index' Set the value in the previous position respect to the indexed one
    '>#index' Set the value in the position next to the indexed one
    '#index' Set the value in a determined position indicated by index number
  • _validators – it specifies the value’s validators to set
  • **kwargs – attributes AND/OR validators

Example:

>>> beatles = Bag()
>>> beatles.setItem('member','John')    # alternatively, you could write beatles.addItem('member','John')
>>> beatles.addItem('member','Paul')
>>> beatles.addItem('member','George')
>>> beatles.addItem('member','Ringo')
>>> print beatles
0 - (str) member: John
1 - (str) member: Paul
2 - (str) member: George
3 - (str) member: Ringo

Obviously, you can’t use the square-brackets notations within this method, because if you try to insert different values with the same label you would lose all the values except for the last one

addValidator(path, validator, parameterString)

Add a validator into the node at the given path

Parameters:
  • path – node’s path
  • validator – validation’s type
  • parameterString – a string which contains the parameters for the validation
asDict(ascii=False, lower=False)

Convert a Bag in a Dictionary and return it.

Parameters:
  • ascii – boolean. TODO
  • lower – boolean. TODO

Note

If you attempt to transform a hierarchical bag to a dictionary, the resulting dictionary will contain nested bags as values. In other words only the first level of the Bag is transformed to a dictionary, and the transformation is not recursive

asDictDeeply(ascii=False, lower=False)

TODO

Parameters:
  • ascii – boolean. TODO
  • lower – boolean. TODO
asString(encoding='UTF-8', mode='weak')

Call the __str__ method, and return an ascii encoded formatted representation of the Bag

Parameters:
  • encoding – the encoding type
  • mode – TODO
cbtraverse(pathlist, callback, result=None, **kwargs)

TODO

Parameters:
  • pathlist – TODO
  • callback – TODO
  • result – TODO
child(tag, childname='*_#', childcontent=None, _parentTag=None, **kwargs)

Set a new item of a tag type into the current structure or return the parent

Parameters:
  • tag – structure type
  • name – structure name
  • childcontent – the html content
clear()

Clear the Bag

clearBackRef()

Clear all the setBackRef() assumption

columns(cols, attrMode=False)

TODO

Parameters:
  • cols – TODO
  • attrMode – boolean. TODO
copy()

Return a Bag copy

deepcopy()

Return a deep Bag copy

defineFormula(**kwargs)

Define a formula that uses defined symbols

Parameters:kwargs – a key-value couple which represents the formula and the string that describes it
defineSymbol(**kwargs)

Define a variable and link it to a BagFormula Resolver at the specified path.

Parameters:kwargs – a dict of symbol to make a formula.
>>> mybag=Bag({'rect': Bag()})
>>> mybag['rect.params.base'] = 20
>>> mybag['rect.params.height'] = 10
>>> mybag.defineFormula(calculate_perimeter='2*($base + $height)' )
>>> mybag.defineSymbol(base ='params.base',  height='params.height')
>>> mybag['rect.perimeter']= mybag.formula('calculate_perimeter')
>>> print mybag['rect.perimeter']
60
delAttr(path=None, attr=None)

TODO

Parameters:
  • path – the path of the BagNode.
  • attr – the name of the attribute to delete
delItem(path, dflt=None)

This method is analog to dictionary’s pop() method. It pops the given item from a Bag at the relative path and returns it

Parameters:
  • path – path of the given item
  • dflt – TODO
>>> b = Bag()
>>> b.setItem('a',1)
>>> b.addItem('a',2)
>>> b.addItem('a',3)
>>> b.pop('a')
1
>>> print b
0 - (int) a: 2
1 - (int) a: 3
delParentRef()

Set False in the ParentBag reference of the relative Bag

digest(what=None, condition=None, asColumns=False)

It returns a list of n tuples including keys and/or values and/or attributes of all the Bag’s elements, where n is the number of special keys called in the method

Parameters:what – the parameter who includes a string of one or more special keys separated by a comma

Here follows a list of the special keys:

Special keys Description
'#k' Show the label of each item
'#v' Show the value of each item
'#v.path' Show inner values of each item
'#__v' Show the values of each node in ‘static’ mode ???
'#a' Show attributes of each item
'#a.attributeName' Show the attribute called ‘attrname’ for each item
Parameters:
  • condition – set a condition for digest process
  • asColumns

    TODO

    >>> b=Bag()
    >>> b.setItem('documents.letters.letter_to_mark','file0',createdOn='10-7-2003',createdBy= 'Jack')
    >>> b.setItem('documents.letters.letter_to_john','file1',createdOn='11-5-2003',createdBy='Mark',
    ... lastModify='11-9-2003')
    >>> b.setItem('documents.letters.letter_to_sheila','file2')
    >>> b.setAttr('documents.letters.letter_to_sheila',createdOn='12-4-2003',createdBy='Walter',
    ... lastModify='12-9-2003',fileOwner='Steve')
    >>> print b['documents.letters'].digest('#k,#a.createdOn,#a.createdBy')
    [('letter_to_sheila','12-4-2003','Walter'),('letter_to_mark','10-7-2003','Jack'),('letter_to_john','11-5-2003','Mark')]
    

Square-brackets notations:

You have to use the special char ? followed by d: followed by one or more expressions:

>>> print b['documents.letters.?d:#k,#a.createdOn,#a.createdBy']
[('letter_to_sheila','12-4-2003','Walter'),('letter_to_mark','10-7-2003','Jack'),('letter_to_john','11-5-2003','Mark')]
>>> print b['documents.letters.?d:#v,#a.createdOn']
[('file0', '10-7-2003'), ('file1', '11-5-2003'), ('file2', '12-4-2003')]
fillFrom(source)

Fill a void Bag from a source (basestring, Bag or list)

Parameters:source – the source for the Bag
filter(cb, _mode='static', **kwargs)

TODO

Parameters:cb – TODO
findNodeByAttr(attr, value)

TODO

Parameters:
  • attr – TODO
  • value – TODO
formula(formula, **kwargs)

Set a BagFormula resolver

Parameters:
  • formula – a string that represents the expression with symbolic vars
  • **kwargs – links between symbols and paths associated to their values
fromXml(source, catalog=None, bagcls=None, empty=None)

Fill a Bag with values read from an XML string or file or URL

Parameters:
  • source – the XML source to be loaded in the Bag
  • catalog – TODO
  • bagcls – TODO
  • empty – TODO
get(label, default=None, mode=None)

TODO

Parameters:
  • label – the Bag‘s label
  • default – TODO
  • mode – TODO
getAttr(path=None, attr=None, default=None)

Get the node’s attribute at the given path and return it. If it doesn’t exist, it returns None, so that this method never raises a KeyError

Parameters:
  • path – path of the given item
  • attr – the label of the attribute to get
  • default – the value returned by this method for an unexisting attribute
>>> b = Bag()
>>> b.setItem('documents.letters.letter_to_mark','file0',createdOn='10-7-2003',createdBy= 'Jack')
>>> print b
0 - (Bag) documents: 
    0 - (Bag) letters: 
        0 - (str) letter_to_mark: file0  <createdOn='10-7-2003' createdBy='Jack'>
>>> print b.getAttr('documents.letters.letter_to_mark', 'createdBy')
Jack
>>> print b.getAttr('documents.letters.letter_to_mark', 'fileOwner')
None
>>> print b.getAttr('documents.letters.letter_to_mark', 'fileOwner', default='wrong')
wrong

Square-brackets notations:

You have to use the special char ? followed by the attribute’s name:

>>> print b['documents.letters.letter_to_sheila?fileOwner']
Steve
getDeepestNode(path=None)

Return the deepest matching node in the bag and the remaining path of the path. bag.getDeepestNode(‘foo.bar.baz’) returns:

>>> if 'foo.bar.baz' in bag:
>>>     return (bag.getNode(foo.bar.baz), [])
>>> elif 'foo.bar' in bag:
>>>     return (bag.getNode('foo.bar'), ['baz'])
>>> elif 'bar' in bag:
>>>     return (bag.getNode(foo),['bar','baz'])
>>> else:
>>>     return (None,['foo','bar','baz'])
getDeepestNode_(path=None)

This method returns the deepest matching node in the bag and the remaining path of the path. bag.getDeepestNode(‘foo.bar.baz’) returns:

>>> if 'foo.bar.baz' in bag:
>>>     return (bag.getNode(foo.bar.baz), [])
>>> elif 'foo.bar' in bag:
>>>     return (bag.getNode('foo.bar'), ['baz'])
>>> elif 'bar' in bag:
>>>     return (bag.getNode(foo),['bar','baz'])
>>> else:
>>>     return (None,['foo','bar','baz'])
getFormula(path)

This method get the resolver of the node at the given path

Parameters:path – the path of the node
getIndex()

Return the Bag index with all the internal address

getIndexList(asText=False)

Return the Bag index as a plan list of the Nodes paths

Parameters:asText – TODO
getInheritedAttributes()

TODO

getItem(path, default=None, mode=None)

Return the value of the given item if it is in the Bag, else it returns None, so that this method never raises a KeyError

This method reimplements the list’s __getitem__() method. Usually a path is a string formed by the labels of the nested items, joined by the char ‘.’, but several different path notations have been implemented to offer some useful features:

  • if a path segment who starts with ‘#’ is followed by a number, the item will by identified by its index position, as a list element
  • if a path ends with ‘.?’, it returns the item’s keys
  • if at the last path-level the label contains ‘#’, what follows the ‘#’ is considered the key of an item’s attribute and this method will return that attribute’s value
  • if a path starts with ‘?’, then it is interpreted as a digest method

A path can also be a list of keys

Parameters:
  • path – the item’s path
  • default – the default return value for a not found item
  • mode=’static’ – with this attribute the getItem doesn’t solve the Bag resolver
>>> mybag = Bag()
>>> mybag.setItem('a',1)
>>> first= mybag.getItem('a')
>>> second = mybag.getItem('b')
>>> print(first,second)
(1, None)
>>> b = Bag()
>>> b['aa.bb.cc'] = 1234
>>> b['aa.bb.cc']
1234

Square-brackets notations:

>>> mybag = Bag({'a':1,'b':2})
>>> second = mybag['b']
>>> print second
2
getNode(path=None, asTuple=False, autocreate=False, default=None)

Return the BagNode stored at the relative path

Parameters:
  • path – path of the given node
  • asTuple – boolean. If True, return a tuple with the object and the node
  • autocreate – boolean. If True, it creates all the not existing nodes of the pathlist
  • default – the default return value for a not found node
getNodeByAttr(attr, value, path=None)

Return a BagNode with the requested attribute (e.g. searching a node with a given ‘id’ in a Bag build from html)

Parameters:
  • attr – path of the given item
  • value – path of the given item
  • path – an empty list that will be filled with the path of the found node
getNodes(condition=None)

Get the actual list of nodes contained in the Bag. The getNodes method works as the filter of a list

getResolver(path)

This method get the resolver of the node at the given path

Parameters:path – the path of the node
has_key(path)

This method is analog to dictionary’s has_key() method. Seek for the presence of the key in the Bag, and return True if the given item has the key, False otherwise

Parameters:path – the path of the given item
>>> b = Bag({'a':1,'b':2,'c':3})
>>> b.has_key('a')
True
>>> b.has_key('abc')
False
items()

Return a copy of the Bag as a list of tuples containing all key,value pairs

>>> b = Bag({'a':1,'b':2,'c':3})
>>> b.items()
[('a', 1), ('c', 3), ('b', 2)]
iteritems()

TODO

iterkeys()

TODO

itervalues()

TODO

keys()

Return a copy of the Bag as a list of keys

>>> b = Bag({'a':1,'a':2,'a':3})
>>> b.keys()
['a', 'c', 'b']
makePicklable()

Allow a Bag to be picklable

merge(otherbag, upd_values=True, add_values=True, upd_attr=True, add_attr=True)

Warning

deprecated since version 0.7

Allow to merge two bags into one

>>> john_doe=Bag()
>>> john_doe['telephones']=Bag()
>>> john_doe['telephones.house']=55523412
>>> other_numbers=Bag({'mobile':444334523, 'office':3320924, 'house':2929387})
>>> other_numbers.setAttr('office',{'from': 9, 'to':17})
>>> john_doe['telephones']=john_doe['telephones'].merge(other_numbers)
>>> print john_doe
0 - (Bag) telephones:
    0 - (int) house: 2929387
    1 - (int) mobile: 444334523
    2 - (int) office: 3320924  <to='17' from='9'>
>>> john_doe['credit_cards']=Bag()
nodes

Get the actual list of nodes contained in the Bag. The getNodes method works as the filter of a list

pickle(destination=None, bin=True)

Return a pickled Bag

Parameters:
  • destination – it is the destination path; default is ‘None’
  • bin – boolean; if False the Bag will be pickled in ASCII code, if True the Bag will be pickled in a binary format
pop(path, dflt=None)

This method is analog to dictionary’s pop() method. It pops the given item from a Bag at the relative path and returns it

Parameters:
  • path – path of the given item
  • dflt – TODO
>>> b = Bag()
>>> b.setItem('a',1)
>>> b.addItem('a',2)
>>> b.addItem('a',3)
>>> b.pop('a')
1
>>> print b
0 - (int) a: 2
1 - (int) a: 3
popNode(path)

This method is analog to dictionary’s pop() method. It pops the given node from a Bag at the relative path and returns it

Parameters:path – path of the given node
removeValidator(path, validator)

Remove a node’s validator at the given path

Parameters:
  • path – node’s path
  • validator – validation’s type
restoreFromPicklable()

Restore a Bag from its picklable form to its original form

rowchild(childname='R_#', _pkey=None, **kwargs)

TODO

Parameters:childname – the childname including the row name
setAttr(_path=None, _attributes=None, _removeNullAttributes=True, **kwargs)

Allow to set, modify or delete attributes into a node at the given path

You can set the attributes into a Bag with the _attributes parameter if you have a dict of attributes; alternatively, you can pass all the attributes as **kwargs.

>>> b = Bag()
>>> b.setAttr('documents.letters.letter_to_sheila', createdOn='12-4-2003', createdBy='Walter', lastModify= '12-9-2003')
>>> b.setAttr('documents.letters.letter_to_sheila', fileOwner='Steve')
>>> b.setAttr('documents',{'type':'secret','createdOn':'2010-11-15'})
>>> print b
0 - (Bag) documents: <createdOn='2010-11-15' type='secret'>
    0 - (Bag) letters: 
        0 - (str) letter_to_mark: file0  <createdOn='10-7-2003' createdBy='Jack'>
        1 - (str) letter_to_john: file1  <lastModify='11-9-2003' createdOn='11-5-2003' createdBy='Mark'>
        2 - (str) letter_to_sheila: file2  <lastModify='12-9-2003' createdOn='12-4-2003' fileOwner='Steve' createdBy='Walter'>

You may delete an attribute assigning None to an existing value:

>>> b.setAttr('documents.letters.letter_to_sheila', fileOwner=None, createdOn=None, createdBy=None)
>>> print b
0 - (Bag) documents: <createdOn='2010-11-15' type='secret'>
    0 - (Bag) letters:
        0 - (str) letter_to_sheila: file2  <lastModify='12-9-2003'>
setBackRef(node=None, parent=None)

Force a Bag to a more strict structure. It makes the Bag similar to a tree-leaf model: a Bag can have only one Parent and it knows this reference

Parameters:
  • node – the parent node
  • parent – TODO
setCallBackItem(path, callback, **kwargs)

An alternative syntax for a BagCbResolver call

Parameters:
  • path – TODO
  • callback – TODO
setCallable(name, argstring=None, func='pass')

TODO

Parameters:
  • name – TODO
  • argstring – TODO
  • func – TODO
setItem(item_path, item_value, _attributes=None, _position=None, _duplicate=False, _updattr=False, _validators=None, _removeNullAttributes=True, **kwargs)

Set an item (values and eventually attributes) to your Bag using a path in the form label1.label2...labelN. If path already exists, it overwrites the value at the given path. Return the Bag.

The default behaviour of setItem() is to add the new value as the last element. You can change this trend with the _position argument, who provides a compact syntax to insert the element in the desired place

Parameters:
  • item_path – the path of the given item
  • item_value – the value to set
  • _attributes – it specified, the value’s attributes to set
  • _position

    it is possible to set a new value at a particular position among its brothers.

    expression must be a string of the following types:

    Expressions Description
    '<' Set the value as the first value of the Bag
    '>' Set the value as the last value of the Bag
    '<label' Set the value in the previous position respect to the labelled one
    '>label' Set the value in the position next to the labelled one
    '<#index' Set the value in the previous position respect to the indexed one
    '>#index' Set the value in the position next to the indexed one
    '#index' Set the value in a determined position indicated by index number
  • _duplicate – boolean. Specify if a node with an existing path overwrite the value or append to it the new one
  • _updattr – boolean. TODO
  • _validators – specify the value’s validators to set
  • _removeNullAttributes – boolean. If True, remove the null attributes
  • **kwargs – attributes AND/OR validators

Example:

>>> mybag = Bag()
>>> mybag.setItem('a',1)
>>> mybag.setItem('b',2)
>>> mybag.setItem('c',3)
>>> mybag.setItem('d',4)
>>> mybag.setItem('e',5, _position= '<')
>>> mybag.setItem('f',6, _position= '<c')
>>> mybag.setItem('g',7, _position= '<#3')
>>> print mybag
0 - (int) e: 5
1 - (int) a: 1
2 - (int) b: 2
3 - (int) g: 7
4 - (int) f: 6
5 - (int) c: 3
6 - (int) d: 4

Square-brackets notations:

Bag[path] = value

Example:

>>> mybag = Bag()
>>> mybag['a'] = 1
>>> mybag['b.c.d'] = 2
>>> print mybag
0 - (int) a: 1
1 - (Bag) b:
    0 - (Bag) c:
        0 - (int) d: 2

Note

if you have to use the _position attribute you can’t use the square-brackets notation

setResolver(path, resolver)

Set a resolver into the node at the given path

Parameters:
  • path – the path of the node
  • resolver – the resolver to set
setdefault(path, default=None)

If path is in the Bag, return its value. If not, insert in the path the default value and return it. Default defaults to None

sort(pars='#k:a')

TODO

Parameters:pars – TODO None: label ascending
subscribe(subscriberId, update=None, insert=None, delete=None, any=None)

Provide a subscribing of a function to an event. Subscribing an event on a Bag means that every time that it happens, it is propagated along the bag hierarchy and is triggered by its eventhandler. A subscription can be seen as a event-function couple, so you can define many eventhandlers for the same event

Parameters:
  • subscriberId – the Id of the Bag’s subscription
  • update – the eventhandler function linked to update event
  • insert – the eventhandler function linked to insert event
  • delete – the eventhandler function linked to delete event
  • any – the eventhandler function linked to do whenever something (delete, insert or update action) happens
sum(what='#v')

TODO

Parameters:what – TODO
toTree(group_by, caption=None, attributes='*')

It transforms a flat Bag into a hierarchical Bag and returns it.

Parameters:
  • group_by – list of keys
  • caption – the attribute to use for the leaf key. If not specified, it uses the original key
  • attributes – keys to copy as attributes of the leaves. Default value is * (= select all the attributes)
toXml(filename=None, encoding='UTF-8', typeattrs=True, typevalue=True, unresolved=False, addBagTypeAttr=True, onBuildTag=None, autocreate=False, translate_cb=None, self_closed_tags=None, omitUnknownTypes=False, catalog=None, omitRoot=False, forcedTagAttr=None, docHeader=None)

Return a complete standard XML version of the Bag, including the encoding tag <?xml version=‘1.0’ encoding=’UTF-8’?> (the docHeader default value)

The content of the Bag is hierarchically represented as an XML block sub-element of the node <GenRoBag> (see the toXmlBlock() documentation for more details about type representation). Is also possible to write the result on a file, passing the path of the file as the ‘filename’ parameter.

Parameters:
  • filename – the output file path
  • encoding – set the XML encoding
  • typeattrs – boolean. If True, keep the attribute’s types
  • typevalue – boolean. If True, keep the value’s type
  • unresolved – boolean. TODO
  • addBagTypeAttr – boolean. TODO
  • autocreate – boolean. If True, it creates all the not existing nodes of the pathlist
  • translate_cb – TODO
  • self_closed_tags – TODO
  • omitUnknownTypes – boolean. TODO
  • catalog – TODO
  • omitRoot – boolean. If False, add the <GenRoBag> tag root
  • forcedTagAttr – TODO
  • docHeader – set an header tag external the <GenRoBag> tag
>>> mybag=Bag()
>>> mybag['aa.bb']=4567
>>> mybag.toXml()
'<?xml version='1.0' encoding='iso-8859-15'?>
<GenRoBag>
<aa><bb T="L">
4567</bb></aa></GenRoBag>'
traverse()

TODO

unpickle(source)

Unpickle a pickled Bag

Parameters:source – the source path
unsubscribe(subscriberId, update=None, insert=None, delete=None, any=None)

Delete a subscription of an event of a given subscriberId

Parameters:
  • subscriberId – the Id of the Bag’s subscription
  • update – the eventhandler function linked to update event
  • insert – the eventhandler function linked to insert event
  • delete – the eventhandler function linked to delete event
  • any – the eventhandler function linked to do whenever something (delete, insert or update action) happens
update(otherbag, resolved=False)

Update the Bag with the key/value pairs from otherbag, overwriting all the existing keys. Return None

Parameters:
  • otherbag – the Bag to merge into
  • resolved – TODO
values()

Return a copy of the Bag values as a list

walk(callback, _mode='static', **kwargs)

Calls a function for each node of the Bag

Parameters:callback – the function which is called
class gnr.core.gnrbag.BagCbResolver(*args, **kwargs)

A standard resolver. Call a callback method, passing its kwargs parameters

load()

TODO

class gnr.core.gnrbag.BagFormula(*args, **kwargs)

Calculate the value of an algebric espression

init()

TODO

load()

TODO

class gnr.core.gnrbag.BagNode(parentbag, label, value=None, attr=None, resolver=None, validators=None, _removeNullAttributes=True)

BagNode is the element type which a Bag is composed of. That’s why it’s possible to say that a Bag is a collection of BagNodes. A BagNode is an object that gather within itself, three main things:

  • label: can be only a string.
  • value: can be anything even a BagNode. If you got the xml of the Bag it should be serializable
  • attributes: dictionary that contains node’s metadata
addValidator(validator, parameterString)

Set a new validator into the BagValidationList of the node. If there are no validators into the node then addValidator instantiate a new BagValidationList and append the validator to it

Parameters:
  • validator – the type of validation to set into the list of the node
  • parameterString – the parameter for a single validation type
asTuple()

TODO

delAttr(*attrToDelete)

Receive one or more attributes’ labels and remove them from the node’s attributes

getAttr(label=None, default=None)

It returns the value of an attribute. You have to specify the attribute’s label. If it doesn’t exist then it returns a default value

Parameters:
  • label – the attribute’s label that should be get
  • default – the default return value for a not found attribute
getInheritedAttributes()

TODO

getLabel()

Return the node’s label

getStaticValue()

Get node’s value in static mode

getValidatorData(validator, label=None, dflt=None)

TODO

getValue(mode='')

Return the value of the BagNode. It is called by the property .value

Parameters:
  • mode=’static’ – allow to get the resolver instance instead of the calculated value
  • mode=’weak’ – allow to get a weak ref stored in the node instead of the actual object
hasAttr(label=None, value=None)

Check if a node has the given pair label-value in its attributes’ dictionary

removeValidator(validator)

TODO

resetResolver()

TODO

resolver

Get node’s resolver

setAttr(attr=None, trigger=True, _updattr=True, _removeNullAttributes=True, **kwargs)

It receives one or more key-value couple, passed as a dict or as named parameters, and sets them as attributes of the node.

Parameters:
  • attr – the attribute that should be set into the node
  • trigger – TODO
setLabel(label)

Set node’s label

setStaticValue(value)

Set node’s value in static mode

setValidators(validators)

TODO

setValue(value, trigger=True, _attributes=None, _updattr=None, _removeNullAttributes=True)

Set the node’s value, unless the node is locked. This method is called by the property .value

Parameters:
  • value – the value to set the new bag inherits the trigger of the parentBag and calls it sending an update event
  • trigger – boolean. TODO
staticvalue

Get node’s value in static mode

subscribe(subscriberId, callback)

TODO

Parameters:
  • subscriberId – TODO
  • callback – TODO
unsubscribe(subscriberId)

TODO

value

Return the value of the BagNode. It is called by the property .value

Parameters:
  • mode=’static’ – allow to get the resolver instance instead of the calculated value
  • mode=’weak’ – allow to get a weak ref stored in the node instead of the actual object
class gnr.core.gnrbag.BagResolver(*args, **kwargs)

BagResolver is an abstract class, that defines the interface for a new kind of dynamic objects. By “Dynamic” property we mean a property that is calculated in real-time but looks like a static one

attributes

TODO

digest(k=None)

same method of the dict digest()

getAttributes()

TODO

init()

TODO

items()

same method of the dict items()

iteritems()

TODO

iterkeys()

TODO

itervalues()

TODO

keys()

same method of the dict keys()

load()

Warning

deprecated since version 0.7

reset()

TODO

resolverDescription()

TODO

resolverSerialize()

TODO

setAttributes(attributes)

TODO

sum(k=None)

TODO

values()

same method of the dict values()

class gnr.core.gnrbag.BagValidationList(parentNode)

This class provides the validation system for a BagNode. This is a list of validators related to a BagNode. This class is used only from the addValidator and removeValidator methods of the Bag and BagNode’ classes. All the methods of this class must be considered private.

add(validator, parameterString)

Add a new validator to the BagValidationList.

Parameters:
  • validator – type of validator
  • parameterString – the string that contains the parameters for the validators
coerceFromText(value)

TODO

Parameters:value – TODO
defaultExt(value, oldvalue, parameterString)

TODO

Parameters:
  • value – TODO
  • oldvalue – TODO
  • parameterString – TODO
getdata(validator, label=None, dflt=None)

This method get the validatorsdata of a validator

remove(validator)

Remove a validator

Parameters:validator – the validator to remove
validate_case(value, oldvalue, parameterString)

Set a validation for the case of a string value

Parameters:
  • value – TODO
  • oldvalue – TODO
  • parameterString – values = ‘upper’ or ‘lower’ or ‘capitalize’
validate_db(value, oldvalue, parameterString)

TODO

Parameters:
  • value – TODO
  • oldvalue – TODO
  • parameterString – TODO
validate_hostaddr(value, oldvalue)

Provide a validaton for Host address value

Parameters:
  • value – TODO
  • oldvalue – TODO
validate_inList(value, oldvalue, parameterString)

TODO

Parameters:
  • value – TODO
  • oldvalue – TODO
  • parameterString – TODO
validate_length(value, oldvalue, parameterString)

Provides a validation for the length of a string value

Parameters:
  • value – TODO
  • oldvalue – TODO
  • parameterString – TODO
class gnr.core.gnrbag.DirectoryResolver(*args, **kwargs)

TODO

load()

TODO

makeLabel(name, ext)

TODO

Parameters:
  • name – TODO
  • ext – TODO
processor_default(path)

TODO

Parameters:path – TODO
processor_directory(path)

TODO

Parameters:path – TODO
processor_html(path)

TODO

Parameters:path – TODO
processor_txt(path)

TODO

Parameters:path – TODO
processor_xml(path)

TODO

Parameters:path – TODO
class gnr.core.gnrbag.UrlResolver(*args, **kwargs)

TODO

load()

TODO