1
2
3
4
5
6
7
8
9 """C++-like virtual properties"""
10
11 __docformat__ = 'restructuredtext'
12
13
15 """Provides "virtual" property: uses derived class's method
16 """
17
18 - def __init__(self, fget=None, fset=None, fdel=None, doc=''):
19 for attr in ('fget', 'fset'):
20 func = locals()[attr]
21 if callable(func):
22 setattr(self, attr, func.func_name)
23 setattr(self, '__doc__', doc)
24
25 - def __get__(self, obj=None, type=None):
26 if not obj:
27 return 'property'
28 if self.fget:
29 return getattr(obj, self.fget)()
30
32 if self.fset:
33 return getattr(obj, self.fset)(arg)
34