Skip to content

Commit 166c63d

Browse files
committed
Codestyle fixes
1 parent be5aadc commit 166c63d

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

src/ipping/__main__.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66

77
def main_udp(args: argparse.Namespace) -> None:
8-
coro = start_udp_client(args.host, args.port, count=args.count, payload_size=args.packetsize, wait=args.wait)
8+
coro = start_udp_client(
9+
args.host,
10+
args.port,
11+
count=args.count,
12+
payload_size=args.packetsize,
13+
wait=args.wait,
14+
)
915
loop = asyncio.get_event_loop()
1016
task = loop.create_task(coro)
1117
try:
@@ -23,17 +29,32 @@ def main() -> None:
2329
parser_udp_ping = subparsers.add_parser('udp')
2430
parser_udp_ping.add_argument('host')
2531
parser_udp_ping.add_argument('port', type=int)
26-
parser_udp_ping.add_argument('-c', '--count', type=int, default=-1,
27-
help='Stop after sending (and receiving) COUNT packets.'
28-
' If this option is not specified, ping will operate until interrupted.')
29-
parser_udp_ping.add_argument('-s', '--packetsize', type=int, default=48,
30-
help='Specify the number of data bytes to be sent.'
31-
' The default is 48, which translates into 64 UDP data bytes when combined'
32-
' with the 16 bytes of ping header data.')
33-
parser_udp_ping.add_argument('-i', '--wait', type=float, default=1.0,
34-
help='Wait WAIT seconds between sending each packet.'
35-
' The default is to wait for one second between each packet.'
36-
' The wait time may be fractional')
32+
parser_udp_ping.add_argument(
33+
'-c',
34+
'--count',
35+
type=int,
36+
default=-1,
37+
help='Stop after sending (and receiving) COUNT packets.'
38+
' If this option is not specified, ping will operate until interrupted.'
39+
)
40+
parser_udp_ping.add_argument(
41+
'-s',
42+
'--packetsize',
43+
type=int,
44+
default=48,
45+
help='Specify the number of data bytes to be sent.'
46+
' The default is 48, which translates into 64 UDP data bytes when combined'
47+
' with the 16 bytes of ping header data.'
48+
)
49+
parser_udp_ping.add_argument(
50+
'-i',
51+
'--wait',
52+
type=float,
53+
default=1.0,
54+
help='Wait WAIT seconds between sending each packet.'
55+
' The default is to wait for one second between each packet.'
56+
' The wait time may be fractional'
57+
)
3758
parser_udp_ping.set_defaults(func=main_udp)
3859

3960
args = parser.parse_args()

src/ipping/udp.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def __init__(
2222
self.on_connection_lost = on_connection_lost
2323
self.on_error_received = on_error_received
2424

25-
self.expected_packets: WeakValueDictionary[Tuple[int, int],
26-
'asyncio.Future[Tuple[int, Addr]]'] = WeakValueDictionary()
25+
self.expected_packets: WeakValueDictionary[
26+
Tuple[int, int], 'asyncio.Future[Tuple[int, Addr]]'
27+
] = WeakValueDictionary()
2728

2829
self.transport: asyncio.DatagramTransport = None # type: ignore
2930

@@ -69,7 +70,7 @@ def __init__(
6970
self.transport: asyncio.DatagramTransport = None # type: ignore
7071
self.protocol: UDPPingClientProtocol = None # type: ignore
7172

72-
self.client_id = random.randint(0, 2**64-1)
73+
self.client_id = random.randint(0, 2**64 - 1)
7374
self.packet_counter = 0
7475

7576
self.loop = loop
@@ -105,7 +106,9 @@ async def ping_request(self) -> Tuple[int, int, Addr]:
105106
self.packet_counter += 1
106107
response_future = loop.create_future()
107108

108-
self.protocol.ping_request(self.client_id, packet_id, self.payload_size, response_future)
109+
self.protocol.ping_request(
110+
self.client_id, packet_id, self.payload_size, response_future
111+
)
109112

110113
timestamp0 = time.perf_counter_ns()
111114
res = await response_future

0 commit comments

Comments
 (0)