diff options
| author | Gary Wilson Jr <gary.wilson@gmail.com> | 2007-10-31 03:59:40 +0000 |
|---|---|---|
| committer | Gary Wilson Jr <gary.wilson@gmail.com> | 2007-10-31 03:59:40 +0000 |
| commit | 8c442f21dc7079a880eb626d20b84fc090563dff (patch) | |
| tree | b52a636fb83fd24349bfc3619fdd56f97ebbc280 /django/utils/http.py | |
| parent | 39f28512b9d2776c5bd716a334999e28fd2ac731 (diff) | |
Fixed #5816 -- Fixed a regression from [6333] that generates incorrect cookie "expires" dates when using a locale other than English. Introduced `http_date` and `cookie_date` utility functions. Thanks for the report Michael Lemaire. Thanks for the patch Karen Tracey and `SmileyChris`.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6634 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/http.py')
| -rw-r--r-- | django/utils/http.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index 4912c9c46a..5ec6e92d28 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -1,4 +1,6 @@ import urllib +from email.Utils import formatdate + from django.utils.encoding import smart_str, force_unicode from django.utils.functional import allow_lazy @@ -37,3 +39,29 @@ def urlencode(query, doseq=0): for k, v in query], doseq) +def cookie_date(epoch_seconds=None): + """ + Formats the time to ensure compatibility with Netscape's cookie standard. + + Accepts a floating point number expressed in seconds since the epoch, in + UTC - such as that outputted by time.time(). If set to None, defaults to + the current time. + + Outputs a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'. + """ + rfcdate = formatdate(epoch_seconds) + return '%s-%s-%s GMT' % (rfcdate[:7], rfcdate[8:11], rfcdate[12:25]) + +def http_date(epoch_seconds=None): + """ + Formats the time to match the RFC1123 date format as specified by HTTP + RFC2616 section 3.3.1. + + Accepts a floating point number expressed in seconds since the epoch, in + UTC - such as that outputted by time.time(). If set to None, defaults to + the current time. + + Outputs a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'. + """ + rfcdate = formatdate(epoch_seconds) + return '%s GMT' % rfcdate[:25] |
