Ticket #7770: cookie-datetime.diff
File cookie-datetime.diff, 1.2 KB (added by , 16 years ago) |
---|
-
django/http/__init__.py
1 1 import os 2 2 from Cookie import SimpleCookie, CookieError 3 from datetime import datetime, timedelta 3 4 from pprint import pformat 4 5 from urllib import urlencode 5 6 from urlparse import urljoin … … 322 323 323 324 def set_cookie(self, key, value='', max_age=None, expires=None, path='/', 324 325 domain=None, secure=False): 326 """Sets a cookie. expires can be a datetime object, a timedelta 327 object from the current time, or a string in the correct format.""" 325 328 self.cookies[key] = value 326 329 if max_age is not None: 327 330 self.cookies[key]['max-age'] = max_age 328 331 if expires is not None: 332 if isinstance(expires, datetime): 333 expires = expires.strftime("%a, %d-%b-%Y %H:%M:%S UTC") 334 elif isinstance(expires, timedelta): 335 expires = datetime.strftime(datetime.utcnow() + expires, "%a, %d-%b-%Y %H:%M:%S UTC") 329 336 self.cookies[key]['expires'] = expires 330 337 if path is not None: 331 338 self.cookies[key]['path'] = path