Skip to content

Commit

Permalink
Update examples to python 3.7 and add some other minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ronf committed Aug 24, 2024
1 parent 17b02ff commit e41e05c
Show file tree
Hide file tree
Showing 41 changed files with 134 additions and 125 deletions.
6 changes: 3 additions & 3 deletions examples/callback_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -46,6 +46,6 @@ async def run_client() -> None:
await chan.wait_closed()

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/callback_client2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -37,6 +37,6 @@ async def run_client() -> None:
await chan.wait_closed()

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/callback_client3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -40,6 +40,6 @@ async def run_client() -> None:
await chan.wait_closed()

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
9 changes: 6 additions & 3 deletions examples/callback_math_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -64,6 +64,9 @@ def eof_received(self) -> bool:
def break_received(self, msec: int) -> bool:
return self.eof_received()

def soft_eof_received(self) -> None:
self.eof_received()

class MySSHServer(asyncssh.SSHServer):
def session_requested(self) -> asyncssh.SSHServerSession:
return MySSHServerSession()
Expand All @@ -73,7 +76,7 @@ async def start_server() -> None:
server_host_keys=['ssh_host_key'],
authorized_client_keys='ssh_user_ca')

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/chat_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2016-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2016-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -76,7 +76,7 @@ async def start_server() -> None:
authorized_client_keys='ssh_user_ca',
process_factory=ChatClient.handle_client)

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/check_exit_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -34,6 +34,6 @@ async def run_client() -> None:
file=sys.stderr)

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/chroot_sftp_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2016-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2016-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -40,7 +40,7 @@ async def start_server() -> None:
authorized_client_keys='ssh_user_ca',
sftp_factory=MySFTPServer)

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/direct_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -44,6 +44,6 @@ async def run_client() -> None:
await chan.wait_closed()

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/direct_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -52,7 +52,7 @@ async def start_server() -> None:
server_host_keys=['ssh_host_key'],
authorized_client_keys='ssh_user_ca')

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -53,7 +53,7 @@ async def start_server() -> None:
authorized_client_keys='ssh_user_ca',
process_factory=handle_client)

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/gather_results.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2016-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2016-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -45,4 +45,4 @@ async def run_multiple_clients() -> None:

print(75*'-')

asyncio.get_event_loop().run_until_complete(run_multiple_clients())
asyncio.run(run_multiple_clients())
6 changes: 3 additions & 3 deletions examples/listening_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -45,6 +45,6 @@ async def run_client() -> None:
print('Listener couldn\'t be opened.', file=sys.stderr)

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/local_forwarding_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -28,6 +28,6 @@ async def run_client() -> None:
await listener.wait_closed()

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/local_forwarding_client2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -29,6 +29,6 @@ async def run_client() -> None:
await listener.wait_closed()

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/local_forwarding_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -44,7 +44,7 @@ async def start_server() -> None:
server_host_keys=['ssh_host_key'],
authorized_client_keys='ssh_user_ca')

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/math_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2016-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2016-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -31,6 +31,6 @@ async def run_client() -> None:
print(op, '=', result, end='')

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/math_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -53,7 +53,7 @@ async def start_server() -> None:
authorized_client_keys='ssh_user_ca',
process_factory=handle_client)

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/redirect_input.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand All @@ -27,6 +27,6 @@ async def run_client() -> None:
await conn.run('tail -r', input='1\n2\n3\n', stdout='/tmp/stdout')

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/redirect_local_pipe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -30,6 +30,6 @@ async def run_client() -> None:
print(remote_result.stdout, end='')

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/redirect_remote_pipe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -29,6 +29,6 @@ async def run_client() -> None:
print(proc2_result.stdout, end='')

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
6 changes: 3 additions & 3 deletions examples/redirect_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2017-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2017-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -43,7 +43,7 @@ async def start_server() -> None:
authorized_client_keys='ssh_user_ca',
process_factory=handle_client)

loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()

try:
loop.run_until_complete(start_server())
Expand Down
6 changes: 3 additions & 3 deletions examples/remote_forwarding_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3.7
#
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others.
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
Expand Down Expand Up @@ -28,6 +28,6 @@ async def run_client() -> None:
await listener.wait_closed()

try:
asyncio.get_event_loop().run_until_complete(run_client())
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
Loading

0 comments on commit e41e05c

Please sign in to comment.