Code Duplication    Length = 62-64 lines in 2 locations

opcua/ua/uaprotocol_auto.py 2 locations

@@ 1868-1931 (lines=64) @@
1865
    '''
1866
1867
    ua_types = (
1868
1869
        ('RecordId', 'UInt32'),
1870
        ('ServerName', 'String'),
1871
        ('DiscoveryUrl', 'String'),
1872
        ('ServerCapabilities', 'ListOfString'),
1873
               )
1874
1875
    def __init__(self, binary=None):
1876
        if binary is not None:
1877
            self._binary_init(binary)
1878
            self._freeze = True
1879
            return
1880
        self.RecordId = 0
1881
        self.ServerName = None
1882
        self.DiscoveryUrl = None
1883
        self.ServerCapabilities = []
1884
        self._freeze = True
1885
1886
    def to_binary(self):
1887
        packet = []
1888
        packet.append(uabin.Primitives.UInt32.pack(self.RecordId))
1889
        packet.append(uabin.Primitives.String.pack(self.ServerName))
1890
        packet.append(uabin.Primitives.String.pack(self.DiscoveryUrl))
1891
        packet.append(uabin.Primitives.Int32.pack(len(self.ServerCapabilities)))
1892
        for fieldname in self.ServerCapabilities:
1893
            packet.append(uabin.Primitives.String.pack(fieldname))
1894
        return b''.join(packet)
1895
1896
    @staticmethod
1897
    def from_binary(data):
1898
        return ServerOnNetwork(data)
1899
1900
    def _binary_init(self, data):
1901
        self.RecordId = uabin.Primitives.UInt32.unpack(data)
1902
        self.ServerName = uabin.Primitives.String.unpack(data)
1903
        self.DiscoveryUrl = uabin.Primitives.String.unpack(data)
1904
        self.ServerCapabilities = uabin.Primitives.String.unpack_array(data)
1905
1906
    def __str__(self):
1907
        return 'ServerOnNetwork(' + 'RecordId:' + str(self.RecordId) + ', ' + \
1908
               'ServerName:' + str(self.ServerName) + ', ' + \
1909
               'DiscoveryUrl:' + str(self.DiscoveryUrl) + ', ' + \
1910
               'ServerCapabilities:' + str(self.ServerCapabilities) + ')'
1911
1912
    __repr__ = __str__
1913
1914
1915
class FindServersOnNetworkParameters(FrozenClass):
1916
    '''
1917
    :ivar StartingRecordId:
1918
    :vartype StartingRecordId: UInt32
1919
    :ivar MaxRecordsToReturn:
1920
    :vartype MaxRecordsToReturn: UInt32
1921
    :ivar ServerCapabilityFilter:
1922
    :vartype ServerCapabilityFilter: String
1923
    '''
1924
1925
    ua_types = (
1926
1927
        ('StartingRecordId', 'UInt32'),
1928
        ('MaxRecordsToReturn', 'UInt32'),
1929
        ('ServerCapabilityFilter', 'ListOfString'),
1930
               )
1931
1932
    def __init__(self, binary=None):
1933
        if binary is not None:
1934
            self._binary_init(binary)
@@ 2696-2757 (lines=62) @@
2693
        ('MdnsServerName', 'String'),
2694
        ('ServerCapabilities', 'ListOfString'),
2695
               )
2696
2697
    def __init__(self, binary=None):
2698
        if binary is not None:
2699
            self._binary_init(binary)
2700
            self._freeze = True
2701
            return
2702
        self.MdnsServerName = None
2703
        self.ServerCapabilities = []
2704
        self._freeze = True
2705
2706
    def to_binary(self):
2707
        packet = []
2708
        packet.append(uabin.Primitives.String.pack(self.MdnsServerName))
2709
        packet.append(uabin.Primitives.Int32.pack(len(self.ServerCapabilities)))
2710
        for fieldname in self.ServerCapabilities:
2711
            packet.append(uabin.Primitives.String.pack(fieldname))
2712
        return b''.join(packet)
2713
2714
    @staticmethod
2715
    def from_binary(data):
2716
        return MdnsDiscoveryConfiguration(data)
2717
2718
    def _binary_init(self, data):
2719
        self.MdnsServerName = uabin.Primitives.String.unpack(data)
2720
        self.ServerCapabilities = uabin.Primitives.String.unpack_array(data)
2721
2722
    def __str__(self):
2723
        return 'MdnsDiscoveryConfiguration(' + 'MdnsServerName:' + str(self.MdnsServerName) + ', ' + \
2724
               'ServerCapabilities:' + str(self.ServerCapabilities) + ')'
2725
2726
    __repr__ = __str__
2727
2728
2729
class RegisterServer2Parameters(FrozenClass):
2730
    '''
2731
    :ivar Server:
2732
    :vartype Server: RegisteredServer
2733
    :ivar DiscoveryConfiguration:
2734
    :vartype DiscoveryConfiguration: ExtensionObject
2735
    '''
2736
2737
    ua_types = (
2738
2739
        ('Server', 'RegisteredServer'),
2740
        ('DiscoveryConfiguration', 'ListOfExtensionObject'),
2741
               )
2742
2743
    def __init__(self, binary=None):
2744
        if binary is not None:
2745
            self._binary_init(binary)
2746
            self._freeze = True
2747
            return
2748
        self.Server = RegisteredServer()
2749
        self.DiscoveryConfiguration = []
2750
        self._freeze = True
2751
2752
    def to_binary(self):
2753
        packet = []
2754
        packet.append(self.Server.to_binary())
2755
        packet.append(uabin.Primitives.Int32.pack(len(self.DiscoveryConfiguration)))
2756
        for fieldname in self.DiscoveryConfiguration:
2757
            packet.append(extensionobject_to_binary(fieldname))
2758
        return b''.join(packet)
2759
2760
    @staticmethod