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

Method get_code

opcua/common/structures.py:92–125  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

90 __repr__ = __str__
91
92 def get_code(self):
93 code = """
94
95class {0}(object):
96
97 '''
98 {0} structure autogenerated from xml
99 '''
100
101""".format(self.name)
102
103 code += " ua_types = [\n"
104 for field in self.fields:
105 prefix = "ListOf" if field.array else ""
106 uatype = prefix + field.uatype
107 if uatype == "ListOfChar":
108 uatype = "String"
109 code += " ('{}', '{}'),\n".format(field.name, uatype)
110
111 code += " ]"
112 code += """
113 def __str__(self):
114 vals = [name + ": " + str(val) for name, val in self.__dict__.items()]
115 return self.__class__.__name__ + "(" + ", ".join(vals) + ")"
116
117 __repr__ = __str__
118
119 def __init__(self):
120"""
121 if not self.fields:
122 code += " pass"
123 for field in self.fields:
124 code += " self.{} = {}\n".format(field.name, field.value)
125 return code
126
127
128class Field(object):

Callers 2

save_to_fileMethod · 0.45
_generate_python_classFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected