Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
happi_client = None
# Load and add each device
devices = list()
klass_regex = re.compile(
r'([a-zA-Z][a-zA-Z\.\_]*)\[(\{.+})*[\,]*\]' # noqa
)
for device_name in device_names:
logger.info("Loading %r ...", device_name)
result = klass_regex.findall(device_name)
if len(result) > 0:
try:
klass, args = result[0]
klass = pcdsutils.utils.import_helper(klass)
default_kwargs = {"name": "device"}
if args:
kwargs = ast.literal_eval(args)
default_kwargs.update(kwargs)
if fake_devices:
klass = make_fake_device(klass)
# Give default value to missing positional args
# This might fail, but is best effort
for arg in inspect.getfullargspec(klass).args:
if arg not in default_kwargs and arg != 'self':
default_kwargs[arg] = 'FAKE'
device = klass(**default_kwargs)
devices.append(device)