Completed
Push — master ( ae553d...3df76a )
by Thomas
25:18 queued 11:15
created

exabgp.bgp.message.update.attribute.bgpls.link.admingroup   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 57.14 %

Importance

Changes 0
Metric Value
eloc 19
dl 20
loc 35
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A AdminGroup.unpack() 7 7 2
A AdminGroup.__init__() 2 2 1
A AdminGroup.__repr__() 2 2 1
A AdminGroup.json() 2 2 1

How to fix   Duplicated Code   

Duplicated Code

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
# encoding: utf-8
2
"""
3
admingroup.py
4
5
Created by Evelio Vila on 2016-12-01.
6
Copyright (c) 2014-2017 Exa Networks. All rights reserved.
7
"""
8
9
from struct import unpack
10
11
from exabgp.bgp.message.notification import Notify
12
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LinkState
13
14
15 View Code Duplication
@LinkState.register()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
16
class AdminGroup(object):
17
    TLV = 1088
18
19
    def __init__(self, colormask):
20
        self.colormask = colormask
21
22
    def __repr__(self):
23
        return "Admin Group mask: %s" % (self.colormask)
24
25
    @classmethod
26
    def unpack(cls, data, length):
27
        if length != 4:
28
            raise Notify(3, 5, "Unable to decode attribute. Incorrect Size")
29
30
        colormask = unpack('!L', data[:4])[0]
31
        return cls(colormask=colormask)
32
33
    def json(self, compact=None):
34
        return '"admin-group-mask": %s' % self.colormask
35