summaryrefslogtreecommitdiffstats
path: root/examples/ssh-and-telnet-embed.py
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2023-12-17 10:46:40 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2023-12-17 10:46:40 +0000
commit4e61276ae3a4432a9d7a65dd49eb6ae71dd5f93a (patch)
tree57f9ac8ea7edafc3db4db312b8a369ab39711636 /examples/ssh-and-telnet-embed.py
parentAdding upstream version 3.0.23. (diff)
downloadptpython-4e61276ae3a4432a9d7a65dd49eb6ae71dd5f93a.tar.xz
ptpython-4e61276ae3a4432a9d7a65dd49eb6ae71dd5f93a.zip
Adding upstream version 3.0.25.upstream/3.0.25
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'examples/ssh-and-telnet-embed.py')
-rwxr-xr-xexamples/ssh-and-telnet-embed.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/examples/ssh-and-telnet-embed.py b/examples/ssh-and-telnet-embed.py
index 378784c..62fa76d 100755
--- a/examples/ssh-and-telnet-embed.py
+++ b/examples/ssh-and-telnet-embed.py
@@ -11,13 +11,16 @@ import pathlib
import asyncssh
from prompt_toolkit import print_formatted_text
-from prompt_toolkit.contrib.ssh.server import PromptToolkitSSHServer
+from prompt_toolkit.contrib.ssh.server import (
+ PromptToolkitSSHServer,
+ PromptToolkitSSHSession,
+)
from prompt_toolkit.contrib.telnet.server import TelnetServer
from ptpython.repl import embed
-def ensure_key(filename="ssh_host_key"):
+def ensure_key(filename: str = "ssh_host_key") -> str:
path = pathlib.Path(filename)
if not path.exists():
rsa_key = asyncssh.generate_private_key("ssh-rsa")
@@ -25,12 +28,12 @@ def ensure_key(filename="ssh_host_key"):
return str(path)
-async def interact(connection=None):
+async def interact(connection: PromptToolkitSSHSession) -> None:
global_dict = {**globals(), "print": print_formatted_text}
await embed(return_asyncio_coroutine=True, globals=global_dict)
-async def main(ssh_port=8022, telnet_port=8023):
+async def main(ssh_port: int = 8022, telnet_port: int = 8023) -> None:
ssh_server = PromptToolkitSSHServer(interact=interact)
await asyncssh.create_server(
lambda: ssh_server, "", ssh_port, server_host_keys=[ensure_key()]