Skip to content

Commit 09e2fc5

Browse files
committed
Commit fixes recommended by pyupgrade tool
1 parent fa01aab commit 09e2fc5

16 files changed

+71
-71
lines changed

asyncssh/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async def _make_request(self, msgtype: int, *args: bytes) -> \
252252

253253
resplen = int.from_bytes((await reader.readexactly(4)), 'big')
254254

255-
resp = SSHPacket((await reader.readexactly(resplen)))
255+
resp = SSHPacket(await reader.readexactly(resplen))
256256
resptype = resp.get_byte()
257257

258258
return resptype, resp

asyncssh/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async def _start(self) -> None:
181181

182182
self._gss = self._conn.get_gss_context()
183183
self._gss.reset()
184-
mechs = b''.join((String(mech) for mech in self._gss.mechs))
184+
mechs = b''.join(String(mech) for mech in self._gss.mechs)
185185
await self.send_request(UInt32(len(self._gss.mechs)), mechs)
186186
else:
187187
self._conn.try_next_auth()

asyncssh/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ def get_port(self) -> int:
725725
if hasattr(self._server, 'get_port'):
726726
return self._server.get_port()
727727
else:
728-
ports = set(addr[1] for addr in self.get_addresses())
728+
ports = {addr[1] for addr in self.get_addresses()}
729729
return ports.pop() if len(ports) == 1 else 0
730730

731731
def close(self) -> None:

asyncssh/crypto/x509.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def _to_purpose_oids(purposes: _Purposes) -> _PurposeOIDs:
9494
if not purposes or 'any' in purposes or _purpose_any in purposes:
9595
purpose_oids = None
9696
else:
97-
purpose_oids = set(_purpose_to_oid.get(p) or x509.ObjectIdentifier(p)
98-
for p in purposes)
97+
purpose_oids = {_purpose_to_oid.get(p) or x509.ObjectIdentifier(p)
98+
for p in purposes}
9999

100100
return purpose_oids
101101

@@ -143,8 +143,8 @@ class X509Name(x509.Name):
143143
('CN', x509.NameOID.COMMON_NAME),
144144
('DC', x509.NameOID.DOMAIN_COMPONENT))
145145

146-
_to_oid = dict((k, v) for k, v in _attrs)
147-
_from_oid = dict((v, k) for k, v in _attrs)
146+
_to_oid = dict(_attrs)
147+
_from_oid = {v: k for k, v in _attrs}
148148

149149
def __init__(self, name: _NameInit):
150150
if isinstance(name, str):

asyncssh/known_hosts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def _match(self, host: str, addr: str,
208208
ip = None
209209

210210
if port:
211-
host = '[{}]:{}'.format(host, port) if host else ''
212-
addr = '[{}]:{}'.format(addr, port) if addr else ''
211+
host = f'[{host}]:{port}' if host else ''
212+
addr = f'[{addr}]:{port}' if addr else ''
213213

214214
matches = []
215215
matches += self._exact_entries.get(host, [])

asyncssh/public_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,8 +1941,8 @@ def validate_chain(self, trust_chain: Sequence['SSHX509Certificate'],
19411941
host_principal: str = '') -> None:
19421942
"""Validate an X.509 certificate chain"""
19431943

1944-
trust_store = set(c for c in trust_chain if c.subject != c.issuer) | \
1945-
set(c for c in trusted_certs)
1944+
trust_store = {c for c in trust_chain if c.subject != c.issuer} | \
1945+
set(trusted_certs)
19461946

19471947
if trusted_cert_paths:
19481948
self._expand_trust_store(self, trusted_cert_paths, trust_store)

asyncssh/sftp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ def _format(self, k: str, v: object) -> Optional[str]:
16281628
return _file_types.get(cast(int, v), str(v)) \
16291629
if v != FILEXFER_TYPE_UNKNOWN else None
16301630
elif k == 'permissions':
1631-
return '{:04o}'.format(cast(int, v))
1631+
return f'{cast(int, v):04o}'
16321632
elif k in ('atime', 'crtime', 'mtime', 'ctime'):
16331633
return self._format_ns(k)
16341634
elif k in ('atime_ns', 'crtime_ns', 'mtime_ns', 'ctime_ns'):

examples/simple_keyed_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def connection_made(self, conn: asyncssh.SSHServerConnection) -> None:
4242
def begin_auth(self, username: str) -> bool:
4343
try:
4444
self._conn.set_authorized_keys('authorized_keys/%s' % username)
45-
except IOError:
45+
except OSError:
4646
pass
4747

4848
return True

tests/test_channel.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ async def _begin_session(self, stdin, stdout, stderr):
271271
elif action == 'agent':
272272
try:
273273
async with asyncssh.connect_agent(self._conn) as agent:
274-
stdout.write(str(len((await agent.get_keys()))) + '\n')
274+
stdout.write(str(len(await agent.get_keys())) + '\n')
275275
except (OSError, asyncssh.ChannelOpenError):
276276
stdout.channel.exit(1)
277277
elif action == 'agent_sock':
@@ -280,7 +280,7 @@ async def _begin_session(self, stdin, stdout, stderr):
280280
if agent_path:
281281
async with asyncssh.connect_agent(agent_path) as agent:
282282
await asyncio.sleep(0.1)
283-
stdout.write(str(len((await agent.get_keys()))) + '\n')
283+
stdout.write(str(len(await agent.get_keys())) + '\n')
284284
else:
285285
stdout.channel.exit(1)
286286
elif action == 'rejected_agent':
@@ -428,11 +428,11 @@ async def _begin_session(self, stdin, stdout, stderr):
428428
elif action == 'empty_data':
429429
stdin.channel.send_packet(MSG_CHANNEL_DATA, String(''))
430430
elif action == 'partial_unicode':
431-
data = '\xff\xff'.encode('utf-8')
431+
data = '\xff\xff'.encode()
432432
stdin.channel.send_packet(MSG_CHANNEL_DATA, String(data[:3]))
433433
stdin.channel.send_packet(MSG_CHANNEL_DATA, String(data[3:]))
434434
elif action == 'partial_unicode_at_eof':
435-
data = '\xff\xff'.encode('utf-8')
435+
data = '\xff\xff'.encode()
436436
stdin.channel.send_packet(MSG_CHANNEL_DATA, String(data[:3]))
437437
elif action == 'unicode_error':
438438
stdin.channel.send_packet(MSG_CHANNEL_DATA, String(b'\xff'))
@@ -767,7 +767,7 @@ async def test_unknown_channel_request(self):
767767
async with self.connect() as conn:
768768
chan, _ = await _create_session(conn)
769769

770-
self.assertFalse((await chan.make_request('unknown')))
770+
self.assertFalse(await chan.make_request('unknown'))
771771

772772
@asynctest
773773
async def test_invalid_channel_request(self):

tests/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ async def test_import_known_hosts(self):
798798

799799
known_hosts_path = os.path.join('.ssh', 'known_hosts')
800800

801-
with open(known_hosts_path, 'r') as f:
801+
with open(known_hosts_path) as f:
802802
known_hosts = asyncssh.import_known_hosts(f.read())
803803

804804
async with self.connect(known_hosts=known_hosts):

0 commit comments

Comments
 (0)