summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-08-19 18:30:48 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-08-19 18:30:48 +0100
commitb6a957f0ba8a2ed1b24d7ee042a9c4beaf51ab03 (patch)
tree87d42b9e8d3d4c1516b53eee1d9332735762826a /django/utils
parent52edc16086e3c28a78c31975bb4da2f9450590b4 (diff)
parent3c0300405009b82b52fd15483371097221662fcd (diff)
Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts: docs/ref/django-admin.txt
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/functional.py15
-rw-r--r--django/utils/http.py10
2 files changed, 10 insertions, 15 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index e23bd3ff80..9cc703fe84 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -263,17 +263,12 @@ class LazyObject(object):
__dir__ = new_method_proxy(dir)
# Dictionary methods support
- @new_method_proxy
- def __getitem__(self, key):
- return self[key]
+ __getitem__ = new_method_proxy(operator.getitem)
+ __setitem__ = new_method_proxy(operator.setitem)
+ __delitem__ = new_method_proxy(operator.delitem)
- @new_method_proxy
- def __setitem__(self, key, value):
- self[key] = value
-
- @new_method_proxy
- def __delitem__(self, key):
- del self[key]
+ __len__ = new_method_proxy(len)
+ __contains__ = new_method_proxy(operator.contains)
# Workaround for http://bugs.python.org/issue12370
diff --git a/django/utils/http.py b/django/utils/http.py
index 4647d89847..9b36ab91d7 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -109,8 +109,7 @@ def http_date(epoch_seconds=None):
Outputs a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
"""
- rfcdate = formatdate(epoch_seconds)
- return '%s GMT' % rfcdate[:25]
+ return formatdate(epoch_seconds, usegmt=True)
def parse_http_date(date):
"""
@@ -253,11 +252,12 @@ def same_origin(url1, url2):
def is_safe_url(url, host=None):
"""
Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
- a different host).
+ a different host and uses a safe scheme).
Always returns ``False`` on an empty url.
"""
if not url:
return False
- netloc = urllib_parse.urlparse(url)[1]
- return not netloc or netloc == host
+ url_info = urllib_parse.urlparse(url)
+ return (not url_info.netloc or url_info.netloc == host) and \
+ (not url_info.scheme or url_info.scheme in ['http', 'https'])