Call the callable with the arguments and keyword arguments provided but inject the active context or environment as first argument if the callable is a :func:`contextfunction` or :func:`environmentfunction`.
(__self, __obj, *args, **kwargs)
| 233 | |
| 234 | @internalcode |
| 235 | def call(__self, __obj, *args, **kwargs): |
| 236 | """Call the callable with the arguments and keyword arguments |
| 237 | provided but inject the active context or environment as first |
| 238 | argument if the callable is a :func:`contextfunction` or |
| 239 | :func:`environmentfunction`. |
| 240 | """ |
| 241 | if __debug__: |
| 242 | __traceback_hide__ = True # noqa |
| 243 | |
| 244 | # Allow callable classes to take a context |
| 245 | if hasattr(__obj, '__call__'): |
| 246 | fn = __obj.__call__ |
| 247 | for fn_type in ('contextfunction', |
| 248 | 'evalcontextfunction', |
| 249 | 'environmentfunction'): |
| 250 | if hasattr(fn, fn_type): |
| 251 | __obj = fn |
| 252 | break |
| 253 | |
| 254 | if isinstance(__obj, _context_function_types): |
| 255 | if getattr(__obj, 'contextfunction', 0): |
| 256 | args = (__self,) + args |
| 257 | elif getattr(__obj, 'evalcontextfunction', 0): |
| 258 | args = (__self.eval_ctx,) + args |
| 259 | elif getattr(__obj, 'environmentfunction', 0): |
| 260 | args = (__self.environment,) + args |
| 261 | try: |
| 262 | return __obj(*args, **kwargs) |
| 263 | except StopIteration: |
| 264 | return __self.environment.undefined('value was undefined because ' |
| 265 | 'a callable raised a ' |
| 266 | 'StopIteration exception') |
| 267 | |
| 268 | def derived(self, locals=None): |
| 269 | """Internal helper function to create a derived context. This is |
no outgoing calls
no test coverage detected