Code Duplication    Length = 26-31 lines in 3 locations

opcua/ua/uaprotocol_auto.py 2 locations

@@ 3068-3098 (lines=31) @@
3065
3066
    __repr__ = __str__
3067
3068
3069
class AnonymousIdentityToken(FrozenClass):
3070
    '''
3071
    A token representing an anonymous user.
3072
3073
    :ivar PolicyId:
3074
    :vartype PolicyId: String
3075
    '''
3076
    def __init__(self, binary=None):
3077
        if binary is not None:
3078
            self._binary_init(binary)
3079
            self._freeze = True
3080
            return
3081
        self.PolicyId = None
3082
        self._freeze = True
3083
3084
    def to_binary(self):
3085
        packet = []
3086
        packet.append(pack_string(self.PolicyId))
3087
        return b''.join(packet)
3088
3089
    @staticmethod
3090
    def from_binary(data):
3091
        return AnonymousIdentityToken(data)
3092
3093
    def _binary_init(self, data):
3094
        self.PolicyId = unpack_string(data)
3095
3096
    def __str__(self):
3097
        return 'AnonymousIdentityToken(' + 'PolicyId:' + str(self.PolicyId) + ')'
3098
3099
    __repr__ = __str__
3100
3101
@@ 3035-3065 (lines=31) @@
3032
3033
    __repr__ = __str__
3034
3035
3036
class UserIdentityToken(FrozenClass):
3037
    '''
3038
    A base type for a user identity token.
3039
3040
    :ivar PolicyId:
3041
    :vartype PolicyId: String
3042
    '''
3043
    def __init__(self, binary=None):
3044
        if binary is not None:
3045
            self._binary_init(binary)
3046
            self._freeze = True
3047
            return
3048
        self.PolicyId = None
3049
        self._freeze = True
3050
3051
    def to_binary(self):
3052
        packet = []
3053
        packet.append(pack_string(self.PolicyId))
3054
        return b''.join(packet)
3055
3056
    @staticmethod
3057
    def from_binary(data):
3058
        return UserIdentityToken(data)
3059
3060
    def _binary_init(self, data):
3061
        self.PolicyId = unpack_string(data)
3062
3063
    def __str__(self):
3064
        return 'UserIdentityToken(' + 'PolicyId:' + str(self.PolicyId) + ')'
3065
3066
    __repr__ = __str__
3067
3068

opcua/ua/uatypes.py 1 location

@@ 1043-1068 (lines=26) @@
1040
            dimensions = unpack_uatype_array("Int32", data)
1041
            value = reshape(value, dimensions)
1042
1043
        return Variant(value, vtype, dimensions)
1044
1045
1046
def reshape(flat, dims):
1047
    subdims = dims[1:]
1048
    subsize = 1
1049
    for i in subdims:
1050
        if i == 0:
1051
            i = 1
1052
        subsize *= i
1053
    while dims[0] * subsize > len(flat):
1054
        flat.append([])
1055
    if not subdims or subdims == [0]:
1056
        return flat
1057
    return [reshape(flat[i: i + subsize], subdims) for i in range(0, len(flat), subsize)]
1058
1059
1060
def _split_list(l, n):
1061
    n = max(1, n)
1062
    return [l[i:i + n] for i in range(0, len(l), n)]
1063
1064
1065
def flatten_and_get_shape(mylist):
1066
    dims = []
1067
    dims.append(len(mylist))
1068
    while isinstance(mylist[0], (list, tuple)):
1069
        dims.append(len(mylist[0]))
1070
        mylist = [item for sublist in mylist for item in sublist]
1071
        if len(mylist) == 0: