Skip to content

Commit 18e4dd7

Browse files
committed
Fixing the errors trigerred in test_urllib2net. Related to issue8656.
1 parent 6057ba1 commit 18e4dd7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Lib/urllib2.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,22 +1276,25 @@ def open_local_file(self, req):
12761276
import email.utils
12771277
import mimetypes
12781278
host = req.get_host()
1279-
file = req.get_selector()
1280-
localfile = url2pathname(file)
1279+
filename = req.get_selector()
1280+
localfile = url2pathname(filename)
12811281
try:
12821282
stats = os.stat(localfile)
12831283
size = stats.st_size
12841284
modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
1285-
mtype = mimetypes.guess_type(file)[0]
1285+
mtype = mimetypes.guess_type(filename)[0]
12861286
headers = mimetools.Message(StringIO(
12871287
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
12881288
(mtype or 'text/plain', size, modified)))
12891289
if host:
12901290
host, port = splitport(host)
12911291
if not host or \
12921292
(not port and socket.gethostbyname(host) in self.get_names()):
1293-
return addinfourl(open(localfile, 'rb'),
1294-
headers, 'file://'+ host + file)
1293+
if host:
1294+
origurl = 'file://' + host + filename
1295+
else:
1296+
origurl = 'file://' + filename
1297+
return addinfourl(open(localfile, 'rb'), headers, origurl)
12951298
except OSError, msg:
12961299
# urllib2 users shouldn't expect OSErrors coming from urlopen()
12971300
raise URLError(msg)

0 commit comments

Comments
 (0)