Code Duplication    Length = 58-62 lines in 4 locations

opcua/ua/uaprotocol_auto.py 4 locations

@@ 1130-1191 (lines=62) @@
1127
    __repr__ = __str__
1128
1129
1130
class Argument(FrozenClass):
1131
    '''
1132
    An argument for a method.
1133
1134
    :ivar Name:
1135
    :vartype Name: String
1136
    :ivar DataType:
1137
    :vartype DataType: NodeId
1138
    :ivar ValueRank:
1139
    :vartype ValueRank: Int32
1140
    :ivar ArrayDimensions:
1141
    :vartype ArrayDimensions: UInt32
1142
    :ivar Description:
1143
    :vartype Description: LocalizedText
1144
    '''
1145
1146
    ua_types = [
1147
1148
        ('Name', 'String'),
1149
        ('DataType', 'NodeId'),
1150
        ('ValueRank', 'Int32'),
1151
        ('ArrayDimensions', 'ListOfUInt32'),
1152
        ('Description', 'LocalizedText'),
1153
               ]
1154
1155
    def __init__(self):
1156
        self.Name = None
1157
        self.DataType = NodeId()
1158
        self.ValueRank = 0
1159
        self.ArrayDimensions = []
1160
        self.Description = LocalizedText()
1161
        self._freeze = True
1162
1163
    def to_binary(self):
1164
        packet = []
1165
        packet.append(uabin.Primitives.String.pack(self.Name))
1166
        packet.append(self.DataType.to_binary())
1167
        packet.append(uabin.Primitives.Int32.pack(self.ValueRank))
1168
        packet.append(uabin.Primitives.Int32.pack(len(self.ArrayDimensions)))
1169
        for fieldname in self.ArrayDimensions:
1170
            packet.append(uabin.Primitives.UInt32.pack(fieldname))
1171
        packet.append(self.Description.to_binary())
1172
        return b''.join(packet)
1173
1174
    @staticmethod
1175
    def from_binary(data):
1176
        obj = Argument()
1177
        self.Name = uabin.Primitives.String.unpack(data)
1178
        obj.DataType = NodeId.from_binary(data)
1179
        self.ValueRank = uabin.Primitives.Int32.unpack(data)
1180
        obj.ArrayDimensions = uabin.Primitives.UInt32.unpack_array(data)
1181
        obj.Description = LocalizedText.from_binary(data)
1182
        return obj
1183
1184
    def __str__(self):
1185
        return 'Argument(' + 'Name:' + str(self.Name) + ', ' + \
1186
               'DataType:' + str(self.DataType) + ', ' + \
1187
               'ValueRank:' + str(self.ValueRank) + ', ' + \
1188
               'ArrayDimensions:' + str(self.ArrayDimensions) + ', ' + \
1189
               'Description:' + str(self.Description) + ')'
1190
1191
    __repr__ = __str__
1192
1193
1194
class EnumValueType(FrozenClass):
@@ 15025-15084 (lines=60) @@
15022
    __repr__ = __str__
15023
15024
15025
class AxisInformation(FrozenClass):
15026
    '''
15027
    :ivar EngineeringUnits:
15028
    :vartype EngineeringUnits: EUInformation
15029
    :ivar EURange:
15030
    :vartype EURange: Range
15031
    :ivar Title:
15032
    :vartype Title: LocalizedText
15033
    :ivar AxisScaleType:
15034
    :vartype AxisScaleType: AxisScaleEnumeration
15035
    :ivar AxisSteps:
15036
    :vartype AxisSteps: Double
15037
    '''
15038
15039
    ua_types = [
15040
15041
        ('EngineeringUnits', 'EUInformation'),
15042
        ('EURange', 'Range'),
15043
        ('Title', 'LocalizedText'),
15044
        ('AxisScaleType', 'AxisScaleEnumeration'),
15045
        ('AxisSteps', 'ListOfDouble'),
15046
               ]
15047
15048
    def __init__(self):
15049
        self.EngineeringUnits = EUInformation()
15050
        self.EURange = Range()
15051
        self.Title = LocalizedText()
15052
        self.AxisScaleType = AxisScaleEnumeration(0)
15053
        self.AxisSteps = []
15054
        self._freeze = True
15055
15056
    def to_binary(self):
15057
        packet = []
15058
        packet.append(self.EngineeringUnits.to_binary())
15059
        packet.append(self.EURange.to_binary())
15060
        packet.append(self.Title.to_binary())
15061
        packet.append(uabin.Primitives.UInt32.pack(self.AxisScaleType.value))
15062
        packet.append(uabin.Primitives.Int32.pack(len(self.AxisSteps)))
15063
        for fieldname in self.AxisSteps:
15064
            packet.append(uabin.Primitives.Double.pack(fieldname))
15065
        return b''.join(packet)
15066
15067
    @staticmethod
15068
    def from_binary(data):
15069
        obj = AxisInformation()
15070
        obj.EngineeringUnits = EUInformation.from_binary(data)
15071
        obj.EURange = Range.from_binary(data)
15072
        obj.Title = LocalizedText.from_binary(data)
15073
        self.AxisScaleType = AxisScaleEnumeration(uabin.Primitives.UInt32.unpack(data))
15074
        obj.AxisSteps = uabin.Primitives.Double.unpack_array(data)
15075
        return obj
15076
15077
    def __str__(self):
15078
        return 'AxisInformation(' + 'EngineeringUnits:' + str(self.EngineeringUnits) + ', ' + \
15079
               'EURange:' + str(self.EURange) + ', ' + \
15080
               'Title:' + str(self.Title) + ', ' + \
15081
               'AxisScaleType:' + str(self.AxisScaleType) + ', ' + \
15082
               'AxisSteps:' + str(self.AxisSteps) + ')'
15083
15084
    __repr__ = __str__
15085
15086
15087
class XVType(FrozenClass):
@@ 4151-4210 (lines=60) @@
4148
    __repr__ = __str__
4149
4150
4151
class NodeAttributes(FrozenClass):
4152
    '''
4153
    The base attributes for all nodes.
4154
4155
    :ivar SpecifiedAttributes:
4156
    :vartype SpecifiedAttributes: UInt32
4157
    :ivar DisplayName:
4158
    :vartype DisplayName: LocalizedText
4159
    :ivar Description:
4160
    :vartype Description: LocalizedText
4161
    :ivar WriteMask:
4162
    :vartype WriteMask: UInt32
4163
    :ivar UserWriteMask:
4164
    :vartype UserWriteMask: UInt32
4165
    '''
4166
4167
    ua_types = [
4168
4169
        ('SpecifiedAttributes', 'UInt32'),
4170
        ('DisplayName', 'LocalizedText'),
4171
        ('Description', 'LocalizedText'),
4172
        ('WriteMask', 'UInt32'),
4173
        ('UserWriteMask', 'UInt32'),
4174
               ]
4175
4176
    def __init__(self):
4177
        self.SpecifiedAttributes = 0
4178
        self.DisplayName = LocalizedText()
4179
        self.Description = LocalizedText()
4180
        self.WriteMask = 0
4181
        self.UserWriteMask = 0
4182
        self._freeze = True
4183
4184
    def to_binary(self):
4185
        packet = []
4186
        packet.append(uabin.Primitives.UInt32.pack(self.SpecifiedAttributes))
4187
        packet.append(self.DisplayName.to_binary())
4188
        packet.append(self.Description.to_binary())
4189
        packet.append(uabin.Primitives.UInt32.pack(self.WriteMask))
4190
        packet.append(uabin.Primitives.UInt32.pack(self.UserWriteMask))
4191
        return b''.join(packet)
4192
4193
    @staticmethod
4194
    def from_binary(data):
4195
        obj = NodeAttributes()
4196
        self.SpecifiedAttributes = uabin.Primitives.UInt32.unpack(data)
4197
        obj.DisplayName = LocalizedText.from_binary(data)
4198
        obj.Description = LocalizedText.from_binary(data)
4199
        self.WriteMask = uabin.Primitives.UInt32.unpack(data)
4200
        self.UserWriteMask = uabin.Primitives.UInt32.unpack(data)
4201
        return obj
4202
4203
    def __str__(self):
4204
        return 'NodeAttributes(' + 'SpecifiedAttributes:' + str(self.SpecifiedAttributes) + ', ' + \
4205
               'DisplayName:' + str(self.DisplayName) + ', ' + \
4206
               'Description:' + str(self.Description) + ', ' + \
4207
               'WriteMask:' + str(self.WriteMask) + ', ' + \
4208
               'UserWriteMask:' + str(self.UserWriteMask) + ')'
4209
4210
    __repr__ = __str__
4211
4212
4213
class ObjectAttributes(FrozenClass):
@@ 7731-7788 (lines=58) @@
7728
    __repr__ = __str__
7729
7730
7731
class AttributeOperand(FrozenClass):
7732
    '''
7733
    :ivar NodeId:
7734
    :vartype NodeId: NodeId
7735
    :ivar Alias:
7736
    :vartype Alias: String
7737
    :ivar BrowsePath:
7738
    :vartype BrowsePath: RelativePath
7739
    :ivar AttributeId:
7740
    :vartype AttributeId: UInt32
7741
    :ivar IndexRange:
7742
    :vartype IndexRange: String
7743
    '''
7744
7745
    ua_types = [
7746
7747
        ('NodeId', 'NodeId'),
7748
        ('Alias', 'String'),
7749
        ('BrowsePath', 'RelativePath'),
7750
        ('AttributeId', 'UInt32'),
7751
        ('IndexRange', 'String'),
7752
               ]
7753
7754
    def __init__(self):
7755
        self.NodeId = NodeId()
7756
        self.Alias = None
7757
        self.BrowsePath = RelativePath()
7758
        self.AttributeId = 0
7759
        self.IndexRange = None
7760
        self._freeze = True
7761
7762
    def to_binary(self):
7763
        packet = []
7764
        packet.append(self.NodeId.to_binary())
7765
        packet.append(uabin.Primitives.String.pack(self.Alias))
7766
        packet.append(self.BrowsePath.to_binary())
7767
        packet.append(uabin.Primitives.UInt32.pack(self.AttributeId))
7768
        packet.append(uabin.Primitives.String.pack(self.IndexRange))
7769
        return b''.join(packet)
7770
7771
    @staticmethod
7772
    def from_binary(data):
7773
        obj = AttributeOperand()
7774
        obj.NodeId = NodeId.from_binary(data)
7775
        self.Alias = uabin.Primitives.String.unpack(data)
7776
        obj.BrowsePath = RelativePath.from_binary(data)
7777
        self.AttributeId = uabin.Primitives.UInt32.unpack(data)
7778
        self.IndexRange = uabin.Primitives.String.unpack(data)
7779
        return obj
7780
7781
    def __str__(self):
7782
        return 'AttributeOperand(' + 'NodeId:' + str(self.NodeId) + ', ' + \
7783
               'Alias:' + str(self.Alias) + ', ' + \
7784
               'BrowsePath:' + str(self.BrowsePath) + ', ' + \
7785
               'AttributeId:' + str(self.AttributeId) + ', ' + \
7786
               'IndexRange:' + str(self.IndexRange) + ')'
7787
7788
    __repr__ = __str__
7789
7790
7791
class SimpleAttributeOperand(FrozenClass):