1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Provides decorator collator classes.
18 """
19
20 import inspect
21
22
24 """
25 Docorated method/function collator.
26 """
27
29 """
30 Collate decorated functions/methods.
31 Returns (Classes, Unbound) where:
32 - Classes is: dict {class:[methods,..]}
33 - Unbound is: dict {module: [functions,...]}
34 @param functions: A collection of decorated functions.
35 @type functions: (list|dict)
36 @return: A tuple (classes, unbound)
37 @rtype: tuple(2)
38 """
39 self.classes = {}
40 self.bound = set()
41 self.functions = functions
42 mapped = []
43 for fn in functions:
44 g = fn.func_globals
45 if g in mapped:
46 continue
47 self.__map(g)
48 mapped.append(g)
49 return (self.classes, self.__functions())
50
52 for cls in self.__classes(g):
53 for method in self.__methods(cls):
54 fn = self.__function(method)
55 decorated = self.__decorated(fn)
56 if not decorated:
57 continue
58 self.bound.add(fn)
59 methods = self.__find(cls)
60 methods.append((method, decorated[1]))
61
63 methods = self.classes.get(cls)
64 if methods is None:
65 methods = []
66 self.classes[cls] = methods
67 return methods
68
70 classes = []
71 for x in g.values():
72 if inspect.isclass(x):
73 classes.append(x)
74 return classes
75
77 return [v for n,v in \
78 inspect.getmembers(cls, inspect.ismethod)]
79
81 for n,v in inspect.getmembers(method, inspect.isfunction):
82 return v
83
96
103