agdj/utils.py
changeset 416 5a586a8c2f8f
parent 415 5e48e2725b18
child 451 88b49087ec1a
     1.1 --- a/agdj/utils.py	Sun Feb 01 01:10:45 2009 -0500
     1.2 +++ b/agdj/utils.py	Sun Feb 01 01:35:02 2009 -0500
     1.3 @@ -56,3 +56,17 @@
     1.4  
     1.5          return val
     1.6      return property(_closure)
     1.7 +
     1.8 +
     1.9 +def dictproperty(method):
    1.10 +    """Turn dictionary or attribute access into a function call"""
    1.11 +
    1.12 +    class _Object(object):
    1.13 +        def __init__(self, obj):
    1.14 +            self.obj = obj
    1.15 +        def __getattr__(self, attr):
    1.16 +            return method(self.obj, attr)
    1.17 +        __getitem__ = __getattr__
    1.18 +    _Object.__name__ = method.__name__
    1.19 +
    1.20 +    return property(_Object)