MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / write

Function write

src/py_class/py_class_impl.py:211–242  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

209last_char = '\n'
210
211def write(text):
212 global last_char
213 for line in text.splitlines(True):
214 line = line.lstrip(' ')
215 if len(line.strip()) == 0 and last_char == '\n':
216 continue
217 if last_char == '\n':
218 initial_closing = 0
219 for c in line:
220 if c in ']}':
221 initial_closing += 1
222 else:
223 break
224 if initial_closing:
225 sys.stdout.write(''.join(indentation[:-initial_closing]))
226 else:
227 sys.stdout.write(''.join(indentation))
228 elif last_char not in ' \n' and len(line) > 0 and line[0] not in ' \n;':
229 sys.stdout.write(' ')
230 sys.stdout.write(line)
231 min_indent_level = len(indentation)
232 for c in line:
233 if c in '[{':
234 if len(indentation) > min_indent_level:
235 indentation.append('')
236 else:
237 indentation.append(' ')
238 elif c in ']}':
239 indentation.pop()
240 if len(indentation) < min_indent_level:
241 min_indent_level = len(indentation)
242 last_char = line[-1]
243
244slot_groups = (
245 ('tp', 'type_slots', None),

Callers 4

normalizeMethod · 0.85
data_initFunction · 0.85
generate_caseFunction · 0.85
mainFunction · 0.85

Calls 3

lenFunction · 0.85
appendMethod · 0.80
popMethod · 0.80

Tested by

no test coverage detected