commit-gnue
[Top][All Lists]
Advanced

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

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


From: jamest
Subject: [gnue] r7083 - trunk/gnue-common/src/definitions
Date: Wed, 2 Mar 2005 21:31:36 -0600 (CST)

Author: jamest
Date: 2005-03-02 21:31:35 -0600 (Wed, 02 Mar 2005)
New Revision: 7083

Modified:
   trunk/gnue-common/src/definitions/GObjects.py
Log:
modify dumpXML to take a list of prefixes to strip 
from object types when building xml output.  This is to
allow newer projects to not require all their object types
to have 2 character prefixes to their xml type (GFField vs field).
Default behaviour matches the old style at this time to
prevent breakage.


Modified: trunk/gnue-common/src/definitions/GObjects.py
===================================================================
--- trunk/gnue-common/src/definitions/GObjects.py       2005-03-02 22:07:34 UTC 
(rev 7082)
+++ trunk/gnue-common/src/definitions/GObjects.py       2005-03-03 03:31:35 UTC 
(rev 7083)
@@ -208,17 +208,32 @@
   def addChild(self, child):
     self._children.append(child)
 
-  #
-  # dumpXML
-  #
-  # Dumps an XML representation of the object
-  #
-
-  def getXmlTag(self):
-    return string.lower(string.replace(self._type[2:],'_','-'))
-
+  def getXmlTag(self, stripPrefixes=None):
+    """
+    Returns the xml tag to be used to represent the object.
+    
+    @param 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.
+    @type multipler: list of strings
+    @return: The xml tag to use
+    @rtype: string
+    """
+    if stripPrefixes == None:
+      return string.lower(string.replace(self._type[2:],'_','-'))
+    for prefix in stripPrefixes:
+      if prefix == self._type[:len(prefix)]:
+        return string.lower(string.replace(self._type[len(prefix):],'_','-'))
+    return string.lower(string.replace(self._type,'_','-'))  
+    
   def dumpXML(self, lookupDict, treeDump=None, gap="  ", xmlnamespaces={},
-              textEncoding='<locale>'):
+              textEncoding='<locale>', stripPrefixes=None):
+    """
+    Dumps an XML representation of the object
+    """
     xmlns = ""
     xmlnsdef = ""
     if textEncoding=='<locale>':
@@ -258,7 +273,7 @@
     except AttributeError:
       pass
 
-    xmlEntity = self.getXmlTag()
+    xmlEntity = self.getXmlTag(stripPrefixes)
     xmlString = "%s<%s%s%s" % (gap[:-2],xmlns, xmlEntity, xmlnsdef)
 
     indent = len(xmlString)
@@ -339,7 +354,7 @@
       if treeDump:
         for child in self._children:
           xmlString += child.dumpXML(lookupDict, 1,gap+"  ",
-              textEncoding=textEncoding, xmlnamespaces=xmlnamespaces)
+              textEncoding=textEncoding, xmlnamespaces=xmlnamespaces, 
stripPrefixes=stripPrefixes)
 
       if hasContent:
         xmlString += "</%s%s>\n" % (xmlns, xmlEntity)
@@ -356,14 +371,11 @@
       if isinstance(child, GObj):
         child.walk(function, *args, **parms)
 
-  #
-  # findParentOfType
-  #
-  # Moves upward though the parents of an object till
-  # it finds the parent of the specified type
-  #
   def findParentOfType(self,type, includeSelf=1):
-
+    """
+    Moves upward though the parents of an object till
+    it finds the parent of the specified type
+    """
     if includeSelf:
       parentObject = self
     else:





reply via email to

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