From 162fade2b70d56ee5cbc3a57d1863f3c989775d6 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Tue, 20 Oct 2009 14:11:08 +0000 Subject: 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 --- django/utils/functional.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'django/utils') 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() -- cgit v1.3