1
0
Fork 0

Merging upstream version 3.0.25.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 18:31:41 +01:00
parent 8e41bc821f
commit 7159687519
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
26 changed files with 770 additions and 530 deletions

View file

@ -19,7 +19,7 @@ loop = asyncio.get_event_loop()
counter = [0]
async def print_counter():
async def print_counter() -> None:
"""
Coroutine that prints counters and saves it in a global variable.
"""
@ -29,7 +29,7 @@ async def print_counter():
await asyncio.sleep(3)
async def interactive_shell():
async def interactive_shell() -> None:
"""
Coroutine that starts a Python REPL from which we can access the global
counter variable.
@ -44,13 +44,10 @@ async def interactive_shell():
loop.stop()
def main():
asyncio.ensure_future(print_counter())
asyncio.ensure_future(interactive_shell())
loop.run_forever()
loop.close()
async def main() -> None:
asyncio.create_task(print_counter())
await interactive_shell()
if __name__ == "__main__":
main()
asyncio.run(main())

View file

@ -32,31 +32,25 @@ class MySSHServer(asyncssh.SSHServer):
return ReplSSHServerSession(self.get_namespace)
def main(port=8222):
async def main(port: int = 8222) -> None:
"""
Example that starts the REPL through an SSH server.
"""
loop = asyncio.get_event_loop()
# Namespace exposed in the REPL.
environ = {"hello": "world"}
# Start SSH server.
def create_server():
def create_server() -> MySSHServer:
return MySSHServer(lambda: environ)
print("Listening on :%i" % port)
print('To connect, do "ssh localhost -p %i"' % port)
loop.run_until_complete(
asyncssh.create_server(
create_server, "", port, server_host_keys=["/etc/ssh/ssh_host_dsa_key"]
)
await asyncssh.create_server(
create_server, "", port, server_host_keys=["/etc/ssh/ssh_host_dsa_key"]
)
# Run eventloop.
loop.run_forever()
await asyncio.Future() # Wait forever.
if __name__ == "__main__":
main()
asyncio.run(main())

View file

@ -70,6 +70,9 @@ def configure(repl):
# Vi mode.
repl.vi_mode = False
# Enable the modal cursor (when using Vi mode). Other options are 'Block', 'Underline', 'Beam', 'Blink under', 'Blink block', and 'Blink beam'
repl.cursor_shape_config = "Modal (vi)"
# Paste mode. (When True, don't insert whitespace after new line.)
repl.paste_mode = False

View file

@ -2,26 +2,26 @@
"""
Example of embedding a Python REPL, and setting a custom prompt.
"""
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.formatted_text import HTML, AnyFormattedText
from ptpython.prompt_style import PromptStyle
from ptpython.repl import embed
def configure(repl):
def configure(repl) -> None:
# Probably, the best is to add a new PromptStyle to `all_prompt_styles` and
# activate it. This way, the other styles are still selectable from the
# menu.
class CustomPrompt(PromptStyle):
def in_prompt(self):
def in_prompt(self) -> AnyFormattedText:
return HTML("<ansigreen>Input[%s]</ansigreen>: ") % (
repl.current_statement_index,
)
def in2_prompt(self, width):
def in2_prompt(self, width: int) -> AnyFormattedText:
return "...: ".rjust(width)
def out_prompt(self):
def out_prompt(self) -> AnyFormattedText:
return HTML("<ansired>Result[%s]</ansired>: ") % (
repl.current_statement_index,
)
@ -30,7 +30,7 @@ def configure(repl):
repl.prompt_style = "custom"
def main():
def main() -> None:
embed(globals(), locals(), configure=configure)

View file

@ -4,7 +4,7 @@
from ptpython.repl import embed
def main():
def main() -> None:
embed(globals(), locals(), vi_mode=False)

View file

@ -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()]