MCPcopy Create free account
hub / github.com/ParzivalHack/PySpector / _silence_fd1

Function _silence_fd1

src/pyspector/cli.py:93–114  ·  view source on GitHub ↗

Redirect file descriptor 1 (stdout) to /dev/null when *active* is True. Used to swallow ``println!`` output emitted by the Rust core during a scan when --debug is not set. Python-side ``click.echo`` calls inside the block are also suppressed; do not place user-facing output (findings, e

(active: bool)

Source from the content-addressed store, hash-verified

91
92_SEV_COLOR: Dict[str, str] = {
93 "CRITICAL": "bright_red",
94 "HIGH": "red",
95 "MEDIUM": "yellow",
96 "LOW": "blue",
97}
98
99
100@contextlib.contextmanager
101def _silence_fd1(active: bool):
102 """Redirect file descriptor 1 (stdout) to /dev/null when *active* is True.
103
104 Used to swallow ``println!`` output emitted by the Rust core during a scan
105 when --debug is not set. Python-side ``click.echo`` calls inside the block
106 are also suppressed; do not place user-facing output (findings, errors)
107 inside this context.
108 """
109 if not active:
110 yield
111 return
112 sys.stdout.flush()
113 saved_fd = os.dup(1)
114 devnull_fd = os.open(os.devnull, os.O_WRONLY)
115 try:
116 os.dup2(devnull_fd, 1)
117 yield

Callers 2

_scan_to_issuesFunction · 0.85
_execute_scanFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected