From misa at rpath.com Tue Jan 31 16:07:46 2012 From: misa at rpath.com (Mihai Ibanescu) Date: Tue, 31 Jan 2012 21:07:46 +0000 Subject: rpath-xmllib: Hopefully properly handling xml:base attributes Message-ID: <201201312107.q0VL7kDo016618@scc.eng.rpath.com> changeset: 14e25159a12e user: Mihai Ibanescu date: Tue, 31 Jan 2012 16:06:23 -0500 Hopefully properly handling xml:base attributes diff --git a/rpath_xmllib/api1.py b/rpath_xmllib/api1.py --- a/rpath_xmllib/api1.py +++ b/rpath_xmllib/api1.py @@ -19,6 +19,7 @@ """ import os +import sys import StringIO from xml import sax @@ -344,6 +345,12 @@ # Now walk all attributes and qualify them with the namespace if # necessary for (nsName, attrName), attrVal in nonNsAttr: + if nsName == 'xml' and nsName not in self._nsMap: + # Bare xml: with no xmlns:xml specification + # Reading http://www.w3.org/TR/xmlbase/#syntax + # we'll assume that an undefined xml namespace prefix is + # bound to DataBinder.xmlBaseNamespace + self._nsMap[nsName] = self._nsAttributes[nsName] = DataBinder.xmlBaseNamespace if nsName is not None and nsName not in self._nsMap: raise UndefinedNamespaceError(nsName) self._otherAttributes[(nsName, attrName)] = attrVal @@ -855,6 +862,7 @@ """ xmlSchemaNamespace = 'http://www.w3.org/2001/XMLSchema-instance' + xmlBaseNamespace = 'http://www.w3.org/XML/1998/namespace' BindingHandlerFactory = BindingHandler def __init__(self, typeDict = None): @@ -1035,7 +1043,8 @@ try: parser.parse(stream) except sax.SAXParseException: - raise InvalidXML + exc_info = sys.exc_info() + raise InvalidXML, exc_info[1], exc_info[2] rootNode = self.contentHandler.rootNode self.contentHandler.rootNode = None return rootNode