Author: mtredinnick
Date: 2007-10-21 13:35:31 -0500 (Sun, 21 Oct 2007)
New Revision: 6587
Modified:
django/trunk/django/utils/functional.py
Log:
Fixed #5560 -- Improved the way we create __str__ and __unicode__ methods in
lazy() objects. This fixes things for Jython and makes the code more readable,
even for CPython. Thanks, Leo Soto.
Modified: django/trunk/django/utils/functional.py
===================================================================
--- django/trunk/django/utils/functional.py 2007-10-21 18:26:24 UTC (rev
6586)
+++ django/trunk/django/utils/functional.py 2007-10-21 18:35:31 UTC (rev
6587)
@@ -53,7 +53,11 @@
self._delegate_unicode = unicode in resultclasses
assert not (self._delegate_str and self._delegate_unicode),
"Cannot call lazy() with both str and unicode return types."
if self._delegate_unicode:
- self.__unicode__ = self.__unicode_cast
+ # Each call to lazy() makes a new __proxy__ object, so this
+ # doesn't interfere with any other lazy() results.
+ __proxy__.__unicode__ = __proxy__.__unicode_cast
+ elif self._delegate_str:
+ __proxy__.__str__ = __proxy__.__str_cast
def __promise__(self, klass, funcname, func):
# Builds a wrapper around some magic method and registers that
magic
@@ -72,14 +76,8 @@
def __unicode_cast(self):
return self.__func(*self.__args, **self.__kw)
- def __str__(self):
- # As __str__ is always a method on the type (class), it is looked
- # up (and found) there first. So we can't just assign to it on a
- # per-instance basis in __init__.
- if self._delegate_str:
- return str(self.__func(*self.__args, **self.__kw))
- else:
- return Promise.__str__(self)
+ def __str_cast(self):
+ return str(self.__func(*self.__args, **self.__kw))
def __cmp__(self, rhs):
if self._delegate_str:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---