1
2
3
4
5
6
7
8
9
10 from elisa.core.utils import misc
11
23
25 """
26 Given a class and a new set of attributes (as passed in by
27 __classinit__), create or modify properties based on functions
28 with special names ending in __get, __set, and __del.
29 """
30 for name, value in new_attrs.items():
31 if (name.endswith('__get') or name.endswith('__set')
32 or name.endswith('__del')):
33 base = name[:-5]
34 if hasattr(cls, base):
35 old_prop = getattr(cls, base)
36 if isinstance(old_prop, property):
37 attrs = {'fget': old_prop.fget,
38 'fset': old_prop.fset,
39 'fdel': old_prop.fdel,
40 'doc': old_prop.__doc__}
41 else:
42 attrs = {}
43 else:
44 attrs = {}
45 attrs['f' + name[-3:]] = value
46 if name.endswith('__get') and value.__doc__:
47 attrs['doc'] = value.__doc__
48 new_prop = property(**attrs)
49 setattr(cls, base, new_prop)
50
51 name = new_attrs.get('name')
52 if not name:
53 name = cls.__name__
54 cls.name = misc.un_camelify(name)
55