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.
  ........
................
This commit is contained in:
Senthil Kumaran 2010-05-08 05:14:29 +00:00
parent 51964772b7
commit 1e72bd3c08
1 changed files with 8 additions and 5 deletions

View File

@ -1202,13 +1202,13 @@ class FileHandler(BaseHandler):
import email.utils import email.utils
import mimetypes import mimetypes
host = req.host host = req.host
file = req.selector filename = req.selector
localfile = url2pathname(file) localfile = url2pathname(filename)
try: try:
stats = os.stat(localfile) stats = os.stat(localfile)
size = stats.st_size size = stats.st_size
modified = email.utils.formatdate(stats.st_mtime, usegmt=True) 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( headers = email.message_from_string(
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
(mtype or 'text/plain', size, modified)) (mtype or 'text/plain', size, modified))
@ -1216,8 +1216,11 @@ class FileHandler(BaseHandler):
host, port = splitport(host) host, port = splitport(host)
if not host or \ if not host or \
(not port and _safe_gethostbyname(host) in self.get_names()): (not port and _safe_gethostbyname(host) in self.get_names()):
return addinfourl(open(localfile, 'rb'), headers, 'file://'+ if host:
host + file) origurl = 'file://' + host + filename
else:
origurl = 'file://' + filename
return addinfourl(open(localfile, 'rb'), headers, origurl)
except OSError as msg: except OSError as msg:
# users shouldn't expect OSErrors coming from urlopen() # users shouldn't expect OSErrors coming from urlopen()
raise URLError(msg) raise URLError(msg)