diff options
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/cache.py | 22 | ||||
| -rw-r--r-- | django/utils/datastructures.py | 5 | ||||
| -rw-r--r-- | django/utils/tzinfo.py | 8 |
3 files changed, 33 insertions, 2 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index 5654bed7aa..4fcf493944 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -74,6 +74,21 @@ def patch_cache_control(response, **kwargs): cc = ', '.join([dictvalue(el) for el in cc.items()]) response['Cache-Control'] = cc +def get_max_age(response): + """ + Returns the max-age from the response Cache-Control header as an integer + (or ``None`` if it wasn't found or wasn't an integer. + """ + if not response.has_header('Cache-Control'): + return + cc = dict([_to_tuple(el) for el in + cc_delim_re.split(response['Cache-Control'])]) + if 'max-age' in cc: + try: + return int(cc['max-age']) + except (ValueError, TypeError): + pass + def patch_response_headers(response, cache_timeout=None): """ Adds some useful headers to the given HttpResponse object: @@ -180,3 +195,10 @@ def learn_cache_key(request, response, cache_timeout=None, key_prefix=None): # for the request.path cache.set(cache_key, [], cache_timeout) return _generate_cache_key(request, [], key_prefix) + + +def _to_tuple(s): + t = s.split('=',1) + if len(t) == 2: + return t[0].lower(), t[1] + return t[0].lower(), True diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index ffdc73f922..ee156b11d0 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -60,7 +60,10 @@ class SortedDict(dict): if isinstance(data, dict): self.keyOrder = data.keys() else: - self.keyOrder = [key for key, value in data] + self.keyOrder = [] + for key, value in data: + if key not in self.keyOrder: + self.keyOrder.append(key) def __deepcopy__(self, memo): from copy import deepcopy diff --git a/django/utils/tzinfo.py b/django/utils/tzinfo.py index e2e1d10fc1..7d5ead9290 100644 --- a/django/utils/tzinfo.py +++ b/django/utils/tzinfo.py @@ -54,6 +54,12 @@ class LocalTimezone(tzinfo): def _isdst(self, dt): tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1) - stamp = time.mktime(tt) + try: + stamp = time.mktime(tt) + except OverflowError: + # 32 bit systems can't handle dates after Jan 2038, so we fake it + # in that case (since we only care about the DST flag here). + tt = (2037,) + tt[1:] + stamp = time.mktime(tt) tt = time.localtime(stamp) return tt.tm_isdst > 0 |
