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