mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Sjoerd Mullender writes:
Urllib makes the URL of the opened file available through the geturl method of the returned object. For local files, this consists of file: plus the name of the file. This results in an invalid URL if the file name was relative. This patch fixes this so that the returned URL is just a relative URL in that case. When the file name is absolute, the URL returned is of the form file:///absolute/path. [I guess that a URL of the form "file:foo.html" is illegal... GvR]
This commit is contained in:
parent
ff3a278d3b
commit
336a201d4f
1 changed files with 8 additions and 2 deletions
|
@ -325,13 +325,19 @@ class URLopener:
|
||||||
'Content-Type: %s\n' % (mtype or 'text/plain')))
|
'Content-Type: %s\n' % (mtype or 'text/plain')))
|
||||||
host, file = splithost(url)
|
host, file = splithost(url)
|
||||||
if not host:
|
if not host:
|
||||||
|
urlfile = file
|
||||||
|
if file[:1] == '/':
|
||||||
|
urlfile = 'file://' + file
|
||||||
return addinfourl(open(url2pathname(file), 'rb'),
|
return addinfourl(open(url2pathname(file), 'rb'),
|
||||||
headers, 'file:'+file)
|
headers, urlfile)
|
||||||
host, port = splitport(host)
|
host, port = splitport(host)
|
||||||
if not port \
|
if not port \
|
||||||
and socket.gethostbyname(host) in (localhost(), thishost()):
|
and socket.gethostbyname(host) in (localhost(), thishost()):
|
||||||
|
urlfile = file
|
||||||
|
if file[:1] == '/':
|
||||||
|
urlfile = 'file://' + file
|
||||||
return addinfourl(open(url2pathname(file), 'rb'),
|
return addinfourl(open(url2pathname(file), 'rb'),
|
||||||
headers, 'file:'+file)
|
headers, urlfile)
|
||||||
raise IOError, ('local file error', 'not on local host')
|
raise IOError, ('local file error', 'not on local host')
|
||||||
|
|
||||||
# Use FTP protocol
|
# Use FTP protocol
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue