diff --git a/src/exabgp/application/decode.py b/src/exabgp/application/decode.py index 75cc55de6..da323c46d 100644 --- a/src/exabgp/application/decode.py +++ b/src/exabgp/application/decode.py @@ -6,7 +6,7 @@ from exabgp.configuration.configuration import Configuration -from exabgp.debug import trace_interceptor +from exabgp.debug.intercept import trace_interceptor from exabgp.environment import Env from exabgp.environment import getenv diff --git a/src/exabgp/application/healthcheck.py b/src/exabgp/application/healthcheck.py index 0d16370c5..cba894fd4 100644 --- a/src/exabgp/application/healthcheck.py +++ b/src/exabgp/application/healthcheck.py @@ -135,9 +135,9 @@ def parse(): # build an equivalent command line. args = sum( [ - "--{0}".format(l.strip()).split("=", 1) - for l in options.config.readlines() - if not l.strip().startswith("#") and l.strip() + "--{0}".format(line.strip()).split("=", 1) + for line in options.config.readlines() + if not line.strip().startswith("#") and line.strip() ], [], ) diff --git a/src/exabgp/application/server.py b/src/exabgp/application/server.py index e926c757c..1f8bf665b 100755 --- a/src/exabgp/application/server.py +++ b/src/exabgp/application/server.py @@ -10,7 +10,7 @@ import argparse import platform -from exabgp.debug import trace_interceptor +from exabgp.debug.intercept import trace_interceptor # import before the fork to improve copy on write memory savings from exabgp.reactor.loop import Reactor diff --git a/src/exabgp/application/validate.py b/src/exabgp/application/validate.py index 28bcb523b..99249796b 100644 --- a/src/exabgp/application/validate.py +++ b/src/exabgp/application/validate.py @@ -12,7 +12,7 @@ from exabgp.configuration.configuration import Configuration from exabgp.bgp.neighbor import NeighborTemplate -from exabgp.debug import trace_interceptor +from exabgp.debug.intercept import trace_interceptor from exabgp.logger import log from exabgp.configuration.check import check_generation diff --git a/src/exabgp/application/version.py b/src/exabgp/application/version.py index ff9176681..3ed946804 100644 --- a/src/exabgp/application/version.py +++ b/src/exabgp/application/version.py @@ -2,7 +2,6 @@ """exabgp current version""" -import os import sys import argparse import platform diff --git a/src/exabgp/bgp/fsm.py b/src/exabgp/bgp/fsm.py index b706b1e8a..fdc178b50 100644 --- a/src/exabgp/bgp/fsm.py +++ b/src/exabgp/bgp/fsm.py @@ -7,8 +7,6 @@ License: 3-clause BSD. (See the COPYRIGHT file) """ -import sys - # https://en.wikipedia.org/wiki/Border_Gateway_Protocol#Finite-state_machines diff --git a/src/exabgp/bgp/message/notification.py b/src/exabgp/bgp/message/notification.py index c7dda22a1..eafcef979 100644 --- a/src/exabgp/bgp/message/notification.py +++ b/src/exabgp/bgp/message/notification.py @@ -99,7 +99,7 @@ def __init__(self, code, subcode, data=b'', parse_data=True): self.data = data return - if not (code, subcode) in [(6, 2), (6, 4)]: + if (code, subcode) not in [(6, 2), (6, 4)]: self.data = data if not len([_ for _ in str(data) if _ not in string.printable]) else hexbytes(data) return diff --git a/src/exabgp/bgp/message/open/asn.py b/src/exabgp/bgp/message/open/asn.py index 029b93c11..2d3a1308d 100644 --- a/src/exabgp/bgp/message/open/asn.py +++ b/src/exabgp/bgp/message/open/asn.py @@ -9,7 +9,6 @@ from struct import pack from struct import unpack -import sys from exabgp.protocol.resource import Resource diff --git a/src/exabgp/bgp/message/open/capability/extended.py b/src/exabgp/bgp/message/open/capability/extended.py index 451e86401..4cd94bb61 100644 --- a/src/exabgp/bgp/message/open/capability/extended.py +++ b/src/exabgp/bgp/message/open/capability/extended.py @@ -7,7 +7,6 @@ License: 3-clause BSD. (See the COPYRIGHT file) """ -from exabgp.bgp.message.open.asn import ASN from exabgp.bgp.message.open.capability.capability import Capability # ========================================================================= ASN4 diff --git a/src/exabgp/bgp/message/open/capability/negotiated.py b/src/exabgp/bgp/message/open/capability/negotiated.py index d4d3f7a51..75aa06dcd 100644 --- a/src/exabgp/bgp/message/open/capability/negotiated.py +++ b/src/exabgp/bgp/message/open/capability/negotiated.py @@ -7,7 +7,6 @@ License: 3-clause BSD. (See the COPYRIGHT file) """ -from exabgp.protocol.family import AFI from exabgp.bgp.message.open.asn import ASN from exabgp.bgp.message.open.asn import AS_TRANS from exabgp.bgp.message.open.holdtime import HoldTime diff --git a/src/exabgp/bgp/message/update/attribute/bgpls/node/srcap.py b/src/exabgp/bgp/message/update/attribute/bgpls/node/srcap.py index 23cc2a697..b9180e7dd 100644 --- a/src/exabgp/bgp/message/update/attribute/bgpls/node/srcap.py +++ b/src/exabgp/bgp/message/update/attribute/bgpls/node/srcap.py @@ -69,15 +69,15 @@ def unpack(cls, data): # SID/Label: If length is set to 3, then the 20 rightmost bits # represent a label. If length is set to 4, then the value # represents a 32 bit SID. - t, l = unpack('!HH', data[3:7]) - if t != 1161: - raise Notify(3, 5, "Invalid sub-TLV type: {}".format(t)) - if l == 3: - sids.append([range_size, unpack('!I', bytes([0]) + data[7 : l + 7])[0] & 0xFFFFF]) - elif l == 4: + sub_type, length = unpack('!HH', data[3:7]) + if sub_type != 1161: + raise Notify(3, 5, "Invalid sub-TLV type: {}".format(sub_type)) + if length == 3: + sids.append([range_size, unpack('!I', bytes([0]) + data[7 : length + 7])[0] & 0xFFFFF]) + elif length == 4: # XXX: really we are reading 7+ but then re-parsing it again ?? - sids.append([range_size, unpack('!I', data[7 : l + 7])[0]]) - data = data[l + 7 :] + sids.append([range_size, unpack('!I', data[7 : length + 7])[0]]) + data = data[length + 7 :] return cls(flags, sids) diff --git a/src/exabgp/bgp/message/update/attribute/community/__init__.py b/src/exabgp/bgp/message/update/attribute/community/__init__.py index bf3a9d15f..9148acf11 100644 --- a/src/exabgp/bgp/message/update/attribute/community/__init__.py +++ b/src/exabgp/bgp/message/update/attribute/community/__init__.py @@ -9,11 +9,11 @@ # flake8: noqa: F401,E261 -from exabgp.bgp.message.update.attribute.community.initial import Community -from exabgp.bgp.message.update.attribute.community.initial import Communities +from exabgp.bgp.message.update.attribute.community.initial.community import Community +from exabgp.bgp.message.update.attribute.community.initial.communities import Communities -from exabgp.bgp.message.update.attribute.community.large import LargeCommunity -from exabgp.bgp.message.update.attribute.community.large import LargeCommunities +from exabgp.bgp.message.update.attribute.community.large.community import LargeCommunity +from exabgp.bgp.message.update.attribute.community.large.communities import LargeCommunities -from exabgp.bgp.message.update.attribute.community.extended import ExtendedCommunity -from exabgp.bgp.message.update.attribute.community.extended import ExtendedCommunities +from exabgp.bgp.message.update.attribute.community.extended.community import ExtendedCommunity +from exabgp.bgp.message.update.attribute.community.extended.communities import ExtendedCommunities diff --git a/src/exabgp/bgp/message/update/attribute/community/initial/__init__.py b/src/exabgp/bgp/message/update/attribute/community/initial/__init__.py deleted file mode 100644 index d7deeb40f..000000000 --- a/src/exabgp/bgp/message/update/attribute/community/initial/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# encoding: utf-8 -""" -community.py - -Created by Thomas Mangin on 2009-11-05. -Copyright (c) 2009-2017 Exa Networks. All rights reserved. -License: 3-clause BSD. (See the COPYRIGHT file) -""" - -from exabgp.bgp.message.update.attribute.community.initial.community import Community -from exabgp.bgp.message.update.attribute.community.initial.communities import Communities - - -# TODO: we should have the common code for the three kind of community separated -# TODO: and this is what should be used for inheritance. diff --git a/src/exabgp/bgp/message/update/attribute/community/large/__init__.py b/src/exabgp/bgp/message/update/attribute/community/large/__init__.py deleted file mode 100644 index 20d7e3448..000000000 --- a/src/exabgp/bgp/message/update/attribute/community/large/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# encoding: utf-8 -""" - -Copyright (c) 2016 Job Snijders -Copyright (c) 2009-2017 Exa Networks. All rights reserved. -License: 3-clause BSD. (See the COPYRIGHT file) -""" - -# Large Community should be imported from this file -# as it makes sure that all the registering decorator are run - -from exabgp.bgp.message.update.attribute.community.large.community import LargeCommunity -from exabgp.bgp.message.update.attribute.community.large.communities import LargeCommunities diff --git a/src/exabgp/bgp/message/update/attribute/community/large/communities.py b/src/exabgp/bgp/message/update/attribute/community/large/communities.py index 59a328efa..ee3b025ed 100644 --- a/src/exabgp/bgp/message/update/attribute/community/large/communities.py +++ b/src/exabgp/bgp/message/update/attribute/community/large/communities.py @@ -6,8 +6,8 @@ """ from exabgp.bgp.message.update.attribute import Attribute -from exabgp.bgp.message.update.attribute.community.initial import Communities -from exabgp.bgp.message.update.attribute.community.large import LargeCommunity +from exabgp.bgp.message.update.attribute.community.initial.communities import Communities +from exabgp.bgp.message.update.attribute.community.large.community import LargeCommunity from exabgp.bgp.message.notification import Notify diff --git a/src/exabgp/bgp/message/update/attribute/sr/srv6/l2service.py b/src/exabgp/bgp/message/update/attribute/sr/srv6/l2service.py index e7068f062..e4535ab27 100644 --- a/src/exabgp/bgp/message/update/attribute/sr/srv6/l2service.py +++ b/src/exabgp/bgp/message/update/attribute/sr/srv6/l2service.py @@ -54,7 +54,7 @@ def unpack(cls, data, length): code = data[0] length = unpack("!H", data[1:3])[0] if code in cls.registered_subtlvs: - subtlv = klass = cls.registered_subtlvs[code].unpack(data[3 : length + 3], length) + subtlv = cls.registered_subtlvs[code].unpack(data[3 : length + 3], length) else: subtlv = GenericSrv6ServiceSubTlv(code, data[3 : length + 3]) subtlvs.append(subtlv) diff --git a/src/exabgp/bgp/message/update/attribute/sr/srv6/l3service.py b/src/exabgp/bgp/message/update/attribute/sr/srv6/l3service.py index aec3e71b3..5ae1dede6 100644 --- a/src/exabgp/bgp/message/update/attribute/sr/srv6/l3service.py +++ b/src/exabgp/bgp/message/update/attribute/sr/srv6/l3service.py @@ -54,7 +54,7 @@ def unpack(cls, data, length): code = data[0] length = unpack("!H", data[1:3])[0] if code in cls.registered_subtlvs: - subtlv = klass = cls.registered_subtlvs[code].unpack(data[3 : length + 3], length) + subtlv = cls.registered_subtlvs[code].unpack(data[3 : length + 3], length) else: subtlv = GenericSrv6ServiceSubTlv(code, data[3 : length + 3]) subtlvs.append(subtlv) diff --git a/src/exabgp/bgp/message/update/attribute/sr/srv6/sidinformation.py b/src/exabgp/bgp/message/update/attribute/sr/srv6/sidinformation.py index 8e977cec5..dc558c72c 100644 --- a/src/exabgp/bgp/message/update/attribute/sr/srv6/sidinformation.py +++ b/src/exabgp/bgp/message/update/attribute/sr/srv6/sidinformation.py @@ -67,7 +67,7 @@ def unpack(cls, data, length): code = data[0] length = unpack("!H", data[1:3])[0] if code in cls.registered_subsubtlvs: - subsubtlv = klass = cls.registered_subsubtlvs[code].unpack(data[3 : length + 3], length) + subsubtlv = cls.registered_subsubtlvs[code].unpack(data[3 : length + 3], length) else: subsubtlv = GenericSrv6ServiceDataSubSubTlv(code, data[3 : length + 3]) subsubtlvs.append(subsubtlv) diff --git a/src/exabgp/bgp/message/update/nlri/flow.py b/src/exabgp/bgp/message/update/nlri/flow.py index 6582296ce..ff1fc3f0e 100644 --- a/src/exabgp/bgp/message/update/nlri/flow.py +++ b/src/exabgp/bgp/message/update/nlri/flow.py @@ -189,9 +189,9 @@ def __init__(self, operations, value): self.first = None # handled by pack/str def pack(self): - l, v = self.encode(self.value) - op = self.operations | _len_to_bit(l) - return bytes([op]) + v + length, value = self.encode(self.value) + op = self.operations | _len_to_bit(length) + return bytes([op]) + value def encode(self, value): raise NotImplementedError('this method must be implemented by subclasses') diff --git a/src/exabgp/bgp/message/update/nlri/mup/dsd.py b/src/exabgp/bgp/message/update/nlri/mup/dsd.py index 01c0e6a63..6cae5ffe6 100644 --- a/src/exabgp/bgp/message/update/nlri/mup/dsd.py +++ b/src/exabgp/bgp/message/update/nlri/mup/dsd.py @@ -11,7 +11,6 @@ from exabgp.bgp.message.update.nlri.mup.nlri import MUP from exabgp.bgp.message.notification import Notify -from struct import pack # +-----------------------------------+ @@ -74,7 +73,7 @@ def unpack(cls, data, afi): data_len = len(data) rd = RouteDistinguisher.unpack(data[:8]) size = data_len - 8 - if not size in [4, 16]: + if size not in [4, 16]: raise Notify(3, 5, "Invalid IP size, expect 4 or 16 octets. accuracy size %d" % size) ip = IP.unpack(data[8 : 8 + size]) diff --git a/src/exabgp/bgp/message/update/nlri/mup/nlri.py b/src/exabgp/bgp/message/update/nlri/mup/nlri.py index 34131e1ed..0f1327b18 100644 --- a/src/exabgp/bgp/message/update/nlri/mup/nlri.py +++ b/src/exabgp/bgp/message/update/nlri/mup/nlri.py @@ -6,7 +6,6 @@ Copyright (c) 2023 BBSakura Networks Inc. All rights reserved. """ from struct import pack -from exabgp.protocol.ip import NoNextHop from exabgp.protocol.family import AFI from exabgp.protocol.family import SAFI from exabgp.bgp.message import Action diff --git a/src/exabgp/bgp/message/update/nlri/mvpn/sharedjoin.py b/src/exabgp/bgp/message/update/nlri/mvpn/sharedjoin.py index 91da47c81..ba3367367 100644 --- a/src/exabgp/bgp/message/update/nlri/mvpn/sharedjoin.py +++ b/src/exabgp/bgp/message/update/nlri/mvpn/sharedjoin.py @@ -1,6 +1,3 @@ -from exabgp.protocol.family import AFI -from exabgp.protocol.family import SAFI - from exabgp.bgp.message.update.nlri.qualifier import RouteDistinguisher from exabgp.bgp.message.update.nlri.mvpn.nlri import MVPN from exabgp.bgp.message.notification import Notify diff --git a/src/exabgp/bgp/message/update/nlri/mvpn/sourcead.py b/src/exabgp/bgp/message/update/nlri/mvpn/sourcead.py index eb8569780..301b21e59 100644 --- a/src/exabgp/bgp/message/update/nlri/mvpn/sourcead.py +++ b/src/exabgp/bgp/message/update/nlri/mvpn/sourcead.py @@ -1,6 +1,3 @@ -from exabgp.protocol.family import AFI -from exabgp.protocol.family import SAFI - from exabgp.bgp.message.update.nlri.qualifier import RouteDistinguisher from exabgp.bgp.message.update.nlri.mvpn.nlri import MVPN from exabgp.bgp.message.notification import Notify diff --git a/src/exabgp/bgp/message/update/nlri/mvpn/sourcejoin.py b/src/exabgp/bgp/message/update/nlri/mvpn/sourcejoin.py index ef1c45ca4..394adb7f1 100644 --- a/src/exabgp/bgp/message/update/nlri/mvpn/sourcejoin.py +++ b/src/exabgp/bgp/message/update/nlri/mvpn/sourcejoin.py @@ -1,6 +1,3 @@ -from exabgp.protocol.family import AFI -from exabgp.protocol.family import SAFI - from exabgp.bgp.message.update.nlri.qualifier import RouteDistinguisher from exabgp.bgp.message.update.nlri.mvpn.nlri import MVPN from exabgp.bgp.message.notification import Notify diff --git a/src/exabgp/bgp/message/update/nlri/qualifier/labels.py b/src/exabgp/bgp/message/update/nlri/qualifier/labels.py index 5a80bf536..1dcb2bb9d 100644 --- a/src/exabgp/bgp/message/update/nlri/qualifier/labels.py +++ b/src/exabgp/bgp/message/update/nlri/qualifier/labels.py @@ -72,7 +72,7 @@ def __len__(self): def json(self): if len(self.labels) >= 1: return '"label": [ %s ]' % ', '.join( - ["[%d%s]" % (l, opt_raw_label(r, ', %d')) for (l, r) in zip(self.labels, self.raw_labels)] + ["[%d%s]" % (label, opt_raw_label(raw, ', %d')) for (label, raw) in zip(self.labels, self.raw_labels)] ) else: return '' @@ -80,7 +80,7 @@ def json(self): def __str__(self): if len(self.labels) > 1: return ' label [ %s ]' % ' '.join( - ["%d%s" % (l, opt_raw_label(r)) for (l, r) in zip(self.labels, self.raw_labels)] + ["%d%s" % (label, opt_raw_label(raw)) for (label, raw) in zip(self.labels, self.raw_labels)] ) elif len(self.labels) == 1: return ' label %d%s' % (self.labels[0], opt_raw_label(self.raw_labels[0])) @@ -89,7 +89,7 @@ def __str__(self): def __repr__(self): if len(self.labels) > 1: - return '[ %s ]' % ','.join(["%d%s" % (l, opt_raw_label(r)) for (l, r) in zip(self.labels, self.raw_labels)]) + return '[ %s ]' % ','.join(["%d%s" % (label, opt_raw_label(raw)) for (label, raw) in zip(self.labels, self.raw_labels)]) elif len(self.labels) == 1: return '%d%s' % (self.labels[0], opt_raw_label(self.raw_labels[0])) else: diff --git a/src/exabgp/bgp/neighbor.py b/src/exabgp/bgp/neighbor.py index 812b2c454..d513a30b0 100644 --- a/src/exabgp/bgp/neighbor.py +++ b/src/exabgp/bgp/neighbor.py @@ -18,7 +18,7 @@ from datetime import timedelta from exabgp.protocol.family import AFI -from exabgp.util.dns import host, domain +# from exabgp.util.dns import host, domain from exabgp.bgp.message import Message from exabgp.bgp.message.open.capability import AddPath @@ -575,25 +575,25 @@ def as_dict(cls, answer): 'add-path': {}, } - for (a, s), (l, p, aps, apr) in answer['families'].items(): + for (a, s), (lf, pf, aps, apr) in answer['families'].items(): k = '%s %s' % (a, s) - formated['local']['families'][k] = l - formated['peer']['families'][k] = p + formated['local']['families'][k] = lf + formated['peer']['families'][k] = pf formated['local']['add-path'][k] = aps formated['peer']['add-path'][k] = apr - if l and p: + if lf and pf: formated['families'].append(k) formated['add-path'][k] = _addpath(aps, apr) - for k, (l, p) in answer['capabilities'].items(): - formated['local']['capabilities'][k] = l - formated['peer']['capabilities'][k] = p - if l and p: + for k, (lc, pc) in answer['capabilities'].items(): + formated['local']['capabilities'][k] = lc + formated['peer']['capabilities'][k] = pc + if locals and pc: formated['capabilities'].append(k) - for k, (s, r) in answer['messages'].items(): - formated['messages']['sent'][k] = s - formated['messages']['received'][k] = r + for k, (ms, mr) in answer['messages'].items(): + formated['messages']['sent'][k] = ms + formated['messages']['received'][k] = mr formated['local']['address'] = answer['local-address'] formated['local']['as'] = answer['local-as'] @@ -623,14 +623,14 @@ def formated_dict(cls, answer): 'id': cls.extensive_kv % ('ID', answer['local-id'], _pr(answer['peer-id']), ''), 'hold': cls.extensive_kv % ('hold-time', answer['local-hold'], _pr(answer['peer-hold']), ''), 'capabilities': '\n'.join( - cls.extensive_kv % ('%s:' % k, _en(l), _en(p), '') for k, (l, p) in answer['capabilities'].items() + cls.extensive_kv % ('%s:' % k, _en(lc), _en(pc), '') for k, (lc, pc) in answer['capabilities'].items() ), 'families': '\n'.join( - cls.extensive_kv % ('%s %s:' % (a, s), _en(l), _en(r), _addpath(aps, apr)) - for (a, s), (l, r, apr, aps) in answer['families'].items() + cls.extensive_kv % ('%s %s:' % (a, s), _en(lf), _en(rf), _addpath(aps, apr)) + for (a, s), (lf, rf, apr, aps) in answer['families'].items() ), 'messages': '\n'.join( - cls.extensive_kv % ('%s:' % k, str(s), str(r), '') for k, (s, r) in answer['messages'].items() + cls.extensive_kv % ('%s:' % k, str(ms), str(mr), '') for k, (ms, mr) in answer['messages'].items() ), } diff --git a/src/exabgp/cli/command.py b/src/exabgp/cli/command.py index adc7c7874..b0d615f3c 100644 --- a/src/exabgp/cli/command.py +++ b/src/exabgp/cli/command.py @@ -1,6 +1,4 @@ import sys -import argparse -import os from vyos.xml import kw from vyos.util import call diff --git a/src/exabgp/cli/test.py b/src/exabgp/cli/test.py index d3a4b8c0f..12208e81a 100755 --- a/src/exabgp/cli/test.py +++ b/src/exabgp/cli/test.py @@ -4,7 +4,7 @@ from vyos.cli.completer import VyOSCompleter from vyos.cli.validator import VyOSValidator from vyos.cli.validator import ValidationError -from vyos.cli.command import dispatch +# from vyos.cli.command import dispatch from vyos.cli import msg diff --git a/src/exabgp/cli/validator.py b/src/exabgp/cli/validator.py index 5629612b1..4d41e9b3f 100644 --- a/src/exabgp/cli/validator.py +++ b/src/exabgp/cli/validator.py @@ -5,7 +5,7 @@ # from prompt_toolkit.validation import Validator from prompt_toolkit.validation import ValidationError -from prompt_toolkit.document import Document +# from prompt_toolkit.document import Document from vyos.modules import validation from vyos.cli import msg diff --git a/src/exabgp/conf/yang/__init__.py b/src/exabgp/conf/yang/__init__.py index 5b924deed..d8df05bba 100755 --- a/src/exabgp/conf/yang/__init__.py +++ b/src/exabgp/conf/yang/__init__.py @@ -6,8 +6,8 @@ Copyright (c) 2020 Exa Networks. All rights reserved. """ -from exabgp.conf.yang.model import Model -from exabgp.conf.yang.code import Code -from exabgp.conf.yang.tree import Parser +# from exabgp.conf.yang.model import Model +# from exabgp.conf.yang.code import Code +# from exabgp.conf.yang.tree import Parser -from exabgp.conf.yang.datatypes import kw +# from exabgp.conf.yang.datatypes import kw diff --git a/src/exabgp/conf/yang/code.py b/src/exabgp/conf/yang/code.py index 7e474bdd8..1a78520c0 100644 --- a/src/exabgp/conf/yang/code.py +++ b/src/exabgp/conf/yang/code.py @@ -13,11 +13,11 @@ # is used to generate code from the AST created from ast import Module, Import, FunctionDef, arguments, arg, alias -from ast import Load, Call, Return, Name, Attribute, Constant, Param -from ast import Add, If, Compare, Gt, Lt, GtE, LtE, And, Or +from ast import Load, Call, Return, Name, Attribute, Constant #, Param +from ast import If, Compare, Gt, Lt, And #, Add, GtE, LtE, Or from ast import BoolOp, UnaryOp, Not, USub -import astunparse +# import astunparse from exabgp.conf.yang.datatypes import kw from exabgp.conf.yang.datatypes import ranges diff --git a/src/exabgp/conf/yang/parser.py b/src/exabgp/conf/yang/parser.py index f0abebb46..2b2e002f3 100644 --- a/src/exabgp/conf/yang/parser.py +++ b/src/exabgp/conf/yang/parser.py @@ -221,7 +221,7 @@ def _parse_one(self, inside, tree, token, string): if string == '{': self.pop(Token.Punctuation, '{') self.pop(Token.Keyword, 'prefix') - prefix = self.formated(self.pop(Token.Literal.String)) + # prefix = self.formated(self.pop(Token.Literal.String)) self.pop(Token.Punctuation, ';') self.pop(Token.Punctuation, '}') self.imports(name) diff --git a/src/exabgp/configuration/announce/flow.py b/src/exabgp/configuration/announce/flow.py index d8c0bd465..8d49945fa 100644 --- a/src/exabgp/configuration/announce/flow.py +++ b/src/exabgp/configuration/announce/flow.py @@ -136,7 +136,6 @@ class AnnounceFlow(ParseAnnounce): 'fragment': 'nlri-add', 'icmp-code': 'nlri-add', 'icmp-type': 'nlri-add', - 'packet-length': 'nlri-add', 'dscp': 'nlri-add', 'traffic-class': 'nlri-add', 'flow-label': 'nlri-add', diff --git a/src/exabgp/configuration/announce/mup.py b/src/exabgp/configuration/announce/mup.py index 8e80614ea..2f9c75d71 100644 --- a/src/exabgp/configuration/announce/mup.py +++ b/src/exabgp/configuration/announce/mup.py @@ -9,8 +9,6 @@ from exabgp.rib.change import Change -from exabgp.bgp.message import Action - from exabgp.protocol.family import AFI from exabgp.protocol.family import SAFI diff --git a/src/exabgp/configuration/announce/mvpn.py b/src/exabgp/configuration/announce/mvpn.py index ff0924cf1..9393b5772 100644 --- a/src/exabgp/configuration/announce/mvpn.py +++ b/src/exabgp/configuration/announce/mvpn.py @@ -5,7 +5,6 @@ from exabgp.bgp.message import Action from exabgp.protocol.family import AFI -from exabgp.protocol.family import SAFI from exabgp.bgp.message.update.attribute import Attributes diff --git a/src/exabgp/configuration/announce/vpls.py b/src/exabgp/configuration/announce/vpls.py index aa9c6a106..a60e54358 100644 --- a/src/exabgp/configuration/announce/vpls.py +++ b/src/exabgp/configuration/announce/vpls.py @@ -35,7 +35,7 @@ from exabgp.configuration.static.mpls import route_distinguisher -from exabgp.configuration.l2vpn.parser import vpls +# from exabgp.configuration.l2vpn.parser import vpls from exabgp.configuration.l2vpn.parser import vpls_endpoint from exabgp.configuration.l2vpn.parser import vpls_size from exabgp.configuration.l2vpn.parser import vpls_offset diff --git a/src/exabgp/configuration/flow/match.py b/src/exabgp/configuration/flow/match.py index c1ca3047b..1ba5cac5f 100644 --- a/src/exabgp/configuration/flow/match.py +++ b/src/exabgp/configuration/flow/match.py @@ -87,7 +87,6 @@ class ParseFlowMatch(Section): 'fragment': 'nlri-add', 'icmp-code': 'nlri-add', 'icmp-type': 'nlri-add', - 'packet-length': 'nlri-add', 'dscp': 'nlri-add', 'traffic-class': 'nlri-add', 'flow-label': 'nlri-add', diff --git a/src/exabgp/configuration/neighbor/__init__.py b/src/exabgp/configuration/neighbor/__init__.py index 08f3f684e..1329111b9 100644 --- a/src/exabgp/configuration/neighbor/__init__.py +++ b/src/exabgp/configuration/neighbor/__init__.py @@ -44,7 +44,6 @@ from exabgp.configuration.neighbor.parser import description from exabgp.configuration.neighbor.parser import inherit from exabgp.configuration.neighbor.parser import rate_limit -from exabgp.version import version from exabgp.environment import getenv diff --git a/src/exabgp/configuration/static/mpls.py b/src/exabgp/configuration/static/mpls.py index 4ae31d980..124ebfedf 100644 --- a/src/exabgp/configuration/static/mpls.py +++ b/src/exabgp/configuration/static/mpls.py @@ -198,7 +198,7 @@ def prefix_sid_srv6(tokeniser): def parse_ip_prefix(tokeninser): addrstr, length = tokeninser.split("/") - if length == None: + if length is None: raise Exception("unexpect prefix format '%s'" % tokeninser) if not length.isdigit(): diff --git a/src/exabgp/debug/__init__.py b/src/exabgp/debug/__init__.py deleted file mode 100644 index 6abb74202..000000000 --- a/src/exabgp/debug/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from exabgp.debug.report import string_exception -from exabgp.debug.report import format_exception -from exabgp.debug.report import format_panic -from exabgp.debug.intercept import trace_interceptor diff --git a/src/exabgp/debug/report.py b/src/exabgp/debug/report.py index 63f7d5edc..5a0d2ed65 100644 --- a/src/exabgp/debug/report.py +++ b/src/exabgp/debug/report.py @@ -16,8 +16,6 @@ from exabgp.environment import Env from exabgp.environment import ROOT - -from exabgp.logger import log from exabgp.logger import history diff --git a/src/exabgp/netlink/old.py b/src/exabgp/netlink/old.py index fced51be0..45bec185f 100755 --- a/src/exabgp/netlink/old.py +++ b/src/exabgp/netlink/old.py @@ -563,6 +563,7 @@ def newRoute(self): attributes, ) + _ = neighbor # prefix = '\20\x7f\0\0\2' for _ in self.extract(Network.Command.RTM_NEWROUTE, network_flags, family): diff --git a/src/exabgp/protocol/__init__.py b/src/exabgp/protocol/__init__.py index a04a3644d..b1703ab01 100644 --- a/src/exabgp/protocol/__init__.py +++ b/src/exabgp/protocol/__init__.py @@ -50,7 +50,7 @@ class Protocol(Resource): }.items() ) - names = dict([(r, l) for (l, r) in codes.items()]) + names = dict([(value, name) for (name, value) in codes.items()]) def pack(self): return bytes([self]) diff --git a/src/exabgp/protocol/family.py b/src/exabgp/protocol/family.py index 6f3c8b17e..7433e46d1 100644 --- a/src/exabgp/protocol/family.py +++ b/src/exabgp/protocol/family.py @@ -78,10 +78,10 @@ class AFI(Resource): }.items() ) - cache = dict([(r, r) for (l, r) in codes.items()]) - names = dict([(r, l) for (l, r) in codes.items()]) + cache = dict([(inst, inst) for (_, inst) in codes.items()]) + names = dict([(inst, name) for (name, inst) in codes.items()]) - inet_names = dict([(r, l.replace('ipv', 'inet')) for (l, r) in codes.items()]) + inet_names = dict([(inst, name.replace('ipv', 'inet')) for (name, inst) in codes.items()]) def name(self): return self.inet_names.get(self, "unknown afi") @@ -244,7 +244,7 @@ class SAFI(Resource): names = _SAFI._names - cache = dict([(r, r) for (l, r) in codes.items()]) + cache = dict([(inst, inst) for (_, inst) in codes.items()]) @staticmethod def unpack(data): diff --git a/src/exabgp/protocol/ip/fragment.py b/src/exabgp/protocol/ip/fragment.py index 4c307efde..33d3831bd 100644 --- a/src/exabgp/protocol/ip/fragment.py +++ b/src/exabgp/protocol/ip/fragment.py @@ -44,4 +44,4 @@ class Fragment(BitResource): }.items() ) - names = dict([(r, l) for (l, r) in codes.items()]) + names = dict([(value, name) for (name, value) in codes.items()]) diff --git a/src/exabgp/protocol/ip/icmp.py b/src/exabgp/protocol/ip/icmp.py index a3ed44a77..47b9ba4ff 100644 --- a/src/exabgp/protocol/ip/icmp.py +++ b/src/exabgp/protocol/ip/icmp.py @@ -56,7 +56,7 @@ class ICMPType(Resource): }.items() ) - names = dict([(r, l) for (l, r) in codes.items()]) + names = dict([(value, name) for (name, value) in codes.items()]) # https://www.iana.org/assignments/icmp-parameters diff --git a/src/exabgp/protocol/ip/netmask.py b/src/exabgp/protocol/ip/netmask.py index 873d2295d..f580860c2 100644 --- a/src/exabgp/protocol/ip/netmask.py +++ b/src/exabgp/protocol/ip/netmask.py @@ -65,7 +65,7 @@ def __str__(self): 0: '0.0.0.0', } - codes = dict([(r, l) for (l, r) in names.items()]) + codes = dict([(inst, name) for (name, inst) in names.items()]) @classmethod def create(cls, string, afi): diff --git a/src/exabgp/protocol/ip/port.py b/src/exabgp/protocol/ip/port.py index 173d7ad90..a4a8e9779 100644 --- a/src/exabgp/protocol/ip/port.py +++ b/src/exabgp/protocol/ip/port.py @@ -4954,7 +4954,7 @@ def name(self): 48556: 'com-bardac-dw', } - codes = dict([(r, l) for (l, r) in names.items()]) + codes = dict([(inst, name) for (name, inst) in names.items()]) # try: diff --git a/src/exabgp/protocol/ip/tcp/flag.py b/src/exabgp/protocol/ip/tcp/flag.py index 5ab518f09..4cab87799 100644 --- a/src/exabgp/protocol/ip/tcp/flag.py +++ b/src/exabgp/protocol/ip/tcp/flag.py @@ -42,7 +42,7 @@ class TCPFlag(BitResource): }.items() ) - names = dict([(r, l) for (l, r) in codes.items()]) + names = dict([(value, name) for (name, value) in codes.items()]) # Backward compatibility codes['urgent'] = URG diff --git a/src/exabgp/reactor/api/command/rib.py b/src/exabgp/reactor/api/command/rib.py index 7f8428bf7..cec5b1e89 100644 --- a/src/exabgp/reactor/api/command/rib.py +++ b/src/exabgp/reactor/api/command/rib.py @@ -92,7 +92,7 @@ def show_adj_rib(self, reactor, service, line, use_json): extensive = line.endswith(' extensive') try: rib = words[2] - if not rib in ('in', 'out'): + if rib not in ('in', 'out'): reactor.processes.answer_error(service) return False except IndexError: diff --git a/src/exabgp/reactor/api/response/json.py b/src/exabgp/reactor/api/response/json.py index f6f5d50f7..df11476e0 100755 --- a/src/exabgp/reactor/api/response/json.py +++ b/src/exabgp/reactor/api/response/json.py @@ -323,7 +323,7 @@ def _update(self, update): for nlri in update.nlris: try: nexthop = str(nlri.nexthop) - except: + except Exception: nexthop = 'null' if nlri.action == Action.ANNOUNCE: # pylint: disable=E1101 plus.setdefault(nlri.family().afi_safi(), {}).setdefault(nexthop, []).append(nlri) diff --git a/src/exabgp/reactor/loop.py b/src/exabgp/reactor/loop.py index 289e067e2..fef54c8d7 100644 --- a/src/exabgp/reactor/loop.py +++ b/src/exabgp/reactor/loop.py @@ -83,7 +83,7 @@ def _termination(self, reason, exit_code): def _prevent_spin(self): second = int(time.time()) - if not second in self._busyspin: + if second not in self._busyspin: self._busyspin = {second: 0} self._busyspin[second] += 1 if self._busyspin[second] > self.max_loop_time: @@ -96,7 +96,7 @@ def _rate_limited(self, peer, rate): return False second = int(time.time()) ratelimit = self._ratelimit.get(peer, {}) - if not second in ratelimit: + if second not in ratelimit: self._ratelimit[peer] = {second: rate - 1} return False if self._ratelimit[peer][second] > 0: @@ -524,9 +524,12 @@ def restart(self): """Kill the BGP session and restart it""" log.info('performing restart of exabgp %s' % version, 'reactor') - # XXX: FIXME: Could return False, in case there is interference with old config... reloaded = self.configuration.reload() + if not reloaded: + # XXX: FIXME: Could return False, in case there is interference with old config... + pass + for key in self._peers.keys(): if key not in self.configuration.neighbors.keys(): peer = self._peers[key] diff --git a/src/exabgp/reactor/network/outgoing.py b/src/exabgp/reactor/network/outgoing.py index b1873f43d..46fb8656e 100644 --- a/src/exabgp/reactor/network/outgoing.py +++ b/src/exabgp/reactor/network/outgoing.py @@ -11,7 +11,7 @@ from .tcp import TTLv6 from .tcp import asynchronous from .tcp import ready -from .error import NetworkError +# from .error import NetworkError from exabgp.logger import log diff --git a/src/exabgp/reactor/network/tcp.py b/src/exabgp/reactor/network/tcp.py index 4f9f9481d..565a73d29 100644 --- a/src/exabgp/reactor/network/tcp.py +++ b/src/exabgp/reactor/network/tcp.py @@ -29,8 +29,6 @@ from exabgp.reactor.network.error import TTLError from exabgp.reactor.network.error import AsyncError -from exabgp.logger import log - def create(afi, interface=None): try: diff --git a/src/exabgp/reactor/peer.py b/src/exabgp/reactor/peer.py index 587040e33..093c6302b 100644 --- a/src/exabgp/reactor/peer.py +++ b/src/exabgp/reactor/peer.py @@ -34,7 +34,7 @@ from exabgp.logger import logfunc from exabgp.logger import lazyformat -from exabgp.debug import format_exception +from exabgp.debug.report import format_exception class ACTION(object): diff --git a/src/exabgp/reactor/protocol.py b/src/exabgp/reactor/protocol.py index bc82b9805..3f4755fe1 100644 --- a/src/exabgp/reactor/protocol.py +++ b/src/exabgp/reactor/protocol.py @@ -40,7 +40,6 @@ from exabgp.bgp.message.update.attribute import Attribute from exabgp.protocol.ip import IP -from exabgp.reactor.api.processes import ProcessError from exabgp.logger import log diff --git a/src/exabgp/vendoring/gcdump.py b/src/exabgp/vendoring/gcdump.py index 098461238..e6638ada1 100644 --- a/src/exabgp/vendoring/gcdump.py +++ b/src/exabgp/vendoring/gcdump.py @@ -26,8 +26,8 @@ def dump(): lines, line_num = inspect.getsourcelines(type(x)) print(" line num:", line_num) - for l in lines: - print(" line:", l.rstrip("\n")) + for line in lines: + print(" line:", line.rstrip("\n")) except Exception: pass diff --git a/src/exabgp/vendoring/objgraph.py b/src/exabgp/vendoring/objgraph.py index fa93e3739..4b8ab34e7 100644 --- a/src/exabgp/vendoring/objgraph.py +++ b/src/exabgp/vendoring/objgraph.py @@ -844,7 +844,7 @@ def _quote(s): def _get_obj_type(obj): objtype = type(obj) - if type(obj) == InstanceType: + if type(obj) is InstanceType: objtype = obj.__class__ return objtype @@ -866,7 +866,7 @@ def _long_typename(obj): def _safe_repr(obj): try: return _short_repr(obj) - except: + except Exception: return '(unrepresentable)' diff --git a/src/exabgp/vendoring/profiler.py b/src/exabgp/vendoring/profiler.py index e2d0055f3..85ce79e3c 100644 --- a/src/exabgp/vendoring/profiler.py +++ b/src/exabgp/vendoring/profiler.py @@ -7,12 +7,15 @@ _CMD_USAGE = "python -m memory_profiler script_file.py" -import time, sys, os, pdb -import warnings -import linecache -import inspect -import subprocess -from copy import copy +import time # noqa: E402 +import sys # noqa: E402 +import os # noqa: E402 +import pdb # noqa: E402 +import warnings # noqa: E402 +import linecache # noqa: E402 +import inspect # noqa: E402 +import subprocess # noqa: E402 +from copy import copy # noqa: E402 # TODO: provide alternative when multprocessing is not available try: @@ -211,8 +214,6 @@ def add_function(self, func): # func_code does not exist in Python3 code = func.__code__ except AttributeError: - import warnings - warnings.warn("Could not extract a code object for the object %r" % (func,)) return if code not in self.code_map: @@ -368,16 +369,16 @@ def show_results(prof, stream=None, precision=3): mem_old = max(lines_normalized[first_line]) precision = int(precision) template_mem = '{{0:{0}.{1}'.format(precision + 6, precision) + 'f} MB' - for i, l in enumerate(linenos): + for idx, line in enumerate(linenos): mem = '' inc = '' - if l in lines_normalized: - mem = max(lines_normalized[l]) + if line in lines_normalized: + mem = max(lines_normalized[line]) inc = mem - mem_old mem_old = mem mem = template_mem.format(mem) inc = template_mem.format(inc) - stream.write(template.format(l, mem, inc, sub_lines[i])) + stream.write(template.format(line, mem, inc, sub_lines[idx])) stream.write('\n\n')