manhole

mautrix.util.manhole.compile_async(tree)
Parameters

tree (ast.AST) –

Return type

code

mautrix.util.manhole.insert_returns(body)
Parameters

body (List[ast.AST]) –

Return type

None

class mautrix.util.manhole.StatefulCommandCompiler

Bases: codeop.CommandCompiler

A command compiler that buffers input until a full command is available.

__init__()
Return type

None

buf: _io.BytesIO
is_partial_command()
Return type

bool

reset()
Return type

None

class mautrix.util.manhole.Interpreter

Bases: abc.ABC

abstract __init__(namespace, banner)
Parameters
  • namespace (Dict[str, Any]) –

  • banner (Union[bytes, str]) –

Return type

None

abstract close()
Return type

None

class mautrix.util.manhole.AsyncInterpreter

Bases: mautrix.util.manhole.Interpreter

An interactive asynchronous interpreter.

reader: asyncio.streams.StreamReader
writer: asyncio.streams.StreamWriter
running: bool
__init__(namespace, banner)
Parameters
  • namespace (Dict[str, Any]) –

  • banner (Union[bytes, str]) –

Return type

None

namespace: Dict[str, Any]
banner: bytes
compiler: mautrix.util.manhole.StatefulCommandCompiler
async send_exception()

When an exception has occurred, write the traceback to the user.

Return type

None

async execute(codeobj)
Parameters

codeobj (code) –

Return type

Tuple[Any, str]

async handle_one_command()

Process a single command. May have many lines.

Return type

None

async run_command(codeobj)

Execute a compiled code object, and write the output back to the client.

Parameters

codeobj (code) –

Return type

None

async write_prompt()
Return type

None

async read_command()

Read a command from the user line by line.

Returns a code object suitable for execution.

Return type

Optional[code]

async send_output(value, stdout)

Write the output or value of the expression back to user.

>>> 5
5
>>> print('cash rules everything around me')
cash rules everything around me
Parameters
  • value (str) –

  • stdout (str) –

Return type

None

close()
Return type

None

class mautrix.util.manhole.InterpreterFactory

Bases: object

__init__(namespace, banner, interpreter_class, whitelist)
Parameters
Return type

None

namespace: Dict[str, Any]
banner: bytes
interpreter_class: Type[mautrix.util.manhole.Interpreter]
clients: List[mautrix.util.manhole.Interpreter]
whitelist: Set[int]
property conn_id: int
async mautrix.util.manhole.start_manhole(path, banner='', namespace=None, loop=None, whitelist=None)

Starts a manhole server on a given UNIX address.

Parameters
  • path (str) – The path to create the UNIX socket at.

  • banner (str) – The banner to show when clients connect.

  • namespace (Optional[Dict[str, Any]]) – The globals to provide to connected clients.

  • loop (Optional[asyncio.events.AbstractEventLoop]) – The asyncio event loop to use.

  • whitelist (Optional[Set[int]]) – List of user IDs to allow connecting.

Return type

Tuple[asyncio.events.AbstractServer, Callable[[], None]]