Protocol¶
- class rmote.protocol.Template(template)[source]¶
Bases:
objectA Mako-like template pre-compiled to a reusable render function.
Picklable - the instance stores only the original template string, so it can be passed as an argument to remote tool calls over the protocol. The class lives in
protocol.pyand is therefore available on the remote side without any extra sync step.Usage:
tmpl = Template("Hello, ${name}!") tmpl.render(name="Alice") # local await protocol(MyTool.run, tmpl) # pass to remote tool
Syntax (Mako-like):
${expr}- evaluate expr and insert the string result;nested braces are handled correctly (e.g.
${{'k': 1}['k']})
\${- literal${(escape, no interpolation)% stmt- Python control-flow line (for / if / while / …)% endfor/% endif/% end- block terminators%%- literal%at the start of an output line## comment- ignored
- BLOCK_CONT = frozenset({'elif', 'else', 'except', 'finally'})¶
- BLOCK_END = frozenset({'end', 'endfor', 'endif', 'endwhile', 'endwith'})¶
- BLOCK_OPEN = frozenset({'class', 'def', 'for', 'if', 'try', 'while', 'with'})¶
- rmote.protocol.render_template(template, **ctx)[source]¶
Compile and render a Mako-like template string in one step.
- Return type:
- class rmote.protocol.BaseProtocol(reader, writer)[source]¶
Bases:
object- BOUNDARY = b'PROTOCOL READY\n'¶
- COMPRESSION_THRESHOLD = 1024¶
- MAGIC = b'RMOTE'¶
- PACKET_HEADER = Struct('>5sIIQ')¶
- async classmethod from_ssh(host, *, user=None, port=None, identity=None, python='python3', ssh_options=None, stderr=-3)[source]¶
Bootstrap a Protocol over SSH.
- Parameters:
host (
Text) – Remote host, optionally inuser@hostform.user (
Text|None) – Remote username (-l). Overrides any user embedded in host.python (
Text) – Python executable on the remote host.ssh_options (
list[Text] |None) – Extra arguments inserted before the host in thesshcommand (e.g.["-o", "StrictHostKeyChecking=no"]).stderr (
int) – Where to redirect remote stderr. Defaults toDEVNULL.
- Return type:
Self
- class rmote.protocol.Protocol(reader, writer)[source]¶
Bases:
BaseProtocol
- class rmote.protocol.Flags(*values)[source]¶
Bases:
IntFlag- COMPRESSED = 1¶
- EXCEPTION = 32¶
- LOG = 64¶
- REQUEST = 2¶
- RESPONSE = 4¶
- RPC = 16¶
- SYNC = 8¶
- rmote.protocol.process(*cmd_and_args, stdin=None, capture_output=False, text=False, env=None, shell=False, check=False, cwd=None)[source]¶
function for execute a subprocess on the remote side, must be safe, do not share stdout/stderr of the child process, because it’s protocol pipes.
Tools must be use only this function for execute subprocesses, to avoid conflicts with protocol communication.
- Return type: