commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r8936 - trunk/gnue-common/src/definitions


From: jcater
Subject: [gnue] r8936 - trunk/gnue-common/src/definitions
Date: Thu, 26 Oct 2006 19:59:00 -0500 (CDT)

Author: jcater
Date: 2006-10-26 19:59:00 -0500 (Thu, 26 Oct 2006)
New Revision: 8936

Modified:
   trunk/gnue-common/src/definitions/GParser.py
   trunk/gnue-common/src/definitions/GParserHelpers.py
Log:
move methods that GParser expects to exist out of GObj and into ParserObj; 
only call buildObject on GObj's

Modified: trunk/gnue-common/src/definitions/GParser.py
===================================================================
--- trunk/gnue-common/src/definitions/GParser.py        2006-10-26 17:58:28 UTC 
(rev 8935)
+++ trunk/gnue-common/src/definitions/GParser.py        2006-10-27 00:59:00 UTC 
(rev 8936)
@@ -233,15 +233,15 @@
   # ---------------------------------------------------------------------------
 
   xmlElements = {}
+  # This is a hack, currently used only by GRPassThru
+  xmlMasqueradeNamespaceElements = None
 
+  # Use namespace as a prefix in GObjects
+  xmlNamespaceAttributesAsPrefixes = False
+
   def __init__ (self):
 
-    # This is a hack, currently used only by GRPassThru
-    self.xmlMasqueradeNamespaceElements = None
 
-    # Use namespace as a prefix in GObjects
-    self.xmlNamespaceAttributesAsPrefixes = False
-
     # Internal stuff
     self.xmlStack        = []
     self.nameStack       = []
@@ -615,9 +615,11 @@
     if not child:
       return
 
-    inits = child._buildObject ()
-    self._phaseInitCount = (inits != None and inits > self._phaseInitCount \
-                            and inits or self._phaseInitCount)
+    if hasattr(child, '_buildObject'): 
+        inits = child._buildObject()
+        self._phaseInitCount = (inits != None and inits > self._phaseInitCount 
\
+                                and inits or self._phaseInitCount)
+        
     assert gDebug (7, "</%s>" % tname)
     
     self.object_created(child)

Modified: trunk/gnue-common/src/definitions/GParserHelpers.py
===================================================================
--- trunk/gnue-common/src/definitions/GParserHelpers.py 2006-10-26 17:58:28 UTC 
(rev 8935)
+++ trunk/gnue-common/src/definitions/GParserHelpers.py 2006-10-27 00:59:00 UTC 
(rev 8936)
@@ -53,7 +53,7 @@
 
   # ---------------------------------------------------------------------------
   # Constructor
-  # ---------------------------------------------------------------------------
+   # 
---------------------------------------------------------------------------
 
   def __init__ (self, parent = None, type = '_NotSet_'):
 
@@ -305,8 +305,70 @@
     return self._dumpXML_ (lookupDict, treeDump, gap, xmlnamespaces,
         textEncoding, stripPrefixes, escape)
 
+  # ---------------------------------------------------------------------------
+  # Function for traversing an object tree
+  # ---------------------------------------------------------------------------
 
+  def walk (self, function, *args, **parms):
+    """
+    Function that recursively walks down through a tree of L{ParserObj}
+    instances and applies a function to them.
+
+    @param function: the function to call for every element found in the tree
+    """
+
+    function (self, *args, **parms)
+    for child in self._children:
+      if isinstance (child, GObj):
+        child.walk (function, *args, **parms)
+
+
   # ---------------------------------------------------------------------------
+  # Get an iterator for child objects
+  # ---------------------------------------------------------------------------
+
+  def iterator (self, test = None, types = (), includeSelf = True):
+    """
+    Return a python iterator of child objects.
+
+    @param 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 test: method
+
+    @param types: A list of valid child types to return.
+           E.g., types=('GFField','GFEntry')
+    @type types: list
+
+    @param includeSelf: Should the current object be included in the tests?
+    @type includeSelf: boolean
+
+    @return: An iterator of matching objects
+
+    """
+    if includeSelf:
+      objects = [self]
+    else:
+      objects = self._children
+    set = []
+
+    def _includable (object):
+      include = True
+      if test:
+        include = include and test (object)
+      if types:
+        include = include and object._type in types
+      if include:
+        set.append (object)
+
+    for child in objects:
+      child.walk (_includable)
+
+    return _GObjectIterator (set)
+
+
+  # ---------------------------------------------------------------------------
   # Find the first parent instance of a given type
   # ---------------------------------------------------------------------------
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]