Total Complexity | 17 |
Total Lines | 54 |
Duplicated Lines | 90.74 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | import abc |
||
2 | import six |
||
3 | |||
4 | |||
5 | View Code Duplication | class AbstractResponseData(six.with_metaclass(abc.ABCMeta, object)): |
|
6 | @abc.abstractmethod |
||
7 | def __init__(self): |
||
8 | self.time = None |
||
9 | self.level = None |
||
10 | self.locationName = None |
||
11 | self.attributes = None |
||
12 | |||
13 | def getTime(self): |
||
14 | return self.time |
||
15 | |||
16 | def setTime(self, time): |
||
17 | self.time = time |
||
18 | |||
19 | def getLevel(self): |
||
20 | return self.level |
||
21 | |||
22 | def setLevel(self, level): |
||
23 | self.level = level |
||
24 | |||
25 | def getLocationName(self): |
||
26 | if six.PY2: |
||
27 | return self.locationName |
||
28 | if self.locationName is not None: |
||
29 | return self.locationName.decode('utf-8') |
||
30 | return self.locationName |
||
31 | |||
32 | def setLocationName(self, locationName): |
||
33 | self.locationName = locationName |
||
34 | |||
35 | def getAttributes(self): |
||
36 | if six.PY2: |
||
37 | return self.attributes |
||
38 | else: |
||
39 | return self.convert(self.attributes) |
||
40 | |||
41 | def setAttributes(self, attributes): |
||
42 | self.attributes = attributes |
||
43 | |||
44 | def convert(self, data): |
||
45 | if isinstance(data, dict): |
||
46 | return dict(map(self.convert, data.items())) |
||
47 | if isinstance(data, bytes): |
||
48 | return data.decode('utf-8') |
||
49 | if isinstance(data, tuple): |
||
50 | return tuple(map(self.convert, data)) |
||
51 | if isinstance(data, list): |
||
52 | return list(map(self.convert, data)) |
||
53 | return data |
||
54 |