Decorate the nodes.
46def _decorate(nodes, opers):
47 """
48 Decorate the functions
49 """
50
51
52 if hasattr(opers, "__call__"):
53
54 def _call_(self, arg):
55 """
56 Evaluate the functor
57
58 >>> fun = ... # get the functor
59 >>> arg = ... # get the argument
60 >>> res = fun ( arg )
61 """
62 result = opers.__call__(self, arg)
63 return True if result else False
64
65 _call_.__doc__ = opers.__call__.__doc__
66
67
68 if hasattr(opers, "__or__"):
69
70 def _or_(self, arg):
71 """
72 LOGICAL or
73
74 >>> fun1 = ... # get the functor
75 >>> fun2 = ... # get the functor
76 >>> fun = fun1 | fun2
77 """
78 return opers.__or__(self, arg)
79
80 _or_.__doc__ = opers.__or__.__doc__
81
82
83 if hasattr(opers, "__ror__"):
84
85 def _ror_(self, arg):
86 """
87 LOGICAL or
88
89 >>> fun1 = ... # get the functor
90 >>> fun2 = ... # get the functor
91 >>> fun = fun1 | fun2
92 """
93 return opers.__ror__(self, arg)
94
95 _or_.__doc__ = opers.__or__.__doc__
96
97
98 if hasattr(opers, "__and__"):
99
100 def _and_(self, arg):
101 """
102 LOGICAL and
103
104 >>> fun1 = ... # get the functor
105 >>> fun2 = ... # get the functor
106 >>> fun = fun1 & fun2
107 """
108 return opers.__and__(self, arg)
109
110 _and_.__doc__ = opers.__and__.__doc__
111
112
113 if hasattr(opers, "__rand__"):
114
115 def _rand_(self, arg):
116 """
117 LOGICAL and
118
119 >>> fun1 = ... # get the functor
120 >>> fun2 = ... # get the functor
121 >>> fun = fun1 & fun2
122 """
123 return opers.__rand__(self, arg)
124
125 _rand_.__doc__ = opers.__rand__.__doc__
126
127
128 if hasattr(opers, "__invert__"):
129
130 def _invert_(self, *arg):
131 """
132 LOGICAL negation
133
134 >>> fun1 = ... # get the functor
135 >>> fun = ~fun2
136 """
137 return opers.__invert__(self, *arg)
138
139 _invert_.__doc__ = opers.__invert__.__doc__
140
141
142 if hasattr(opers, "__rshift__"):
143
144 def _rshift_(self, arg):
145 """
146 Streamers
147
148 >>> fun1 = ... # get the functor
149 >>> fun1 = ... # get the functor
150 >>> fun = fun1 >> fun2
151 """
152 return opers.__rshift__(self, arg)
153
154 _rshift_.__doc__ = opers.__rshift__.__doc__
155
156
157 if hasattr(opers, "__rrshift__"):
158
159 def _rrshift_(self, arg):
160 """
161 Evaluate the functor as streametr shift
162
163 >>> fun = ... # get the functor
164 >>> arg = ... # get the argument
165 >>> res = arg >> fun
166 """
167 result = opers.__rrshift__(self, arg)
168 return True if result else False
169
170 _rrshift_.__doc__ = opers.__rrshift__.__doc__
171
172 for node in nodes:
173 if _call_:
174 node.__call__ = _call_
175 if _or_:
176 node.__or__ = _or_
177 if _ror_:
178 node.__ror__ = _ror_
179 if _and_:
180 node.__and__ = _and_
181 if _rand_:
182 node.__rand__ = _rand_
183 if _rshift_:
184 node.__rshift__ = _rshift_
185 if _rrshift_:
186 node.__rrshift__ = _rrshift_
187 if _invert_:
188 node.__invert__ = _invert_
189
190 node.__repr__ = lambda s: s.toString()
191 node.__str__ = lambda s: s.toString()
192
193 return nodes
194
195