commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8430 - trunk/gnue-common/src/logic


From: reinhard
Subject: [gnue] r8430 - trunk/gnue-common/src/logic
Date: Wed, 19 Apr 2006 06:50:44 -0500 (CDT)

Author: reinhard
Date: 2006-04-19 06:50:43 -0500 (Wed, 19 Apr 2006)
New Revision: 8430

Modified:
   trunk/gnue-common/src/logic/GTriggerCore.py
   trunk/gnue-common/src/logic/NamespaceCore.py
Log:
Build up a good repr() name for the namespace objects.


Modified: trunk/gnue-common/src/logic/GTriggerCore.py
===================================================================
--- trunk/gnue-common/src/logic/GTriggerCore.py 2006-04-19 10:32:17 UTC (rev 
8429)
+++ trunk/gnue-common/src/logic/GTriggerCore.py 2006-04-19 11:50:43 UTC (rev 
8430)
@@ -90,7 +90,7 @@
     # Construct a namespace object tree for an XML object tree
     # -------------------------------------------------------------------------
 
-    def create_namespace_object(self, global_namespace):
+    def create_namespace_object(self, global_namespace, namespace_name):
         """
         Construct a namespace object tree from an XML
         (L{definitions.GObject.GObj}) object tree.
@@ -99,11 +99,6 @@
         L{definitions.GObject.GObj} in the object.
         """
 
-        # Do not create a namespace object for xml objects with no "name"
-        # property.
-        if not hasattr(self, 'name') or self.name is None:
-            return None
-
         # Create dictionary with methods as defined
         methods = {}
         for (name, definition) in self._triggerFunctions.items():
@@ -126,6 +121,7 @@
 
         # Create the namespace object
         namespace_object = NamespaceElement(
+                name       = namespace_name,
                 xml_object = self,
                 get_method = self._triggerGet,
                 set_method = self._triggerSet,
@@ -135,14 +131,14 @@
         # Process the children of this xml object
         if len(self._children):
             self.__add_children(self._children, namespace_object,
-                    global_namespace)
+                    global_namespace, namespace_name)
 
         # Remember the namespace object
         self._namespace_object = namespace_object
 
         # Add the namespace object to global namespace if the xml object
-        # requests it
-        if self._triggerGlobal:
+        # requests it and the object has a name
+        if self._triggerGlobal and hasattr(self, 'name') and self.name:
             global_namespace[self.name] = namespace_object
 
         return namespace_object
@@ -152,25 +148,40 @@
     # Add children to a Namespace object matching the children of the GObj
     # -------------------------------------------------------------------------
 
-    def __add_children(self, children, namespace_object, global_namespace):
+    def __add_children(self, children, namespace_object, global_namespace,
+            namespace_prefix):
         """
         Create child namespace objects according to child XML objects
         """
         for child in children:
+            # Skip children that are not namespace enabled
             if not isinstance(child, GTriggerCore):
                 continue
 
-            child_object = child.create_namespace_object (global_namespace)
+            # Skip GRPassThrough objects
+            if hasattr(child, 'name') and child.name \
+                    and child.name.startswith('__'):
+                if len(child._children):
+                    self.__add_children(child._children, namespace_object,
+                            global_namespace, namespace_prefix)
+                continue
 
+            # Decide which name this child should present on repr()
+            if hasattr(child, 'name') and child.name:
+                namespace_name = namespace_prefix + '.' + child.name
+            else:
+                namespace_name = namespace_prefix + '.<unnamed %s>' \
+                        % child.getXmlTag()
+
+            # Create namespace objects for all children, even for those without
+            # a name - one of the children might have triggers attached, so we
+            # would need a "self" namespace object
+            child_object = child.create_namespace_object (global_namespace,
+                    namespace_name)
+
             # Add this objects children to its namespace by their name
-            if child_object:
-                # skip on GRPassThru objects
-                if child.name.startswith('__'):
-                    if len(child._children):
-                        self.__add_children(child._children, namespace_object,
-                                global_namespace)
-                else:
-                    namespace_object.__dict__[child.name] = child_object
+            if hasattr(child, 'name') and child.name:
+                namespace_object.__dict__[child.name] = child_object
 
 
 # =============================================================================
@@ -210,7 +221,7 @@
     # Constructor
     # -------------------------------------------------------------------------
 
-    def __init__(self, xml_object, get_method, set_method, methods,
+    def __init__(self, name, xml_object, get_method, set_method, methods,
             properties):
         """
         Initialize a namespace proxy object.
@@ -218,6 +229,7 @@
 
         checktype (xml_object, GTriggerCore)
 
+        self.__name       = name
         self.__xml_object = xml_object
         self.__get_method = get_method
         self.__set_method = set_method
@@ -234,7 +246,7 @@
     # -------------------------------------------------------------------------
 
     def __repr__(self):
-        return self.__xml_object.name
+        return self.__name
 
 
     # -------------------------------------------------------------------------
@@ -308,7 +320,7 @@
         if self.__get_method:
             return str(self.__get_method())
         else:
-            return self.__xml_object.name
+            return self.__name
 
     # -------------------------------------------------------------------------
 

Modified: trunk/gnue-common/src/logic/NamespaceCore.py
===================================================================
--- trunk/gnue-common/src/logic/NamespaceCore.py        2006-04-19 10:32:17 UTC 
(rev 8429)
+++ trunk/gnue-common/src/logic/NamespaceCore.py        2006-04-19 11:50:43 UTC 
(rev 8430)
@@ -56,6 +56,8 @@
         # circular import
         checktype (xml_object, GObj)
 
+        self.__root_name = rootName
+
         self._globalNamespace = {}
 
         self._globalNamespace[rootName] = \
@@ -74,4 +76,5 @@
         Depreciated. Use xml_object.create_namespace_object instead.
         """
 
-        return xml_object.create_namespace_object(self._globalNamespace)
+        return xml_object.create_namespace_object(self._globalNamespace,
+                self.__root_name)





reply via email to

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