Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0872e05

Browse files
committed
Fix handling of file inputs on Windows; passing them to urllib.urlopen()
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.
1 parent 1bac645 commit 0872e05

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/xml/sax/saxutils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,16 @@ def prepare_input_source(source, base = ""):
198198
source = xmlreader.InputSource(source)
199199
source.setByteStream(f)
200200

201-
if source.getByteStream() == None:
201+
if source.getByteStream() is None:
202202
sysid = source.getSystemId()
203-
if urlparse.urlparse(sysid)[0] == '':
203+
if os.path.isfile(sysid):
204204
basehead = os.path.split(os.path.normpath(base))[0]
205205
source.setSystemId(os.path.join(basehead, sysid))
206+
f = open(sysid, "rb")
206207
else:
207208
source.setSystemId(urlparse.urljoin(base, sysid))
209+
f = urllib.urlopen(source.getSystemId())
208210

209-
source.setByteStream(urllib.urlopen(source.getSystemId()))
211+
source.setByteStream(f)
210212

211213
return source

0 commit comments

Comments
 (0)