MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / _generate_python_class

Function _generate_python_class

opcua/common/structures.py:308–330  ·  view source on GitHub ↗

generate Python code and execute in a new environment return a dict of structures {name: class} Rmw: Since the code is generated on the fly, in case of error the stack trace is not available and debugging is very hard...

(model, env=None)

Source from the content-addressed store, hash-verified

306
307
308def _generate_python_class(model, env=None):
309 """
310 generate Python code and execute in a new environment
311 return a dict of structures {name: class}
312 Rmw: Since the code is generated on the fly, in case of error the stack trace is
313 not available and debugging is very hard...
314 """
315 if env is None:
316 env = {}
317 # Add the required libraries to dict
318 if "ua" not in env:
319 env['ua'] = ua
320 if "datetime" not in env:
321 env['datetime'] = datetime
322 if "uuid" not in env:
323 env['uuid'] = uuid
324 if "enum" not in env:
325 env['IntEnum'] = IntEnum
326 # generate classes one by one and add them to dict
327 for element in model:
328 code = element.get_code()
329 exec(code, env)
330 return env
331
332
333def load_enums(server, env=None):

Callers 2

get_python_classesMethod · 0.85
load_enumsFunction · 0.85

Calls 1

get_codeMethod · 0.45

Tested by

no test coverage detected