diff --git a/Lib/urllib.py b/Lib/urllib.py index 1b5baaaf95f1..c12f4519cca6 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -325,13 +325,19 @@ def open_local_file(self, url): 'Content-Type: %s\n' % (mtype or 'text/plain'))) host, file = splithost(url) if not host: + urlfile = file + if file[:1] == '/': + urlfile = 'file://' + file return addinfourl(open(url2pathname(file), 'rb'), - headers, 'file:'+file) + headers, urlfile) host, port = splitport(host) if not port \ and socket.gethostbyname(host) in (localhost(), thishost()): + urlfile = file + if file[:1] == '/': + urlfile = 'file://' + file return addinfourl(open(url2pathname(file), 'rb'), - headers, 'file:'+file) + headers, urlfile) raise IOError, ('local file error', 'not on local host') # Use FTP protocol