sshscript 4.0.2__py3-none-any.whl → 6.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sshscript/__init__.py CHANGED
@@ -59,6 +59,7 @@ run_file = sshscript.run_file
59
59
  check_file = sshscript.check_file
60
60
  run_script = sshscript.run_script
61
61
  Session = session.Session
62
+ ScriptResult = session.ScriptResult
62
63
  CommandResult = session.CommandResult
63
64
  CommandJob = session.CommandJob
64
65
  CommandTimeoutError = session.CommandTimeoutError
@@ -89,6 +90,7 @@ __all__ = [
89
90
  'run_script',
90
91
  'Session',
91
92
  'CommandResult',
93
+ 'ScriptResult',
92
94
  'CommandJob',
93
95
  'CommandTimeoutError',
94
96
  'JobResult',
sshscript/__init__.pyi CHANGED
@@ -1,6 +1,7 @@
1
1
  from typing import Any, ContextManager
2
2
  from os import PathLike
3
3
  from .session import Session as Session
4
+ from .scriptcontrol import ScriptResult as ScriptResult
4
5
  from .commandresult import CommandResult as CommandResult
5
6
  from .commandjob import CommandJob as CommandJob, JobResult as JobResult, CommandTimeoutError as CommandTimeoutError
6
7
  from .errorutils import SSHScriptException as SSHScriptException
@@ -9,7 +10,7 @@ __version__: str
9
10
 
10
11
  def check_file(script_path: str | PathLike[str]) -> int: ...
11
12
  def run_file(script_path: str | PathLike[str], vars: dict[str, Any] | None = ..., showScript: bool = ...) -> int: ...
12
- def run_script(script: str, varGlobals: dict[str, Any] | None = ..., showScript: bool = ...) -> dict[str, Any]: ...
13
+ def run_script(script: str, varGlobals: dict[str, Any] | None = ..., showScript: bool = ...) -> ScriptResult: ...
13
14
  def spy_imports() -> ContextManager[None]: ...
14
15
  def get_logger() -> Any: ...
15
16
  def set_logger(userlogger: Any = ..., logname: str | None = ...) -> Any: ...
sshscript/_version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Single source of the SSHScript package version."""
2
2
 
3
- __version__ = "4.0.2"
3
+ __version__ = "6.0.0"
@@ -1492,6 +1492,11 @@ class GenericChannel(object):
1492
1492
  Existing newlines are retained. Use send() to write exact text instead.
1493
1493
  A readiness/silence status does not establish command success.
1494
1494
  """
1495
+ return self._input_text(text, timeout=timeout, append_newline=True)
1496
+
1497
+ def _input_text(self, text, timeout=60, *, append_newline=True):
1498
+ """Shared interactive protocol for lines and raw terminal control bytes."""
1499
+ payload = text + ('\n' if append_newline else '') if isinstance(text, str) else text
1495
1500
  if not isinstance(text, str):
1496
1501
  raise TypeError('input text must be str')
1497
1502
 
@@ -1504,7 +1509,7 @@ class GenericChannel(object):
1504
1509
  )
1505
1510
 
1506
1511
  if not self.hijacked:
1507
- return self.send(text + '\n', timeout=timeout)
1512
+ return self.send(payload, timeout=timeout)
1508
1513
 
1509
1514
  deadline = time.monotonic() + timeout
1510
1515
  executing_lock = self.executing_lock
@@ -1555,7 +1560,7 @@ class GenericChannel(object):
1555
1560
  stderr.set_callback(prompt_found, current_prompt)
1556
1561
 
1557
1562
  self.send(
1558
- text + '\n',
1563
+ payload,
1559
1564
  timeout=self._remaining(deadline),
1560
1565
  )
1561
1566
 
sshscript/dollarparser.py CHANGED
@@ -138,7 +138,7 @@ def _token_syntax_error(error, script_path, spyscript):
138
138
  return _source_syntax_error(synthetic, script_path, spyscript)
139
139
 
140
140
 
141
- def parse(script_path, spyscript):
141
+ def parse(script_path, spyscript, *, preprocess=None):
142
142
  """Return a transformed AST whose locations still refer to *spyscript*."""
143
143
  _cache_source(script_path, spyscript)
144
144
  try:
@@ -156,6 +156,8 @@ def parse(script_path, spyscript):
156
156
  raise _source_syntax_error(error, script_path, spyscript) from None
157
157
 
158
158
  try:
159
+ if preprocess is not None:
160
+ tree = preprocess.visit(tree)
159
161
  py_tree = DollarChanger().visit(tree)
160
162
  return ast.fix_missing_locations(py_tree)
161
163
  except Exception as error:
sshscript/errorutils.py CHANGED
@@ -32,13 +32,6 @@ class SSHScriptException(Exception):
32
32
  def __str__(self):
33
33
  return f'{self.message}(#{self.errno})'
34
34
 
35
- class SSHScriptBreak(SSHScriptException):
36
- """Control-flow signal for $.break(status), handled by the script runner."""
37
- pass
38
-
39
- class SSHScriptExit(SSHScriptException):
40
- """Control-flow signal for $.exit(status), propagated to the command-line runner."""
41
- pass
42
35
 
43
36
  def dumpScript(source,tb_lineno=None,linerange=10):
44
37
  """Print source with line numbers and optional error-line context."""