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

Class Struct

opcua/common/structures.py:82–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81
82class Struct(object):
83 def __init__(self, name):
84 self.name = _clean_name(name)
85 self.fields = []
86 self.typeid = None
87
88 def __str__(self):
89 return "Struct(name={}, fields={}".format(self.name, self.fields)
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 1

_make_modelMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected