Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
--------
Optional[Scope]
The relevant :class:`Scope` or None
"""
stack = inspect.stack()
try:
for frame_info in stack[skip_frames + 1:]:
frame = None
try:
frame = frame_info.frame
if name in frame.f_locals or (global_ok and name in frame.f_globals):
return Scope(globals_=frame.f_globals, locals_=frame.f_locals)
finally:
del frame
finally:
del stack
return None
def __init__(self, code: str, scope: Scope = None, arg_dict: dict = None, loop: asyncio.BaseEventLoop = None):
self.args = [self]
self.arg_names = ['_async_executor']
if arg_dict:
for key, value in arg_dict.items():
self.arg_names.append(key)
self.args.append(value)
self.code = wrap_code(code, args=', '.join(self.arg_names))
self.scope = scope or Scope()
self.loop = loop or asyncio.get_event_loop()