commit-gnue
[Top][All Lists]
Advanced

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

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


From: reinhard
Subject: [gnue] r9535 - trunk/gnue-common/src/definitions
Date: Thu, 26 Apr 2007 11:36:13 -0500 (CDT)

Author: reinhard
Date: 2007-04-26 11:36:13 -0500 (Thu, 26 Apr 2007)
New Revision: 9535

Modified:
   trunk/gnue-common/src/definitions/GParser.py
Log:
Execute the actual import immediately when parsing the statement rather than in
phase 1 init.


Modified: trunk/gnue-common/src/definitions/GParser.py
===================================================================
--- trunk/gnue-common/src/definitions/GParser.py        2007-04-26 14:27:47 UTC 
(rev 9534)
+++ trunk/gnue-common/src/definitions/GParser.py        2007-04-26 16:36:13 UTC 
(rev 9535)
@@ -132,6 +132,7 @@
   dh.url = url
   dh.checkRequired = checkRequired
   dh.parser = parser
+  dh.root_attributes = attributes
 
   dh.initValidation ()
 
@@ -167,16 +168,6 @@
 
   dh.finalValidation ()
 
-  # Set the root object's attributes
-  #
-  # There should only be 1 root object but GNUe Forms
-  # allows for nested forms so we have to walk the tree
-  #
-  #
-  #object.__dict__.update(attributes)
-  if hasattr(object,'walk'):
-    object.walk (__addAttributesWalker, attributes = attributes)
-
   if initialize:
     assert gDebug (7, "Initializing the object tree starting at %s" % (object))
     object.phaseInit (dh._phaseInitCount)
@@ -188,14 +179,6 @@
   return object
 
 
-# -----------------------------------------------------------------------------
-
-def __addAttributesWalker (object, attributes = {}):
-
-  if isinstance (object, GRootObj):
-    object.__dict__.update (attributes)
-
-
 # ---------------------------------------------------------------------------
 # Remove redundant whitespace characters from a string
 # ---------------------------------------------------------------------------
@@ -552,6 +535,15 @@
     # Set the attributes
     object._set_initial_attributes_(lattrs)
 
+    # If it is an import, replace the placeholder with the actual object
+    if isinstance(object, GImportItem):
+        object = object.get_imported_item()
+        self.xmlStack[0].addChild(object)
+        object.setParent(self.xmlStack[0])
+
+    if isinstance(object, GRootObj):
+        object.__dict__.update(self.root_attributes)
+
     self.xmlStack.insert (0, object)
     self.nameStack.insert (0, tname)
 
@@ -708,22 +700,15 @@
     GObj.__init__ (self, parent, type = type)
 
     self._loadedxmlattrs = {} # Set by parser
-    self._inits          = [self.__primaryInit]
     self._xmlParser      = self.findParentOfType (None)._xmlParser
 
 
   # ---------------------------------------------------------------------------
-  # Prepare the type or the importclass for the object
+  # Do the actual importing
   # ---------------------------------------------------------------------------
 
-  def _buildObject (self):
-    """
-    After the parser has built the object determine either the apropriate type
-    or the importclass for the object. This will be needed by the phase-init.
+  def get_imported_item(self):
 
-    @returns: number of phase initializations needed by this object
-    """
-
     if hasattr (self, '_xmltag'):
       self._type = 'GC%s' % self._xmltag
 
@@ -731,15 +716,6 @@
       item = self._type [9:].lower ()
       self._importclass = self._xmlParser.getXMLelements () [item]['BaseClass']
 
-    return GObj._buildObject (self)
-
-
-  # ---------------------------------------------------------------------------
-  # Phase I init
-  # ---------------------------------------------------------------------------
-
-  def __primaryInit (self):
-
     # Open the library and convert it into objects
     handle = openResource (self.library)
     parent = self.findParentOfType (None)
@@ -761,15 +737,13 @@
     rv = self.__findImportItem (self, form, id)
     if rv is not None:
       rv._IMPORTED = True
-      rv.setParent (self)
-      self.addChild (rv)
 
       # transfer attributes reassigned during the import
       for key in [k for k in self._loadedxmlattrs.keys () if k [0] != '_']:
         rv.__dict__ [key] = self._loadedxmlattrs [key]
         assert gDebug (7, ">>> Moving %s" % key)
 
-      rv._buildObject ()
+      return rv
 
     else:
       raise MarkupError, \
@@ -806,6 +780,11 @@
 # Generic class for importable objects
 # =============================================================================
 
+# This works like this:
+# <import trigger="trigger1,trigger2" entry="entry1,entry2">
+# which is horrible, doesn't make much sense (give the deep nesting of things
+# in forms) and should most probably be removed completely. -- Reinhard
+
 class GImport (GObj):
 
   # ---------------------------------------------------------------------------





reply via email to

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