[Python-checkins] python/dist/src/Lib/email Utils.py,1.27,1.28

anthonybaxter at users.sourceforge.net anthonybaxter at users.sourceforge.net
Mon Oct 11 15:53:10 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26235/Lib/email
Modified Files:
	Utils.py 
Log Message:
Added a usegmt flag to email.Utils.formatdate - this allows it to be 
used to replace rfc822.formatdate for protocols like HTTP (where 'GMT' must
be the timezone string).
Index: Utils.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Utils.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- Utils.py	3 Oct 2004 03:16:18 -0000	1.27
+++ Utils.py	11 Oct 2004 13:53:07 -0000	1.28
@@ -103,7 +103,7 @@
 
 
 
-def formatdate(timeval=None, localtime=False):
+def formatdate(timeval=None, localtime=False, usegmt=False):
 """Returns a date string as specified by RFC 2822, e.g.:
 
 2001年11月09日 01:08:47 -0000
@@ -114,6 +114,10 @@
 Optional localtime is a flag that when True, interprets timeval, and
 returns a date relative to the local timezone instead of UTC, properly
 taking daylight savings time into account.
+
+ Optional argument usegmt means that the timezone is written out as 
+ an ascii string, not numeric one (so "GMT" instead of "+0000"). This
+ is needed for HTTP, and is only used when localtime==False.
 """
 # Note: we cannot use strftime() because that honors the locale and RFC
 # 2822 requires that day and month names be the English abbreviations.
@@ -138,7 +142,10 @@
 else:
 now = time.gmtime(timeval)
 # Timezone offset is always -0000
- zone = '-0000'
+ if usegmt:
+ zone = 'GMT'
+ else:
+ zone = '-0000'
 return '%s, %02d %s %04d %02d:%02d:%02d %s' % (
 ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][now[6]],
 now[2],


More information about the Python-checkins mailing list

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