class LazyProxy(object):
Class for proxy objects that delegate to a specified function to evaluate the actual object.
>>> def greeting(name='world'): ... return 'Hello, %s!' % name >>> lazy_greeting = LazyProxy(greeting, name='Joe') >>> print(lazy_greeting) Hello, Joe! >>> u' ' + lazy_greeting u' Hello, Joe!' >>> u'(%s)' % lazy_greeting u'(Hello, Joe!)'
This can be used, for example, to implement lazy translation functions that delay the actual translation until the string is actually used. The rationale for such behavior is that the locale of the user may not always be available. In web applications, you only know the locale when processing a request.
The proxy implementation attempts to be as complete as possible, so that the lazy objects should mostly work as expected, for example for sorting:
>>> greetings = [ ... LazyProxy(greeting, 'world'), ... LazyProxy(greeting, 'Joe'), ... LazyProxy(greeting, 'universe'), ... ] >>> greetings.sort() >>> for greeting in greetings: ... print(greeting) Hello, Joe! Hello, universe! Hello, world!
Method | __add__ |
Undocumented |
Method | __call__ |
Undocumented |
Method | __contains__ |
Undocumented |
Method | __copy__ |
Undocumented |
Method | __deepcopy__ |
Undocumented |
Method | __delattr__ |
Undocumented |
Method | __delitem__ |
Undocumented |
Method | __dir__ |
Undocumented |
Method | __eq__ |
Undocumented |
Method | __ge__ |
Undocumented |
Method | __getattr__ |
Undocumented |
Method | __getitem__ |
Undocumented |
Method | __gt__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __le__ |
Undocumented |
Method | __len__ |
Undocumented |
Method | __lt__ |
Undocumented |
Method | __mod__ |
Undocumented |
Method | __mul__ |
Undocumented |
Method | __ne__ |
Undocumented |
Method | __nonzero__ |
Undocumented |
Method | __radd__ |
Undocumented |
Method | __rmod__ |
Undocumented |
Method | __rmul__ |
Undocumented |
Method | __setattr__ |
Undocumented |
Method | __setitem__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | __unicode__ |
Undocumented |
Class Variable | __slots__ |
Undocumented |
Property | value |
Undocumented |