accept any standard input and return it as a string or None
(stdin: Optional[IO]=sys.stdin)
| 118 | |
| 119 | |
| 120 | def accept_stdin(stdin: Optional[IO]=sys.stdin) -> Optional[str]: |
| 121 | """accept any standard input and return it as a string or None""" |
| 122 | |
| 123 | if not stdin: |
| 124 | return None |
| 125 | |
| 126 | if not stdin.isatty(): |
| 127 | # stderr('READING STDIN TO ACCEPT...') |
| 128 | stdin_str = stdin.read() |
| 129 | |
| 130 | if stdin_str: |
| 131 | # stderr('GOT STDIN...', len(stdin_str)) |
| 132 | return stdin_str |
| 133 | |
| 134 | return None |
| 135 | |
| 136 | |
| 137 | class TimedProgress: |