Code Duplication    Length = 26-31 lines in 3 locations

opcua/ua/uaprotocol_auto.py 2 locations

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

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: