Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def instantiate_component(self, module, cname, id, args, kwargs, active_components):
# Maybe we still have the instance?
c = self.instances.get(id, None)
if c is not None and c._disposed is False:
return c
# Find the class
m = window.flexx.require(module)
Cls = m[cname] # noqa
# Instantiate. If given, replicate the active components by which the
# JsComponent was instantiated in Python.
kwargs['flx_session'] = self
kwargs['flx_id'] = id
active_components = active_components or []
for ac in active_components:
ac.__enter__()
try:
c = Cls(*args, **kwargs)
finally:
for ac in reversed(active_components):
ac.__exit__()
return c