Class LazyProxy
object --+
|
LazyProxy
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!
|
__init__(self,
func,
*args,
**kwargs)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__call__(self,
*args,
**kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__delattr__(self,
name)
x.__delattr__('name') <==> del x.name |
|
|
|
|
|
__setattr__(self,
name,
value)
x.__setattr__('name', value) <==> x.name = value |
|
|
|
|
|
|
|
__setitem__(self,
key,
value) |
|
|
Inherited from object :
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__
|
|
value
|
Inherited from object :
__class__
|
__init__(self,
func,
*args,
**kwargs)
(Constructor)
|
|
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
- Overrides:
object.__init__
- (inherited documentation)
|
__str__(self)
(Informal representation operator)
|
|
str(x)
- Overrides:
object.__str__
- (inherited documentation)
|
x.__delattr__('name') <==> del x.name
- Overrides:
object.__delattr__
- (inherited documentation)
|
__setattr__(self,
name,
value)
|
|
x.__setattr__('name', value) <==> x.name = value
- Overrides:
object.__setattr__
- (inherited documentation)
|
value
- Get Method:
- unreachable.value(self)
- Set Method:
{ ' territory_zones ' : { ' 001 ' : [ ' Etc/GMT ' ,
' Etc/GMT-1 ' ,
' Etc/GMT-2 ' ,
' Etc/GMT-3 ' ,
' Etc/GMT-4 ' ,
' Etc/GMT-5 ' ,
' Etc/GMT-6 ' ,
' Etc/GMT-7 ' ,
...
|
- Delete Method:
{ ' territory_zones ' : { ' 001 ' : [ ' Etc/GMT ' ,
' Etc/GMT-1 ' ,
' Etc/GMT-2 ' ,
' Etc/GMT-3 ' ,
' Etc/GMT-4 ' ,
' Etc/GMT-5 ' ,
' Etc/GMT-6 ' ,
' Etc/GMT-7 ' ,
...
|
|