Completed
Push — master ( 229cac...232edf )
by Thomas
10:56
created

exabgp.bgp.message.update.attribute.bgpls.prefix.srrid   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 46.51 %

Importance

Changes 0
Metric Value
eloc 18
dl 20
loc 43
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

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

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
srrid.py
4
5
Created by Evelio Vila
6
Copyright (c) 2014-2017 Exa Networks. All rights reserved.
7
"""
8
9
from exabgp.protocol.ip import IP
10
from exabgp.bgp.message.update.attribute.bgpls.linkstate import LINKSTATE
11
12
#    draft-gredler-idr-bgp-ls-segment-routing-ext-03
13
#    0                   1                   2                   3
14
#    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
15
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
16
#   |            Type               |            Length             |
17
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
18
#   //                  IPv4/IPv6 Address (Router-ID)              //
19
#   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
20
#     Source Router Identifier (Source Router-ID) TLV
21
22
23 View Code Duplication
@LINKSTATE.register()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
24
class SrSourceRouterID(object):
25
    TLV = 1171
26
27
    def __init__(self, srid):
28
        self.srid = srid
29
30
    def __repr__(self):
31
        return "Source router identifier: %s" % (self.srid)
32
33
    @classmethod
34
    def unpack(cls, data, length):
35
        size = len(data)
36
        if size not in (4, 16):
37
            raise Notify(3, 5, "Error parsing SR Source Router ID. Wrong size")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Notify does not seem to be defined.
Loading history...
38
39
        return cls(IP.unpack(data[:size]))
40
41
    def json(self, compact=None):
42
        return '"sr-source-router-id": "%s"' % str(self.srid)
43