]> granicus.if.org Git - python/commitdiff
Fix handling of file inputs on Windows; passing them to urllib.urlopen()
authorFred Drake <fdrake@acm.org>
Tue, 26 Sep 2000 17:23:09 +0000 (17:23 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 26 Sep 2000 17:23:09 +0000 (17:23 +0000)
caused the drive letter to cause urlopen() to think it was an unrecognized
URL scheme.  This only passes system ids to urlopen() if the file does not
exist.  It works on Windows & Unix.

It should work everywhere else as well.

Lib/xml/sax/saxutils.py

index 3f130f3af5909fa3e6fee983ffd481d198c1bf2d..a25b41f09637aac6563b2aef9270c25e5de910e8 100644 (file)
@@ -198,14 +198,16 @@ def prepare_input_source(source, base = ""):
         source = xmlreader.InputSource(source)
         source.setByteStream(f)
 
-    if source.getByteStream() == None:
+    if source.getByteStream() is None:
         sysid = source.getSystemId()
-        if urlparse.urlparse(sysid)[0] == '':
+        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 = urllib.urlopen(source.getSystemId())
             
-        source.setByteStream(urllib.urlopen(source.getSystemId()))
+        source.setByteStream(f)
         
     return source