Code Duplication    Length = 42-48 lines in 2 locations

Trakttv.bundle/Contents/Libraries/Shared/plugin/managers/user.py 1 location

@@ 14-61 (lines=48) @@
11
log = logging.getLogger(__name__)
12
13
14
class GetUser(Get):
15
    def __call__(self, user):
16
        user = self.manager.parse_user(user)
17
18
        if not user:
19
            return None
20
21
        return super(GetUser, self).__call__(
22
            User.key == to_integer(user['key'])
23
        )
24
25
    def or_create(self, user, fetch=False, match=False, filtered_exception=False):
26
        user = self.manager.parse_user(user)
27
28
        if not user:
29
            return None
30
31
        try:
32
            # Create new user
33
            obj = self.manager.create(
34
                key=to_integer(user['key'])
35
            )
36
37
            # Update newly created object
38
            self.manager.update(
39
                obj, user,
40
41
                fetch=fetch,
42
                match=match,
43
                filtered_exception=filtered_exception
44
            )
45
46
            return obj
47
        except (apsw.ConstraintError, peewee.IntegrityError):
48
            # Return existing user
49
            obj = self(user)
50
51
            if fetch or match:
52
                # Update existing `User`
53
                self.manager.update(
54
                    obj, user,
55
56
                    fetch=fetch,
57
                    match=match,
58
                    filtered_exception=filtered_exception
59
                )
60
61
            return obj
62
63
64
class UpdateUser(Update):

Trakttv.bundle/Contents/Libraries/Shared/plugin/managers/client.py 1 location

@@ 15-56 (lines=42) @@
12
log = logging.getLogger(__name__)
13
14
15
class GetClient(Get):
16
    def __call__(self, player):
17
        player = self.manager.parse_player(player)
18
19
        return super(GetClient, self).__call__(
20
            Client.key == player['key']
21
        )
22
23
    def or_create(self, player, fetch=False, match=False, filtered_exception=False):
24
        player = self.manager.parse_player(player)
25
26
        try:
27
            # Create new client
28
            obj = self.manager.create(
29
                key=player['key']
30
            )
31
32
            # Update newly created object
33
            self.manager.update(
34
                obj, player,
35
36
                fetch=fetch,
37
                match=match,
38
                filtered_exception=filtered_exception
39
            )
40
41
            return obj
42
        except (apsw.ConstraintError, peewee.IntegrityError):
43
            # Return existing user
44
            obj = self(player)
45
46
            if fetch or match:
47
                # Update existing `User`
48
                self.manager.update(
49
                    obj, player,
50
51
                    fetch=fetch,
52
                    match=match,
53
                    filtered_exception=filtered_exception
54
                )
55
56
            return obj
57
58
59
class UpdateClient(Update):