Created
January 4, 2011 10:10
-
-
Save t0ster/764608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ResultAttr: | |
attr_names = set(( | |
'_ResultAttr__value', '_ResultAttr__result', 'name')) | |
def __init__(self, name, value, result): | |
""" | |
Proxy class for `Result` attributes | |
Arguments: | |
- `name`: attribute name, for example 'user' | |
- `value`: actual value | |
- `result`: `Result` instance | |
""" | |
self.__name = name | |
self.__value = value | |
self.__result = result | |
def __getattr__(self, name): | |
if hasattr(self.__value, name): | |
return getattr(self.__value, name) | |
else: | |
return getattr( | |
self.__result, | |
'%s%s%s' % (self.__name, DOTATTR_SEPARATOR, name)) | |
def __call__(self): | |
return self | |
def __cmp__(self, other): | |
return cmp(self.__value, self.__value.__class__(other)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment