Django

Code

Changeset 5420

Show
Ignore:
Timestamp:
06/03/07 00:35:06 (1 year ago)
Author:
mtredinnick
Message:

unicode: Implemented string interpolation for lazy objects.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/utils/functional.py

    r5344 r5420  
    3333                for (k, v) in resultclass.__dict__.items(): 
    3434                    setattr(self, k, self.__promise__(resultclass, k, v)) 
    35             if unicode in resultclasses: 
     35            self._delegate_str = str in resultclasses 
     36            self._delegate_unicode = unicode in resultclasses 
     37            assert not (self._delegate_str and self._delegate_unicode), "Cannot call lazy() with both str and unicode return types." 
     38            if self._delegate_unicode: 
    3639                self.__unicode__ = self.__unicode_cast 
    37             self._delegate_str  = str in resultclasses 
    3840 
    3941        def __promise__(self, klass, funcname, func): 
     
    6365                return Promise.__str__(self) 
    6466 
     67        def __mod__(self, rhs): 
     68            if self._delegate_str: 
     69                return str(self) % rhs 
     70            elif self._delegate_unicode: 
     71                return unicode(self) % rhs 
     72            else: 
     73                raise AssertionError('__mod__ not supported for non-string types') 
     74 
    6575    def __wrapper__(*args, **kw): 
    6676        # Creates the proxy object, instead of the actual value. 
  • django/branches/unicode/django/utils/translation/__init__.py

    r5255 r5420  
    7171ungettext_lazy = lazy(ungettext, unicode) 
    7272ugettext_lazy = lazy(ugettext, unicode) 
    73 string_concat = lazy(string_concat, str, unicode) 
     73string_concat = lazy(string_concat, unicode) 
    7474 
    7575def activate(language):