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)
| 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 |
| 101 | def _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 |
no outgoing calls
no test coverage detected