Package gnue :: Package common :: Package definitions :: Module GObjects :: Class GObj
[show private | hide private]

Type GObj

GTriggerCore --+
               |
  object --+   |
           |   |
   ParserObj --+
               |
              GObj

Known Subclasses:
GRootObj, ProjectObj

The base class for almost all GNUe objects. GObj based objects can be represented by XML tags in a GParser based setup. This class introduces the concept of phased initialization as well as dictionary style access.

This is the method of attribute access used by Designer and Reports. For example. if foo is a GObject, then the following are equivalent:
 foo.required = 'Y'
 foo['required'] = 'Y'
The advantage of this method, however, is when namespaces are used in the GObj XML document (i.e., reports). e.g., :
 foo['Char:x'] = 1
 foo['Char:y'] = 2

These don't have a clean equivalent using the .attribute method. (Though, technically, a tool could access foo.Char__x, but that should be considered bad style.)

Eventually, .attribute style access should probably be deprecated, so we can clean up the python namespaces of GObjects. (i.e., we could keep all XML-storable attributes in one dict instead of in the namespace __dict__.
Method Summary
  __init__(self)
Initialize a GTriggerCore instance.
  __getitem__(self, key)
  __setitem__(self, key, value)
  _dumpXML_(self, lookupDict, treeDump, gap, xmlnamespaces, textEncoding, stripPrefixes, escape)
Dumps an XML representation of the object
  buildAndInitObject(self, **params)
This is a convenience function for applications NOT using GParser to load an object tree.
  buildObject(self, **params)
A convenience function for applications NOT using GParser to load an object tree.
string getXmlTag(self, stripPrefixes)
Returns the xml tag to be used to represent the object.
  iterator(self, test, types, includeSelf)
Return a python iterator of child objects.
  maxInits(self)
maxInits returns the maximum size of all the _inits list from this object or it's children
  phaseInit(self, iterations)
Starts GNUe's phased initialization system from this object down.
  showTree(self, indent)
A recusive function to print an indented text representation of the GObj tree from this object down.
  walk(self, function, *args, **parms)
Function that recursively walks down through a tree of ParserObj instances and applies a function to them.
    Inherited from GTriggerCore
  __repr__(self)
  create_namespace_object(self, global_namespace, namespace_name)
Construct a namespace object tree from an XML (definitions.GObjects.GObj) object tree.
  get_namespace_object(self)
Return the namespace object that mirrors this object in the action/trigger namespace.
    Inherited from ParserObj
  _diffActionWalker_(self, obj, action)
Set the action attribute of a given object to the specified action.
  _getAsContents_(self)
Get the contents of this object.
  _id_(self, maxIdLength)
Return a compareable and identifying id of an object within a tree.
  _set_initial_attributes_(self, attributes)
Set attributes loaded by GParser.
  addChild(self, child)
Add an object to the list of children
  assign(self, source, recursive)
Assign all attributes from a given object to this one.
  diff(self, goal, maxIdLength)
Build an object tree representing the difference between two object trees.
  dumpXML(self, lookupDict, treeDump, gap, xmlnamespaces, textEncoding, stripPrefixes, escape)
Return a XML representation of the object.
  findChildNamed(self, name, childType)
Moves downward though the children of an object till it finds the child with the specified name.
  findChildOfType(self, childType, includeSelf, allowAllChildren)
Moves downward through the children of an object till it finds the child of the specified type.
  findChildrenOfType(self, childType, includeSelf, allowAllChildren)
Find all children of a specific type.
  findParentOfType(self, parentType, includeSelf)
Moves upward though the parents of an object till it finds the parent of the specified type.
  getChildrenAsContent(self)
Returns the content of any GContent objects that are children of this object.
  getDescription(self)
Return a useful description of the object.
any getParent(self)
Returns the immediate parent of an object instance in a GObj tree.
  merge(self, other, maxIdLength, overwrite)
Merge another object tree into this tree.
  setParent(self, newParent)
Set the immediate parent of an object instance in a GObj tree
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
Return hash(x)...
  __new__(T, S, ...)
Return a new object with type S, a subtype of T...
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
Return str(x)...

Method Details

__init__(self, *args, **parms)
(Constructor)

Initialize a GTriggerCore instance.
Overrides:
gnue.common.logic.GTriggerCore.GTriggerCore.__init__ (inherited documentation)

__getitem__(self, key)
(Indexing operator)

__setitem__(self, key, value)
(Index assignment operator)

_dumpXML_(self, lookupDict, treeDump, gap, xmlnamespaces, textEncoding, stripPrefixes, escape)

Dumps an XML representation of the object
Overrides:
gnue.common.definitions.GParserHelpers.ParserObj._dumpXML_

buildAndInitObject(self, **params)

This is a convenience function for applications NOT using GParser to load an object tree.

buildObject(self, **params)

A convenience function for applications NOT using GParser to load an object tree.

getXmlTag(self, stripPrefixes=None)

Returns the xml tag to be used to represent the object.
Parameters:
stripPrefixes - A list of prefixes that will automatically be removed from the objects type. This can be used to remove the gf from the start of all the gnue-forms objects. If set to None (the default) then the behaviour will be the old style which removes the first two characters from the type.
Returns:
The XML tag to use
           (type=string)

iterator(self, test=None, types=(), includeSelf=True)

Return a python iterator of child objects.
Parameters:
test - A function that should return true or false to indicate whether a GObject should be included in the iterator. This method will be passed a GObj instance. e.g., test=lambda obj: obj._type in ('GFField,'GFEntry')
           (type=method)
types - A list of valid child types to return. E.g., types=('GFField','GFEntry')
           (type=list)
includeSelf - Should the current object be included in the tests?
           (type=boolean)
Returns:
An iterator of matching objects

maxInits(self)

maxInits returns the maximum size of all the _inits list from this object or it's children

phaseInit(self, iterations=0)

Starts GNUe's phased initialization system from this object down.

Typically called from within a GParser instance. phaseInit interates thru the GObj tree as many times as necessary to fully initialize the tree. It determines the number of iterations to perform during it's first pass down the tree.

phaseInit looks for a private list variable called _inits that contains a list of functions to execute. Here is an example from gnue-forms GFForm object.

self._inits = [self.primaryInit, None, self.secondaryInit]

This list tells phase init to execute the self.primaryInit function during the first iteration of the initialization process. During the seconds pass through it does nothing on these objects. During the third pass through it executes self.secondaryInit.

Some may question why we don't do all initialization logic inside the python objects __init__ functions. Frequently you may find that a parent object may need specific infomation from some of its children to properly initialize itself. This type of logic cannot be places into an __init__ as the children may not be loaded yet or may not yet have the needed information.
Parameters:
iterations - Limits the number of passes to the specified number.

showTree(self, indent=0)

A recusive function to print an indented text representation of the GObj tree from this object down. This is usefull for debugging purposes.
Parameters:
indent - Sets the level of indention. Used during recursion to properly indent the tree.
           (type=int)

walk(self, function, *args, **parms)

Function that recursively walks down through a tree of ParserObj instances and applies a function to them.
Parameters:
function - the function to call for every element found in the tree


GNUe Home

Public API

Developer's Corner