Package gnue :: Package common :: Package definitions :: Module GParserHelpers :: Class ParserObj
[show private | hide private]

Type ParserObj

object --+
         |
        ParserObj

Known Subclasses:
GObj

Base class for objects handled by a gnue.common.definitions.GParser.
Method Summary
  __init__(self, parent, type)
  _diffActionWalker_(self, obj, action)
Set the action attribute of a given object to the specified action.
  _dumpXML_(self, lookupDict, treeDump, gap, xmlnamespaces, textEncoding, stripPrefixes, escape)
Return a XML representation of the object.
  _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
  __repr__(x)
Return repr(x)...
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
Return str(x)...

Method Details

__init__(self, parent=None, type='_NotSet_')
(Constructor)

Overrides:
__builtin__.object.__init__

_diffActionWalker_(self, obj, action)

Set the action attribute of a given object to the specified action.
Parameters:
obj - ParserObj to set the action attribute
action - the action to be set

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

Return a XML representation of the object.
Parameters:
lookupDict - dictionary describing the XML entities, their attributes and types
treeDump - if True, also include a XML representation of all children
gap - string defining the current indentation level
xmlnamespaces - dictionary with the available XML namespaces
textEncoding - encoding used to transform string-type attributes into unicode. If textEncoding is set to '<locale>' (default) it will be set to the configuration variable 'textEncoding', i.e. from gnue.conf
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.
escape - if set to True the resulting XML string should be escaped
Returns:
a string with the object's XML representation

_getAsContents_(self)

Get the contents of this object. Usually this will be used by getChildrenAsContents ().
Returns:
the contents of the object.

_id_(self, maxIdLength=None)

Return a compareable and identifying id of an object within a tree. Usually this is it's name (if available) or it's object type (as given in the constructor).
Parameters:
maxIdLength - if not None only return up to maxIdLength characters.
Returns:
id for the instance

_set_initial_attributes_(self, attributes)

Set attributes loaded by GParser.
Parameters:
attributes - dictionary of attributes

addChild(self, child)

Add an object to the list of children
Parameters:
child - The object to add.
           (type=ParserObj derived class)

assign(self, source, recursive=False)

Assign all attributes from a given object to this one. If the recursive option is given, all of the source's children will be duplicated and assigned to this object.
Parameters:
source - the ParserObj instance to assign attributes from
recursive - if True, all children of source will be recursiveley duplicated and assigned to this object
Raises:
AssignmentTypeError - if the source object is another class than this object

diff(self, goal, maxIdLength=None)

Build an object tree representing the difference between two object trees.
Parameters:
goal - ParserObj tree to compare this object's tree to.
maxIdLength - if defined, use only up to maxIdLength characters of the object name to check for identity.
Returns:

ParserObj tree representing the difference. Every object in this tree has an additional attribute _action which can contain one of the following values:

* add: the object is only available in the 'goal' tree * change: the object is avaialable in both trees, but differs * remove: the object is only available in the 'source' tree

dumpXML(self, lookupDict, treeDump=False, gap='  ', xmlnamespaces={}, textEncoding='<locale>', stripPrefixes=None, escape=True)

Return a XML representation of the object.
Parameters:
lookupDict - dictionary describing the XML entities, their attributes and types
treeDump - if True, also include a XML representation of all children
gap - string defining the current indentation level
xmlnamespaces - dictionary with the available XML namespaces
textEncoding - encoding used to transform string-type attributes into unicode. If textEncoding is set to '<locale>' (default) it will be set to the configuration variable 'textEncoding', i.e. from gnue.conf
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.
escape - if set to True the resulting XML string should be escaped
Returns:
a string with the object's XML representation

findChildNamed(self, name, childType=None)

Moves downward though the children of an object till it finds the child with the specified name.
Parameters:
name - The name to search for
childType - The type of object to search for, if None then any type will match.
Returns:
The child with the matching name, or None if child not found

findChildOfType(self, childType, includeSelf=True, allowAllChildren=False)

Moves downward through the children of an object till it finds the child of the specified type.
Parameters:
childType - type of the child to be searched for
includeSelf - if set to True, the search starts with this instance
allowAllChildren - if set to True, the search will be performed recursive.
Returns:
the first child of the requested type or None if no such object is found.

findChildrenOfType(self, childType, includeSelf=True, allowAllChildren=False)

Find all children of a specific type.
Parameters:
childType - type of the objects to match
includeSelf - if set to True, the search will be started with this instance.
allowAllChildren - if set to True, recursivley step down the object tree and add all children of the requested type
Returns:
sequence with all child objects matching the requested type

findParentOfType(self, parentType, includeSelf=True)

Moves upward though the parents of an object till it finds the parent of the specified type.
Parameters:
parentType - type of the object to be found
includeSelf - if set to True, the search starts with this object instead of the object's parent.
Returns:
the first parent object of the given type or None if no such object was found.

getChildrenAsContent(self)

Returns the content of any GContent objects that are children of this object.
Returns:
The contents of the children

getDescription(self)

Return a useful description of the object. Currently used by GNUe Designer.

getParent(self)

Returns the immediate parent of an object instance in a GObj tree.
Returns:
The parent of the object in the GObj tree.
           (type=any)

merge(self, other, maxIdLength=None, overwrite=False)

Merge another object tree into this tree.

All attributes and child nodes from the other object are merged into this object. If any child node exists in both objects with the same name (id), the merge is done recursively.
Parameters:
other - ParserObj tree to be merged into this object tree
maxIdLength - maximum length of the name to compare, useful if any of the objects has the identifier truncated
overwrite - whether attributes and children of the other object should overwrite attributes and children of this object

setParent(self, newParent)

Set the immediate parent of an object instance in a GObj tree
Parameters:
newParent - instance to be set as parent


GNUe Home

Private API

Developer's Corner