Skip to content

Instantly share code, notes, and snippets.

@t0ster
Created January 4, 2011 10:10
Show Gist options
  • Save t0ster/764608 to your computer and use it in GitHub Desktop.
Save t0ster/764608 to your computer and use it in GitHub Desktop.
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