diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-05-08 05:14:29 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-05-08 05:14:29 (GMT) |
commit | 1e72bd3c08dd0fca728478691d17f157a07b27f0 (patch) | |
tree | 49e798f66458bd44ce3bc3d850809c2f961eb663 /Lib | |
parent | 51964772b7dd412feb7a92dd88887f4cbc6a1b49 (diff) | |
download | cpython-1e72bd3c08dd0fca728478691d17f157a07b27f0.zip cpython-1e72bd3c08dd0fca728478691d17f157a07b27f0.tar.gz cpython-1e72bd3c08dd0fca728478691d17f157a07b27f0.tar.bz2 |
Merged revisions 80959 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r80959 | senthil.kumaran | 2010-05-08 10:42:05 +0530 (Sat, 08 May 2010) | 9 lines
Merged revisions 80957 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80957 | senthil.kumaran | 2010-05-08 10:30:11 +0530 (Sat, 08 May 2010) | 2 lines
Fixing the errors trigerred in test_urllib2net. Related to issue8656.
........
................
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/urllib/request.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 6e892e4..6a2ce91 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1202,13 +1202,13 @@ class FileHandler(BaseHandler): import email.utils import mimetypes host = req.host - file = req.selector - localfile = url2pathname(file) + filename = req.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 = email.message_from_string( 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % (mtype or 'text/plain', size, modified)) @@ -1216,8 +1216,11 @@ class FileHandler(BaseHandler): host, port = splitport(host) if not host or \ (not port and _safe_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 as msg: # users shouldn't expect OSErrors coming from urlopen() raise URLError(msg) |