diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-03-18 20:58:22 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-03-18 20:58:22 +0000 |
| commit | c8e2f7591d6ea3545aeb32fa4c92cbeb9a622546 (patch) | |
| tree | 85567aca5535ddfaaed1f1dcc11218288cb446ff /django/http | |
| parent | c7cc4cfb9ebef17930db4a92cd0632a536a4ff7a (diff) | |
Fixed #17931 -- Accepted aware datetimes to set cookies expiry dates. Thanks jaddison for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17766 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/__init__.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py index 0c746fe74f..94478ae5ae 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -121,6 +121,7 @@ from django.http.utils import * from django.utils.datastructures import MultiValueDict, ImmutableList from django.utils.encoding import smart_str, iri_to_uri, force_unicode from django.utils.http import cookie_date +from django.utils import timezone RESERVED_CHARS="!*'();:@&=+$,/?%#[]" @@ -641,13 +642,18 @@ class HttpResponse(object): """ Sets a cookie. - ``expires`` can be a string in the correct format or a - ``datetime.datetime`` object in UTC. If ``expires`` is a datetime - object then ``max_age`` will be calculated. + ``expires`` can be: + - a string in the correct format, + - a naive ``datetime.datetime`` object in UTC, + - an aware ``datetime.datetime`` object in any time zone. + If it is a ``datetime.datetime`` object then ``max_age`` will be calculated. + """ self.cookies[key] = value if expires is not None: if isinstance(expires, datetime.datetime): + if timezone.is_aware(expires): + expires = timezone.make_naive(expires, timezone.utc) delta = expires - expires.utcnow() # Add one second so the date matches exactly (a fraction of # time gets lost between converting to a timedelta and |
