Merge pull request #702 from berkerpeksag/use-email-utils-formatdate

Use email.utils.formatdate in gunicorn.util.http_date.
This commit is contained in:
Randall Leeds 2014-02-14 14:43:14 -08:00
commit 2ee1c26ec8
2 changed files with 3 additions and 10 deletions

1
THANKS
View File

@ -71,3 +71,4 @@ keakon <keakon@gmail.com>
Xie Shi <xieshi@douban.com>
Steven Cummings <estebistec@gmail.com>
Malthe Borch <mborch@gmail.com>
Berker Peksag <berker.peksag@gmail.com>

View File

@ -4,6 +4,7 @@
# See the NOTICE for more information.
import email.utils
import fcntl
import io
import os
@ -34,11 +35,6 @@ CHUNK_SIZE = (16 * 1024)
MAX_BODY = 1024 * 132
weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
monthname = [None,
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# Server and Date aren't technically hop-by-hop
# headers, but they are in the purview of the
# origin server which the WSGI spec says we should
@ -400,11 +396,7 @@ def http_date(timestamp=None):
"""Return the current date and time formatted for a message header."""
if timestamp is None:
timestamp = time.time()
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
weekdayname[wd],
day, monthname[month], year,
hh, mm, ss)
s = email.utils.formatdate(timestamp, localtime=False, usegmt=True)
return s