[XML-SIG] prepare_input_source and relative path

Sylvain Thénault Sylvain.Thenault at logilab.fr
Fri Apr 8 11:30:11 CEST 2005


the same patch with just outdated comments removed...
-- 
Sylvain Thénault                               LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org

-------------- next part --------------
--- /usr/lib/python2.3/site-packages/_xmlplus/sax/saxutils.py	2004-11-29 13:36:36.000000000 +0100
+++ cvs_work/_xmlplus/sax/saxutils.py	2005-04-08 11:29:42.000000000 +0200
@@ -10,6 +10,8 @@
 import xmlreader
 import sys, _exceptions, saxlib
 
+from xml.Uri import Absolutize, MakeUrllibSafe,IsAbsolute
+
 try:
     _StringTypes = [types.StringType, types.UnicodeType]
 except AttributeError: # 1.5 compatibility:UnicodeType not defined
@@ -510,22 +512,25 @@
         source = xmlreader.InputSource()
         source.setByteStream(f)
         if hasattr(f, "name"):
-            source.setSystemId(f.name)
+            source.setSystemId(absolute_system_id(f.name, base))
 
     if source.getByteStream() is None:
-        sysid = source.getSystemId()
-        if os.path.isfile(sysid):
-            basehead = os.path.split(os.path.normpath(base))[0]
-            source.setSystemId(os.path.join(basehead, sysid))
-            f = open(sysid, "rb")
-        else:
-            source.setSystemId(urlparse.urljoin(base, sysid))
-            f = urllib2.urlopen(source.getSystemId())
-
+        sysid = absolute_system_id(source.getSystemId(), base)
+        source.setSystemId(sysid)
+        f = urllib2.urlopen(sysid)
         source.setByteStream(f)
 
     return source
 
+
+def absolute_system_id(sysid, base=''):
+    if os.path.exists(sysid):
+        sysid = 'file:%s' % os.path.abspath(sysid)
+    elif base:        
+        sysid = Absolutize(sysid, base)
+    assert IsAbsolute(sysid)
+    return MakeUrllibSafe(sysid)
+    
 # ===========================================================================
 #
 # DEPRECATED SAX 1.0 CLASSES


More information about the XML-SIG mailing list