summaryrefslogtreecommitdiff
path: root/Lib/urllib2.py
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-05-08 05:00:11 +0000
committerSenthil Kumaran <orsenthil@gmail.com>2010-05-08 05:00:11 +0000
commit18e4dd74e06a8d036e46336041a72f3dae52b15c (patch)
tree6b13b6409d0f20ca943c2a56cbe3721fae110319 /Lib/urllib2.py
parent6057ba1f97ea19c484b03d5dd2f431e7767fefd1 (diff)
downloadcpython-git-18e4dd74e06a8d036e46336041a72f3dae52b15c.tar.gz
Fixing the errors trigerred in test_urllib2net. Related to issue8656.
Diffstat (limited to 'Lib/urllib2.py')
-rw-r--r--Lib/urllib2.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 84f78333e9..43ca53d1ce 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -1276,13 +1276,13 @@ class FileHandler(BaseHandler):
import email.utils
import mimetypes
host = req.get_host()
- file = req.get_selector()
- localfile = url2pathname(file)
+ filename = req.get_selector()
+ localfile = url2pathname(filename)
try:
stats = os.stat(localfile)
size = stats.st_size
modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
- mtype = mimetypes.guess_type(file)[0]
+ mtype = mimetypes.guess_type(filename)[0]
headers = mimetools.Message(StringIO(
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
(mtype or 'text/plain', size, modified)))
@@ -1290,8 +1290,11 @@ class FileHandler(BaseHandler):
host, port = splitport(host)
if not host or \
(not port and socket.gethostbyname(host) in self.get_names()):
- return addinfourl(open(localfile, 'rb'),
- headers, 'file://'+ host + file)
+ if host:
+ origurl = 'file://' + host + filename
+ else:
+ origurl = 'file://' + filename
+ return addinfourl(open(localfile, 'rb'), headers, origurl)
except OSError, msg:
# urllib2 users shouldn't expect OSErrors coming from urlopen()
raise URLError(msg)