summaryrefslogtreecommitdiffstats
path: root/Lib/urllib2.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-08-27 20:16:53 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-08-27 20:16:53 (GMT)
commit6d8c1aabff765d4958132f750a968769e7cece13 (patch)
tree617d67c72baf597fea0176a99972bc309a7e195c /Lib/urllib2.py
parent53da3178011d5eaf143d6d9d76274a7530204179 (diff)
downloadcpython-6d8c1aabff765d4958132f750a968769e7cece13.zip
cpython-6d8c1aabff765d4958132f750a968769e7cece13.tar.gz
cpython-6d8c1aabff765d4958132f750a968769e7cece13.tar.bz2
Add content-type header to ftp URLs (SF patch #454553)
Modify rfc822.formatdate() to always generate English names, regardless of locale. This is required by RFC 1123. In open_local_file() of urllib and urllib2, use new formatdate() from rfc822.
Diffstat (limited to 'Lib/urllib2.py')
-rw-r--r--Lib/urllib2.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 5882de6..beb9fa5 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -96,9 +96,12 @@ import urlparse
import md5
import mimetypes
import mimetools
+import rfc822
import ftplib
import sys
import time
+import os
+import stat
import gopherlib
import posixpath
@@ -914,16 +917,22 @@ class FileHandler(BaseHandler):
# not entirely sure what the rules are here
def open_local_file(self, req):
- mtype = mimetypes.guess_type(req.get_selector())[0]
- headers = mimetools.Message(StringIO('Content-Type: %s\n' \
- % (mtype or 'text/plain')))
host = req.get_host()
file = req.get_selector()
+ localfile = url2pathname(file)
+ stats = os.stat(localfile)
+ size = stats[stat.ST_SIZE]
+ modified = rfc822.formatdate(stats[stat.ST_MTIME])
+ mtype = mimetypes.guess_type(file)[0]
+ stats = os.stat(localfile)
+ headers = mimetools.Message(StringIO(
+ 'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
+ (mtype or 'text/plain', size, modified)))
if host:
host, port = splitport(host)
if not host or \
(not port and socket.gethostbyname(host) in self.get_names()):
- return addinfourl(open(url2pathname(file), 'rb'),
+ return addinfourl(open(localfile, 'rb'),
headers, 'file:'+file)
raise URLError('file not on local host')