[XML-SIG] prepare_input_source and relative path

Sylvain Thénault Sylvain.Thenault at logilab.fr
Wed Apr 6 12:15:49 CEST 2005


Hi !

after some times working on other stuff, I've remembered that I had
still the prepare_input_source patch pending. I've joined to this
message the patch as it is now, and it's well working for me. I'll
check it in in the next few days if no one objects. I also think that
having a new release once this patch is applied would be a very good
thing since it fixes some important xml compliance problem, such as
those reported in :

http://sourceforge.net/tracker/index.php?func=detail&aid=616431&group_id=6473&atid=106473
http://bugs.debian.org/213324
http://bugs.debian.org/182967

it may even fix sf bugs #749284 and #567411 which are related to system
id problems, but I'm not sure at all for those one...

regards


PS: i'm not sure I should checkin the test_Uri.py file since it depends
on Ft test tools, and I've no time to backport it to use unittest only.
-- 
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
+++ /home/syt/cvs_work/_xmlplus/sax/saxutils.py	2005-04-06 11:55:50.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
@@ -513,19 +515,29 @@
             source.setSystemId(f.name)
 
     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 a base is given, sysid may be relative to it, make the
+    # join before isfile() test
+    if base:
+        basehead = os.path.split(os.path.abspath(base))[0]
+        path = os.path.join(basehead, sysid)
+    else:
+        path = os.path.abspath(sysid)
+    if os.path.isfile(path):
+        sysid = 'file:%s' % path
+    elif base:
+        sysid = Absolutize(sysid, base)
+    #assert IsAbsolute(sysid)
+    return MakeUrllibSafe(sysid)
+    
 # ===========================================================================
 #
 # DEPRECATED SAX 1.0 CLASSES
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Uri.py
Type: text/x-python
Size: 16518 bytes
Desc: not available
Url : http://mail.python.org/pipermail/xml-sig/attachments/20050406/b17b2adc/Uri-0001.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_saxutils.py
Type: text/x-python
Size: 2062 bytes
Desc: not available
Url : http://mail.python.org/pipermail/xml-sig/attachments/20050406/b17b2adc/test_saxutils-0001.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_Uri.py
Type: text/x-python
Size: 37608 bytes
Desc: not available
Url : http://mail.python.org/pipermail/xml-sig/attachments/20050406/b17b2adc/test_Uri-0001.py


More information about the XML-SIG mailing list