Skip to content

Commit

Permalink
format with ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Oct 20, 2024
1 parent 59443f4 commit 82ac7f1
Show file tree
Hide file tree
Showing 155 changed files with 803 additions and 768 deletions.
5 changes: 2 additions & 3 deletions src/exabgp/application/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"""exabgp command line interface"""


import os
import sys
import time
Expand Down Expand Up @@ -126,7 +125,7 @@ def cmdline(cmdarg):

pipes = named_pipe(ROOT, pipename)
if len(pipes) != 1:
sys.stdout.write('could not find ExaBGP\'s named pipes (%s.in and %s.out) for the cli\n' % (pipename, pipename))
sys.stdout.write("could not find ExaBGP's named pipes (%s.in and %s.out) for the cli\n" % (pipename, pipename))
sys.stdout.write('we scanned the following folders (the number is your PID):\n - ')
sys.stdout.write('\n - '.join(pipes))
sys.stdout.flush()
Expand Down Expand Up @@ -314,7 +313,7 @@ def cmdline(cmdarg):
break
if string == Answer.text_error or string == Answer.json_error:
done = True
sys.stderr.write('ExaBGP returns an error (see ExaBGP\'s logs for more information)\n')
sys.stderr.write("ExaBGP returns an error (see ExaBGP's logs for more information)\n")
sys.stderr.write('use help for a list of available commands\n')
sys.stderr.flush()
break
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/application/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def cmdline(cmdarg):
sys.stdout.write(' 001E:02:0000:0007:900F:0003:0001:01\n')
sys.stdout.write(' FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF001E0200000007900F0003000101\n')
sys.stdout.write(' FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:001E:02:0000:0007:900F:0003:0001:01\n')
sys.stdout.write(" FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 001E02 00000007900F0003000101\n")
sys.stdout.write(' FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 001E02 00000007900F0003000101\n')
sys.stdout.flush()
sys.exit(1)

Expand Down
202 changes: 101 additions & 101 deletions src/exabgp/application/healthcheck.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/exabgp/application/netlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def addresses():
hwaddr = '<no addr>'
if Address.Type.Attribute.IFLA_ADDRESS in ifi.attributes:
hwaddr = ':'.join(x.encode('hex') for x in ifi.attributes[Address.Type.Attribute.IFLA_ADDRESS])
print("%d: %s %s" % (ifi.index, ifi.attributes[Address.Type.Attribute.IFLA_IFNAME][:-1], hwaddr))
print('%d: %s %s' % (ifi.index, ifi.attributes[Address.Type.Attribute.IFLA_IFNAME][:-1], hwaddr))

for ifa in addrs.get(ifi.index, {}):
address = ifa.attributes.get(Attributes.Type.IFA_ADDRESS)
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/application/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def main(location=''):
if not location:
location = os.environ.get('exabgp_cli_pipe', '')
if not location:
sys.stderr.write("usage %s %s\n" % (sys.executable, ' '.join(sys.argv)))
sys.stderr.write('usage %s %s\n' % (sys.executable, ' '.join(sys.argv)))
sys.stderr.write("run with 'env exabgp_cli_pipe=<location>' if you are trying to mess with ExaBGP's internals")
sys.stderr.flush()
sys.exit(1)
Expand Down
11 changes: 5 additions & 6 deletions src/exabgp/application/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"""exabgp server"""


import os
import sys
import time
Expand Down Expand Up @@ -212,7 +211,7 @@ def run(comment, configurations, pid=0):
__exit(env.debug.memory, exit_code)

if pid:
profile_name = "%s-pid-%d" % (env.profile.file, pid)
profile_name = '%s-pid-%d' % (env.profile.file, pid)
else:
profile_name = env.profile.file

Expand Down Expand Up @@ -243,14 +242,14 @@ def run(comment, configurations, pid=0):
kprofile.output(write)
except IOError:
notice = 'could not save profiling in formation at: ' + destination
log.debug("-" * len(notice), 'reactor')
log.debug('-' * len(notice), 'reactor')
log.debug(notice, 'reactor')
log.debug("-" * len(notice), 'reactor')
log.debug('-' * len(notice), 'reactor')
__exit(env.debug.memory, exit_code)
else:
log.debug("-" * len(notice), 'reactor')
log.debug('-' * len(notice), 'reactor')
log.debug(notice, 'reactor')
log.debug("-" * len(notice), 'reactor')
log.debug('-' * len(notice), 'reactor')
Reactor(configuration).run()
__exit(env.debug.memory, 1)

Expand Down
1 change: 0 additions & 1 deletion src/exabgp/application/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"""exabgp configuration validation"""


import sys
import argparse

Expand Down
1 change: 1 addition & 0 deletions src/exabgp/application/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from exabgp.version import version, get_root


def setargs(sub):
# fmt:off
pass
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/bgp/message/keepalive.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def message(self, negotiated=None):
return self._message(b'')

def __str__(self):
return "KEEPALIVE"
return 'KEEPALIVE'

@classmethod
def unpack_message(cls, data, direction, negotiated): # pylint: disable=W0613
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/bgp/message/nop.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def message(self, negotiated=None):
raise RuntimeError('NOP messages can not be sent on the wire')

def __str__(self):
return "NOP"
return 'NOP'

@classmethod
def unpack_message(cls, data, direction, negotiated): # pylint: disable=W0613
Expand Down
110 changes: 55 additions & 55 deletions src/exabgp/bgp/message/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,63 @@ class Notification(Message):
TYPE = bytes([Message.CODE.NOTIFICATION])

_str_code = {
1: "Message header error",
2: "OPEN message error",
3: "UPDATE message error",
4: "Hold timer expired",
5: "State machine error",
6: "Cease",
1: 'Message header error',
2: 'OPEN message error',
3: 'UPDATE message error',
4: 'Hold timer expired',
5: 'State machine error',
6: 'Cease',
}

_str_subcode = {
(1, 0): "Unspecific",
(1, 1): "Connection Not Synchronized",
(1, 2): "Bad Message Length",
(1, 3): "Bad Message Type",
(2, 0): "Unspecific",
(2, 1): "Unsupported Version Number",
(2, 2): "Bad Peer AS",
(2, 3): "Bad BGP Identifier",
(2, 4): "Unsupported Optional Parameter",
(2, 5): "Authentication Notification (Deprecated)",
(2, 6): "Unacceptable Hold Time",
(1, 0): 'Unspecific',
(1, 1): 'Connection Not Synchronized',
(1, 2): 'Bad Message Length',
(1, 3): 'Bad Message Type',
(2, 0): 'Unspecific',
(2, 1): 'Unsupported Version Number',
(2, 2): 'Bad Peer AS',
(2, 3): 'Bad BGP Identifier',
(2, 4): 'Unsupported Optional Parameter',
(2, 5): 'Authentication Notification (Deprecated)',
(2, 6): 'Unacceptable Hold Time',
# RFC 5492 - https://tools.ietf.org/html/rfc5492
(2, 7): "Unsupported Capability",
(2, 7): 'Unsupported Capability',
# draft-ietf-idr-bgp-multisession-06
(2, 8): "Grouping Conflict",
(2, 9): "Grouping Required",
(2, 10): "Capability Value Mismatch",
(3, 0): "Unspecific",
(3, 1): "Malformed Attribute List",
(3, 2): "Unrecognized Well-known Attribute",
(3, 3): "Missing Well-known Attribute",
(3, 4): "Attribute Flags Error",
(3, 5): "Attribute Length Error",
(3, 6): "Invalid ORIGIN Attribute",
(3, 7): "AS Routing Loop",
(3, 8): "Invalid NEXT_HOP Attribute",
(3, 9): "Optional Attribute Error",
(3, 10): "Invalid Network Field",
(3, 11): "Malformed AS_PATH",
(4, 0): "Unspecific",
(5, 0): "Unspecific",
(2, 8): 'Grouping Conflict',
(2, 9): 'Grouping Required',
(2, 10): 'Capability Value Mismatch',
(3, 0): 'Unspecific',
(3, 1): 'Malformed Attribute List',
(3, 2): 'Unrecognized Well-known Attribute',
(3, 3): 'Missing Well-known Attribute',
(3, 4): 'Attribute Flags Error',
(3, 5): 'Attribute Length Error',
(3, 6): 'Invalid ORIGIN Attribute',
(3, 7): 'AS Routing Loop',
(3, 8): 'Invalid NEXT_HOP Attribute',
(3, 9): 'Optional Attribute Error',
(3, 10): 'Invalid Network Field',
(3, 11): 'Malformed AS_PATH',
(4, 0): 'Unspecific',
(5, 0): 'Unspecific',
# RFC 6608 - https://tools.ietf.org/html/rfc6608
(5, 1): "Receive Unexpected Message in OpenSent State",
(5, 2): "Receive Unexpected Message in OpenConfirm State",
(5, 3): "Receive Unexpected Message in Established State",
(6, 0): "Unspecific",
(5, 1): 'Receive Unexpected Message in OpenSent State',
(5, 2): 'Receive Unexpected Message in OpenConfirm State',
(5, 3): 'Receive Unexpected Message in Established State',
(6, 0): 'Unspecific',
# RFC 4486 - https://tools.ietf.org/html/rfc4486
(6, 1): "Maximum Number of Prefixes Reached",
(6, 2): "Administrative Shutdown", # augmented with draft-ietf-idr-shutdown
(6, 3): "Peer De-configured",
(6, 4): "Administrative Reset",
(6, 5): "Connection Rejected",
(6, 6): "Other Configuration Change",
(6, 7): "Connection Collision Resolution",
(6, 8): "Out of Resources",
(6, 1): 'Maximum Number of Prefixes Reached',
(6, 2): 'Administrative Shutdown', # augmented with draft-ietf-idr-shutdown
(6, 3): 'Peer De-configured',
(6, 4): 'Administrative Reset',
(6, 5): 'Connection Rejected',
(6, 6): 'Other Configuration Change',
(6, 7): 'Connection Collision Resolution',
(6, 8): 'Out of Resources',
# draft-keyur-bgp-enhanced-route-refresh-00
(7, 1): "Invalid Message Length",
(7, 2): "Malformed Message Subtype",
(7, 1): 'Invalid Message Length',
(7, 2): 'Malformed Message Subtype',
}

def __init__(self, code, subcode, data=b'', parse_data=True):
Expand All @@ -114,19 +114,19 @@ def __init__(self, code, subcode, data=b'', parse_data=True):
data = data[1:]

if shutdown_length == 0:
self.data = b"empty Shutdown Communication."
self.data = b'empty Shutdown Communication.'
# move offset past length field
return

if len(data) < shutdown_length:
self.data = b"invalid Shutdown Communication (buffer underrun) length : %i [%s]" % (
self.data = b'invalid Shutdown Communication (buffer underrun) length : %i [%s]' % (
shutdown_length,
hexstring(data),
)
return

if shutdown_length > 128:
self.data = b"invalid Shutdown Communication (too large) length : %i [%s]" % (
self.data = b'invalid Shutdown Communication (too large) length : %i [%s]' % (
shutdown_length,
hexstring(data),
)
Expand All @@ -137,18 +137,18 @@ def __init__(self, code, subcode, data=b'', parse_data=True):
'\r', ' '
).replace('\n', ' ')
except UnicodeDecodeError:
self.data = b"invalid Shutdown Communication (invalid UTF-8) length : %i [%s]" % (
self.data = b'invalid Shutdown Communication (invalid UTF-8) length : %i [%s]' % (
shutdown_length,
hexstring(data),
)
return

trailer = data[shutdown_length:]
if trailer:
self.data += b", trailing data: " + hexstring(trailer)
self.data += b', trailing data: ' + hexstring(trailer)

def __str__(self):
return "%s / %s%s" % (
return '%s / %s%s' % (
self._str_code.get(self.code, 'unknown error'),
self._str_subcode.get((self.code, self.subcode), 'unknow reason'),
' / %s' % self.data.decode('ascii') if self.data else '',
Expand Down
4 changes: 2 additions & 2 deletions src/exabgp/bgp/message/open/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def message(self, negotiated=None):
)

def __str__(self):
return "OPEN version=%d asn=%d hold_time=%s router_id=%s capabilities=[%s]" % (
return 'OPEN version=%d asn=%d hold_time=%s router_id=%s capabilities=[%s]' % (
self.version,
self.asn.trans(),
self.hold_time,
Expand All @@ -90,5 +90,5 @@ def unpack_message(cls, data, direction=None, negotiated=None):
asn = unpack('!H', data[1:3])[0]
hold_time = unpack('!H', data[3:5])[0]
numeric = unpack('!L', data[5:9])[0]
router_id = "%d.%d.%d.%d" % (numeric >> 24, (numeric >> 16) & 0xFF, (numeric >> 8) & 0xFF, numeric & 0xFF)
router_id = '%d.%d.%d.%d' % (numeric >> 24, (numeric >> 16) & 0xFF, (numeric >> 8) & 0xFF, numeric & 0xFF)
return cls(Version(version), ASN(asn), HoldTime(hold_time), RouterID(router_id), Capabilities.unpack(data[9:]))
2 changes: 1 addition & 1 deletion src/exabgp/bgp/message/open/capability/addpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __str__(self):
'AddPath('
+ ','.join(
[
"%s %s %s" % (self.string[self[aafi]], xafi, xsafi)
'%s %s %s' % (self.string[self[aafi]], xafi, xsafi)
for (aafi, xafi, xsafi) in [((afi, safi), str(afi), str(safi)) for (afi, safi) in self]
]
)
Expand Down
12 changes: 6 additions & 6 deletions src/exabgp/bgp/message/open/capability/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class Parameter(int):

def __str__(self):
if self == 0x01:
return "AUTHENTIFICATION INFORMATION"
return 'AUTHENTIFICATION INFORMATION'
if self == 0x02:
return "OPTIONAL"
return 'OPTIONAL'
return 'UNKNOWN'


Expand Down Expand Up @@ -204,13 +204,13 @@ def pack(self):
def unpack(data):
def _extended_type_length(name, data):
if len(data) < 3:
raise Notify(2, 0, "Bad length for OPEN (extended) %s (<3) %s" % (name, Capability.hex(data)))
raise Notify(2, 0, 'Bad length for OPEN (extended) %s (<3) %s' % (name, Capability.hex(data)))
# Optional parameters length
ld = unpack('!H', data[1:3])[0]
boundary = ld + 3
if len(data) < boundary:
raise Notify(
2, 0, "Bad length for OPEN (extended) %s (buffer underrun) %s" % (name, Capability.hex(data))
2, 0, 'Bad length for OPEN (extended) %s (buffer underrun) %s' % (name, Capability.hex(data))
)
key = data[0]
value = data[3:boundary]
Expand All @@ -219,11 +219,11 @@ def _extended_type_length(name, data):

def _key_values(name, data):
if len(data) < 2:
raise Notify(2, 0, "Bad length for OPEN %s (<2) %s" % (name, Capability.hex(data)))
raise Notify(2, 0, 'Bad length for OPEN %s (<2) %s' % (name, Capability.hex(data)))
ld = data[1]
boundary = ld + 2
if len(data) < boundary:
raise Notify(2, 0, "Bad length for OPEN %s (buffer underrun) %s" % (name, Capability.hex(data)))
raise Notify(2, 0, 'Bad length for OPEN %s (buffer underrun) %s' % (name, Capability.hex(data)))
key = data[0]
value = data[2:boundary]
rest = data[boundary:]
Expand Down
4 changes: 2 additions & 2 deletions src/exabgp/bgp/message/open/capability/graceful.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def extract(self):

def __str__(self):
families = [(str(afi), str(safi), hex(self[(afi, safi)])) for (afi, safi) in self.keys()]
sfamilies = ' '.join(["%s/%s=%s" % (afi, safi, family) for (afi, safi, family) in families])
return "Graceful Restart Flags %s Time %d %s" % (hex(self.restart_flag), self.restart_time, sfamilies)
sfamilies = ' '.join(['%s/%s=%s' % (afi, safi, family) for (afi, safi, family) in families])
return 'Graceful Restart Flags %s Time %d %s' % (hex(self.restart_flag), self.restart_time, sfamilies)

def json(self):
d = {
Expand Down
1 change: 0 additions & 1 deletion src/exabgp/bgp/message/open/capability/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

# https://datatracker.ietf.org/doc/html/draft-walton-bgp-hostname-capability-02


from exabgp.bgp.message.open.capability.capability import Capability
from exabgp.util.dns import host, domain

Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/bgp/message/open/capability/mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MultiProtocol(Capability, list):
ID = Capability.CODE.MULTIPROTOCOL

def __str__(self):
return 'Multiprotocol(' + ','.join(["%s %s" % (str(afi), str(safi)) for (afi, safi) in self]) + ')'
return 'Multiprotocol(' + ','.join(['%s %s' % (str(afi), str(safi)) for (afi, safi) in self]) + ')'

def json(self):
return '{ "name": "multiprotocol", "families": [%s ] }' % ','.join(
Expand Down
4 changes: 2 additions & 2 deletions src/exabgp/bgp/message/open/capability/nexthop.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def add_nexthop(self, afi, safi, nhafi):

def __str__(self):
return (
'NextHop(' + ','.join(["%s %s %s" % (str(afi), str(safi), str(nhafi)) for (afi, safi, nhafi) in self]) + ')'
'NextHop(' + ','.join(['%s %s %s' % (str(afi), str(safi), str(nhafi)) for (afi, safi, nhafi) in self]) + ')'
)

def json(self):
Expand All @@ -42,7 +42,7 @@ def json(self):
def extract(self):
rs = b''
for afi, safi, nhafi in self:
rs += afi.pack() + pack("!B", 0) + safi.pack() + nhafi.pack()
rs += afi.pack() + pack('!B', 0) + safi.pack() + nhafi.pack()
return [
rs,
]
Expand Down
Loading

0 comments on commit 82ac7f1

Please sign in to comment.