Read from a stream and write processed output to stdout.
(stream, args, state)
| 30 | |
| 31 | |
| 32 | def process_stream(stream, args, state): |
| 33 | """Read from a stream and write processed output to stdout.""" |
| 34 | for line in stream: |
| 35 | is_blank = line == "\n" |
| 36 | |
| 37 | if args.squeeze_blank and is_blank and state["previous_was_blank"]: |
| 38 | continue |
| 39 | |
| 40 | state["previous_was_blank"] = is_blank |
| 41 | |
| 42 | if args.show_ends: |
| 43 | if line.endswith("\n"): |
| 44 | line = line[:-1] + "$\n" |
| 45 | else: |
| 46 | line = line + "$" |
| 47 | |
| 48 | if args.number_nonblank: |
| 49 | if not is_blank: |
| 50 | sys.stdout.write(f"{state['line_number']:6}\t") |
| 51 | state["line_number"] += 1 |
| 52 | elif args.number: |
| 53 | sys.stdout.write(f"{state['line_number']:6}\t") |
| 54 | state["line_number"] += 1 |
| 55 | |
| 56 | sys.stdout.write(line) |
| 57 | |
| 58 | |
| 59 | def process_file(filename, args, state): |
no outgoing calls
no test coverage detected