[Python-checkins] r80957 - python/trunk/Lib/urllib2.py
senthil.kumaran
python-checkins at python.org
Sat May 8 07:00:11 CEST 2010
Author: senthil.kumaran
Date: Sat May 8 07:00:11 2010
New Revision: 80957
Log:
Fixing the errors trigerred in test_urllib2net. Related to issue8656.
Modified:
python/trunk/Lib/urllib2.py
Modified: python/trunk/Lib/urllib2.py
==============================================================================
--- python/trunk/Lib/urllib2.py (original)
+++ python/trunk/Lib/urllib2.py Sat May 8 07:00:11 2010
@@ -1276,13 +1276,13 @@
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 @@
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)
More information about the Python-checkins
mailing list