Code Duplication    Length = 23-26 lines in 2 locations

opcua/ua/uaprotocol_hand.py 2 locations

@@ 162-187 (lines=26) @@
159
            = struct.unpack("<5I", data.read(20))
160
        return ack
161
162
163
class AsymmetricAlgorithmHeader(uatypes.FrozenClass):
164
165
    def __init__(self):
166
        self.SecurityPolicyURI = "http://opcfoundation.org/UA/SecurityPolicy#None"
167
        self.SenderCertificate = None
168
        self.ReceiverCertificateThumbPrint = None
169
        self._freeze = True
170
171
    def to_binary(self):
172
        b = []
173
        b.append(uatypes.pack_string(self.SecurityPolicyURI))
174
        b.append(uatypes.pack_string(self.SenderCertificate))
175
        b.append(uatypes.pack_string(self.ReceiverCertificateThumbPrint))
176
        return b"".join(b)
177
178
    @staticmethod
179
    def from_binary(data):
180
        hdr = AsymmetricAlgorithmHeader()
181
        hdr.SecurityPolicyURI = uatypes.unpack_string(data)
182
        hdr.SenderCertificate = uatypes.unpack_bytes(data)
183
        hdr.ReceiverCertificateThumbPrint = uatypes.unpack_bytes(data)
184
        return hdr
185
186
    def __str__(self):
187
        return "{}(SecurityPolicy:{}, certificatesize:{}, receiverCertificatesize:{} )".format(
188
            self.__class__.__name__, self.SecurityPolicyURI, len(self.SenderCertificate),
189
            len(self.ReceiverCertificateThumbPrint))
190
    __repr__ = __str__
@@ 110-132 (lines=23) @@
107
            self.MessageType, self.ChunkType, self.body_size, self.ChannelId)
108
    __repr__ = __str__
109
110
111
class ErrorMessage(uatypes.FrozenClass):
112
113
    def __init__(self):
114
        self.Error = uatypes.StatusCode()
115
        self.Reason = ""
116
        self._freeze = True
117
118
    def to_binary(self):
119
        b = []
120
        b.append(self.Error.to_binary())
121
        b.append(uatypes.pack_string(self.Reason))
122
        return b"".join(b)
123
124
    @staticmethod
125
    def from_binary(data):
126
        ack = ErrorMessage()
127
        ack.Error = uatypes.StatusCode.from_binary(data)
128
        ack.Reason = uatypes.unpack_string(data)
129
        return ack
130
131
    def __str__(self):
132
        return "MessageAbort(error:{}, reason:{})".format(self.Error, self.Reason)
133
    __repr__ = __str__
134
135