diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2009-10-20 14:14:27 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2009-10-20 14:14:27 +0000 |
| commit | aaa9ccfe141f772baa8e08a7815f975e1ab29326 (patch) | |
| tree | 0abce37a5e5c6a1ba0b37398f10154dd3eb6686f /django/utils | |
| parent | c1b3808ec0387b831eb255ce0759b47b19c67542 (diff) | |
[1.1.X] Fixed #12060 - equality tests between User and SimpleLazyObject-wrapped User failed.
Also added more tests for SimpleLazyObject
Thanks to ericholscher for report.
Backport of r11637 from trunk
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11638 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/functional.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py index 52969cd43a..65a9b9d7aa 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -312,14 +312,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() |
