Skip to content

Commit 55e4ce4

Browse files
bluetechKriechi
authored andcommitted
Run pyupgrade --py36-plus
1 parent 7f8b000 commit 55e4ce4

16 files changed

+35
-54
lines changed

compliance/run-autobahn-tests.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"servers": [
2121
{
2222
"agent": "wsproto",
23-
"url": "ws://localhost:{}".format(PORT),
23+
"url": f"ws://localhost:{PORT}",
2424
"options": {"version": 18},
2525
}
2626
],
@@ -30,7 +30,7 @@
3030
}
3131

3232
SERVER_CONFIG = {
33-
"url": "ws://localhost:{}".format(PORT),
33+
"url": f"ws://localhost:{PORT}",
3434
"options": {"failByDrop": False},
3535
"outdir": "./reports/clients",
3636
"webport": 8080,
@@ -43,7 +43,7 @@
4343
"all": ["*"],
4444
"fast": [
4545
# The core functionality tests
46-
*["{}.*".format(i) for i in range(1, 12)],
46+
*[f"{i}.*" for i in range(1, 12)],
4747
# Compression tests -- in each section, the tests get progressively
4848
# slower until they're taking 10s of seconds apiece. And it's
4949
# mostly stress tests, without much extra coverage to show for
@@ -82,7 +82,7 @@ def wait_for_listener(port: int) -> None:
8282
sock = socket.socket()
8383
try:
8484
sock.connect(("localhost", port))
85-
except socket.error as exc:
85+
except OSError as exc:
8686
if exc.errno == errno.ECONNREFUSED:
8787
time.sleep(0.01)
8888
else:
@@ -240,9 +240,7 @@ def main() -> None:
240240
say("Unrecognized mode, try 'client' or 'server'")
241241
sys.exit(2)
242242

243-
say(
244-
"in {} mode: failed {} out of {} total".format(args.MODE.upper(), failed, total)
245-
)
243+
say(f"in {args.MODE.upper()} mode: failed {failed} out of {total} total")
246244

247245
if failed:
248246
say("Test failed")

compliance/test_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def run_case(server: str, case: int, agent: str) -> None:
6363
connection.send(
6464
Request(
6565
host=uri.netloc,
66-
target="%s?%s" % (uri.path, uri.query),
66+
target=f"{uri.path}?{uri.query}",
6767
extensions=[PerMessageDeflate()],
6868
)
6969
)
@@ -105,9 +105,7 @@ def update_reports(server: str, agent: str) -> None:
105105
sock.connect((uri.hostname, uri.port or 80))
106106

107107
sock.sendall(
108-
connection.send(
109-
Request(host=uri.netloc, target="%s?%s" % (uri.path, uri.query))
110-
)
108+
connection.send(Request(host=uri.netloc, target=f"{uri.path}?{uri.query}"))
111109
)
112110
closed = False
113111

compliance/test_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
def new_conn(sock: socket.socket) -> None:
1414
global count
15-
print("test_server.py received connection {}".format(count))
15+
print(f"test_server.py received connection {count}")
1616
count += 1
1717
ws = WSConnection(SERVER)
1818
closed = False
1919
while not closed:
2020
try:
2121
data: Optional[bytes] = sock.recv(65535)
22-
except socket.error:
22+
except OSError:
2323
data = None
2424

2525
ws.receive_data(data or None)
@@ -46,7 +46,7 @@ def new_conn(sock: socket.socket) -> None:
4646

4747
try:
4848
sock.sendall(outgoing_data)
49-
except socket.error:
49+
except OSError:
5050
closed = True
5151

5252
sock.close()

example/synchronous_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def wsproto_demo(host: str, port: int) -> None:
4949
"""
5050

5151
# 0) Open TCP connection
52-
print("Connecting to {}:{}".format(host, port))
52+
print(f"Connecting to {host}:{port}")
5353
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5454
conn.connect((host, port))
5555

@@ -64,14 +64,14 @@ def wsproto_demo(host: str, port: int) -> None:
6464

6565
# 2) Send a message and display response
6666
message = "wsproto is great"
67-
print("Sending message: {}".format(message))
67+
print(f"Sending message: {message}")
6868
net_send(ws.send(Message(data=message)), conn)
6969
net_recv(ws, conn)
7070
handle_events(ws)
7171

7272
# 3) Send ping and display pong
7373
payload = b"table tennis"
74-
print("Sending ping: {!r}".format(payload))
74+
print(f"Sending ping: {payload!r}")
7575
net_send(ws.send(Ping(payload=payload)), conn)
7676
net_recv(ws, conn)
7777
handle_events(ws)
@@ -111,9 +111,9 @@ def handle_events(ws: WSConnection) -> None:
111111
if isinstance(event, AcceptConnection):
112112
print("WebSocket negotiation complete")
113113
elif isinstance(event, TextMessage):
114-
print("Received message: {}".format(event.data))
114+
print(f"Received message: {event.data}")
115115
elif isinstance(event, Pong):
116-
print("Received pong: {!r}".format(event.payload))
116+
print(f"Received pong: {event.payload!r}")
117117
else:
118118
raise Exception("Do not know how to handle event: " + str(event))
119119

example/synchronous_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def handle_connection(stream: socket.socket) -> None:
9797
print("Received ping and sending pong")
9898
out_data += ws.send(event.response())
9999
else:
100-
print("Unknown event: {!r}".format(event))
100+
print(f"Unknown event: {event!r}")
101101

102102
# 4) Send data from wsproto to network
103103
print("Sending {} bytes".format(len(out_data)))

src/wsproto/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
wsproto
43
~~~~~~~
@@ -86,11 +85,9 @@ def events(self) -> Generator[Event, None, None]:
8685
Each event is an instance of a subclass of
8786
:class:`wsproto.events.Event`.
8887
"""
89-
for event in self.handshake.events():
90-
yield event
88+
yield from self.handshake.events()
9189
if self.connection is not None:
92-
for event in self.connection.events():
93-
yield event
90+
yield from self.connection.events()
9491

9592

9693
__all__ = ("ConnectionType", "WSConnection")

src/wsproto/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
wsproto/connection
43
~~~~~~~~~~~~~~~~~~
@@ -106,7 +105,7 @@ def send(self, event: Event) -> bytes:
106105
else:
107106
self._state = ConnectionState.LOCAL_CLOSING
108107
else:
109-
raise LocalProtocolError("Event {} cannot be sent.".format(event))
108+
raise LocalProtocolError(f"Event {event} cannot be sent.")
110109
return data
111110

112111
def receive_data(self, data: Optional[bytes]) -> None:

src/wsproto/events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
wsproto/events
43
~~~~~~~~~~~~~~

src/wsproto/extensions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
wsproto/extensions
43
~~~~~~~~~~~~~~~~~~
@@ -306,7 +305,7 @@ def __repr__(self) -> str:
306305
if self.server_no_context_takeover:
307306
descr.append("server_no_context_takeover")
308307

309-
return "<%s %s>" % (self.__class__.__name__, "; ".join(descr))
308+
return "<{} {}>".format(self.__class__.__name__, "; ".join(descr))
310309

311310

312311
#: SUPPORTED_EXTENSIONS maps all supported extension names to their class.

src/wsproto/frame_protocol.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
wsproto/frame_protocol
43
~~~~~~~~~~~~~~~~~~~~~~
@@ -410,7 +409,7 @@ def parse_header(self) -> bool:
410409
try:
411410
opcode = Opcode(opcode)
412411
except ValueError:
413-
raise ParseFailed("Invalid opcode {:#x}".format(opcode))
412+
raise ParseFailed(f"Invalid opcode {opcode:#x}")
414413

415414
if opcode.iscontrol() and not fin:
416415
raise ParseFailed("Invalid attempt to fragment control frame")

0 commit comments

Comments
 (0)