commit-gnue
[Top][All Lists]
Advanced

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

r6761 - trunk/gnue-common/src/definitions


From: jcater
Subject: r6761 - trunk/gnue-common/src/definitions
Date: Tue, 30 Nov 2004 17:25:53 -0600 (CST)

Author: jcater
Date: 2004-11-30 17:25:52 -0600 (Tue, 30 Nov 2004)
New Revision: 6761

Modified:
   trunk/gnue-common/src/definitions/GParser.py
Log:
Added support for a default namespaces and for ignoring unknown namespaces 
(used primarily for report filters); default behaviors are the same as before 
this commit.


Modified: trunk/gnue-common/src/definitions/GParser.py
===================================================================
--- trunk/gnue-common/src/definitions/GParser.py        2004-11-30 17:37:57 UTC 
(rev 6760)
+++ trunk/gnue-common/src/definitions/GParser.py        2004-11-30 23:25:52 UTC 
(rev 6761)
@@ -103,7 +103,7 @@
   dh.initValidation()
 
   # Tell the parser to use our handler
-  parser.setContentHandler(dh)  
+  parser.setContentHandler(dh)
 
   parser.parse(stream)
 
@@ -177,15 +177,29 @@
 #
 #######################################################
 class xmlHandler(xml.sax.ContentHandler):
+
+  # Set to default namespace (which would be dropped)
+  # i.e., if default namespace is "Foo", then <Foo:test> would
+  # just be processed as <test>.
+  default_namespace = None
+
+  # Drop any elements that have a namespaces we don't know about?
+  ignore_unknown_namespaces = False
+
   def __init__(self):
 
     self.xmlElements = {}
+
+    # This is a hack, currently used only by GRPassThru
     self.xmlMasqueradeNamespaceElements = None
-    self.xmlNamespaceAttributesAsPrefixes = 0
 
+    # Use namespace as a prefix in GObjects
+    self.xmlNamespaceAttributesAsPrefixes = False
+
+    # Internal stuff
     self.xmlStack = []
     self.nameStack = []
-    self.bootstrapflag = 0
+    self.bootstrapflag = False
     self.uniqueIDs = {}
     self.root = None
     self._phaseInitCount = 0
@@ -244,7 +258,7 @@
     attrs = {}
     loadedxmlattrs = {}
 
-    if not ns:
+    if not ns or ns == self.default_namespace:
       #
       # No namespace qualifier
       #
@@ -359,7 +373,7 @@
       except IndexError:
         tmsg = u_("Error processing <%(namespace)s:%(name)s> tag: root "
                   "element needs to be in default namespace") \
-               % {'namespace': ns,
+              % {'namespace': ns,
                   'name'     : name}
         raise MarkupError, tmsg
 
@@ -367,13 +381,16 @@
       object._xmlnamespace = ns
       object._listedAttributes = loadedxmlattrs.keys()
 
+    elif self.ignore_unknown_namespaces:
+      self.xmlStack.insert(0, None)
+      self.nameStack.insert(0, None)
+      return
     else:
       #
       # namespace qualifier and we are not masquerading
       #
-      print _("WARNING: Markup includes namespaces, but the current tool does "
-              "not include namespace support!")
-      sys.exit()
+      tmsg =  u_("WARNING: Markup includes unsupported namespace '%s'." ) % 
(ns)
+      raise MarkupError, tmsg
 
 
     # Save the attributes loaded from XML file
@@ -422,6 +439,10 @@
     ns, name = qtag
     self.nameStack.pop(0)
     child = self.xmlStack.pop(0)
+
+    if not child:
+      return
+
     inits = child._buildObject()
     self._phaseInitCount = (inits != None and inits > self._phaseInitCount \
                             and inits or self._phaseInitCount)





reply via email to

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