Skip to content

Commit

Permalink
silence ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Oct 20, 2024
1 parent 0ac000a commit ff87e72
Show file tree
Hide file tree
Showing 59 changed files with 99 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/exabgp/application/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/exabgp/application/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
],
[],
)
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/application/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/application/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/exabgp/application/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"""exabgp current version"""

import os
import sys
import argparse
import platform
Expand Down
2 changes: 0 additions & 2 deletions src/exabgp/bgp/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/bgp/message/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/exabgp/bgp/message/open/asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from struct import pack
from struct import unpack
import sys

from exabgp.protocol.resource import Resource

Expand Down
1 change: 0 additions & 1 deletion src/exabgp/bgp/message/open/capability/extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/exabgp/bgp/message/open/capability/negotiated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/exabgp/bgp/message/update/attribute/bgpls/node/srcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions src/exabgp/bgp/message/update/attribute/community/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/exabgp/bgp/message/update/nlri/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 1 addition & 2 deletions src/exabgp/bgp/message/update/nlri/mup/dsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


# +-----------------------------------+
Expand Down Expand Up @@ -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])

Expand Down
1 change: 0 additions & 1 deletion src/exabgp/bgp/message/update/nlri/mup/nlri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/exabgp/bgp/message/update/nlri/mvpn/sharedjoin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/exabgp/bgp/message/update/nlri/mvpn/sourcead.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/exabgp/bgp/message/update/nlri/mvpn/sourcejoin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/exabgp/bgp/message/update/nlri/qualifier/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ 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 ''

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]))
Expand All @@ -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:
Expand Down
32 changes: 16 additions & 16 deletions src/exabgp/bgp/neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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()
),
}

Expand Down
2 changes: 0 additions & 2 deletions src/exabgp/cli/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import sys
import argparse
import os

from vyos.xml import kw
from vyos.util import call
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/cli/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/exabgp/conf/yang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit ff87e72

Please sign in to comment.