summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2009-10-20 14:11:08 +0000
committerLuke Plant <L.Plant.98@cantab.net>2009-10-20 14:11:08 +0000
commit162fade2b70d56ee5cbc3a57d1863f3c989775d6 (patch)
treefef65789850e45a80f504ef005e721a8d74ee6d5 /django
parentc6e8e5d9f068210d25f501b2aae4192d1c01185c (diff)
Fixed #12060 - equality tests between User and SimpleLazyObject-wrapped User failed.
Also added more tests for SimpleLazyObject Thanks to ericholscher for report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11637 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/utils/functional.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index e12ef3b813..434b6b76c9 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -316,14 +316,35 @@ class SimpleLazyObject(LazyObject):
if self._wrapped is None: self._setup()
return str(self._wrapped)
+ def __unicode__(self):
+ if self._wrapped is None: self._setup()
+ return unicode(self._wrapped)
+
def __deepcopy__(self, memo):
if self._wrapped is None:
- result = self.__class__(self._setupfunc)
+ # We have to use SimpleLazyObject, not self.__class__, because the
+ # latter is proxied.
+ result = SimpleLazyObject(self._setupfunc)
memo[id(self)] = result
return result
else:
import copy
return copy.deepcopy(self._wrapped, memo)
+ # Need to pretend to be the wrapped class, for the sake of objects that care
+ # about this (especially in equality tests)
+ def __get_class(self):
+ if self._wrapped is None: self._setup()
+ return self._wrapped.__class__
+ __class__ = property(__get_class)
+
+ def __eq__(self, other):
+ if self._wrapped is None: self._setup()
+ return self._wrapped == other
+
+ def __hash__(self):
+ if self._wrapped is None: self._setup()
+ return hash(self._wrapped)
+
def _setup(self):
self._wrapped = self._setupfunc()