MCPcopy Create free account
hub / github.com/geekcomputers/Python / process_stream

Function process_stream

Cat/cat.py:32–56  ·  view source on GitHub ↗

Read from a stream and write processed output to stdout.

(stream, args, state)

Source from the content-addressed store, hash-verified

30
31
32def 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
59def process_file(filename, args, state):

Callers 3

process_fileFunction · 0.85
process_filesFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected