[Python-checkins] CVS: python/dist/src/Lib rfc822.py,1.60,1.61 urllib.py,1.132,1.133 urllib2.py,1.20,1.21

Jeremy Hylton jhylton@users.sourceforge.net
2001年8月27日 13:16:55 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv3216
Modified Files:
	rfc822.py urllib.py urllib2.py 
Log Message:
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.
Index: rfc822.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/rfc822.py,v
retrieving revision 1.60
retrieving revision 1.61
diff -C2 -d -r1.60 -r1.61
*** rfc822.py	2001年08月13日 14:43:15	1.60
--- rfc822.py	2001年08月27日 20:16:53	1.61
***************
*** 954,962 ****
 
 1994年11月06日 08:49:37 GMT ; RFC 822, updated by RFC 1123
 """
 if timeval is None:
 timeval = time.time()
! return "%s" % time.strftime('%a, %d %b %Y %H:%M:%S GMT',
! time.gmtime(timeval))
 
 
--- 954,972 ----
 
 1994年11月06日 08:49:37 GMT ; RFC 822, updated by RFC 1123
+ 
+ According to RFC 1123, day and month names must always be in
+ English. If not for that, this code could use strftime(). It
+ can't because strftime() honors the locale and could generated
+ non-English names.
 """
 if timeval is None:
 timeval = time.time()
! timeval = time.gmtime(timeval)
! return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (
! ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][timeval[6]],
! timeval[2],
! ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
! "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][timeval[1]-1],
! 				timeval[0], timeval[3], timeval[4], timeval[5])
 
 
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.132
retrieving revision 1.133
diff -C2 -d -r1.132 -r1.133
*** urllib.py	2001年08月23日 13:37:50	1.132
--- urllib.py	2001年08月27日 20:16:53	1.133
***************
*** 407,422 ****
 def open_local_file(self, url):
 """Use local file."""
! import mimetypes, mimetools, StringIO
 host, file = splithost(url)
 localname = url2pathname(file)
 stats = os.stat(localname)
 size = stats[stat.ST_SIZE]
! modified = time.gmtime(stats[stat.ST_MTIME])
! modified = "%s, %02d %s %04d %02d:%02d:%02d GMT" % (
! ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][modified[6]],
! modified[2],
! ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
! "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][modified[1]-1],
! modified[0], modified[3], modified[4], modified[5])
 mtype = mimetypes.guess_type(url)[0]
 headers = mimetools.Message(StringIO.StringIO(
--- 407,416 ----
 def open_local_file(self, url):
 """Use local file."""
! import mimetypes, mimetools, rfc822, StringIO
 host, file = splithost(url)
 localname = url2pathname(file)
 stats = os.stat(localname)
 size = stats[stat.ST_SIZE]
! modified = rfc822.formatdate(stats[stat.ST_MTIME])
 mtype = mimetypes.guess_type(url)[0]
 headers = mimetools.Message(StringIO.StringIO(
Index: urllib2.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib2.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** urllib2.py	2001年08月24日 13:10:13	1.20
--- urllib2.py	2001年08月27日 20:16:53	1.21
***************
*** 97,103 ****
--- 97,106 ----
 import mimetypes
 import mimetools
+ import rfc822
 import ftplib
 import sys
 import time
+ import os
+ import stat
 import gopherlib
 import posixpath
***************
*** 915,928 ****
 # 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()
 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'),
 headers, 'file:'+file)
 raise URLError('file not on local host')
--- 918,937 ----
 # not entirely sure what the rules are here
 def open_local_file(self, req):
 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(localfile, 'rb'),
 headers, 'file:'+file)
 raise URLError('file not on local host')

AltStyle によって変換されたページ (->オリジナル) /