Create a function from the strings name, signature and body. evaldict is the evaluation dictionary. If addsource is true an attribute __source__ is added to the result. The attributes attrs are added, if any.
(cls, obj, body, evaldict, defaults=None,
doc=None, module=None, addsource=True, **attrs)
| 205 | |
| 206 | @classmethod |
| 207 | def create(cls, obj, body, evaldict, defaults=None, |
| 208 | doc=None, module=None, addsource=True, **attrs): |
| 209 | """ |
| 210 | Create a function from the strings name, signature and body. |
| 211 | evaldict is the evaluation dictionary. If addsource is true an |
| 212 | attribute __source__ is added to the result. The attributes attrs |
| 213 | are added, if any. |
| 214 | """ |
| 215 | if isinstance(obj, str): # "name(signature)" |
| 216 | name, rest = obj.strip().split('(', 1) |
| 217 | signature = rest[:-1] # strip a right parens |
| 218 | func = None |
| 219 | else: # a function |
| 220 | name = None |
| 221 | signature = None |
| 222 | func = obj |
| 223 | self = cls(func, name, signature, defaults, doc, module) |
| 224 | ibody = '\n'.join(' ' + line for line in body.splitlines()) |
| 225 | return self.make('def %(name)s(%(signature)s):\n' + ibody, |
| 226 | evaldict, addsource, **attrs) |
| 227 | |
| 228 | |
| 229 | def decorate(func, caller): |