MCPcopy
hub / github.com/rocky/python-uncompyle6 / str_with_template1

Method str_with_template1

uncompyle6/semantics/pysource.py:358–409  ·  view source on GitHub ↗
(self, ast, indent, sibNum=None)

Source from the content-addressed store, hash-verified

356 stream.write("\n")
357
358 def str_with_template1(self, ast, indent, sibNum=None) -> str:
359 rv = str(ast.kind)
360
361 if sibNum is not None:
362 rv = "%2d. %s" % (sibNum, rv)
363 enumerate_children = False
364 if len(ast) > 1:
365 rv += f" ({len(ast)})"
366 enumerate_children = True
367
368 if ast in PRECEDENCE:
369 rv += f", precedence {PRECEDENCE[ast]}"
370
371 mapping = self._get_mapping(ast)
372 table = mapping[0]
373 key = ast
374 for i in mapping[1:]:
375 key = key[i]
376 pass
377
378 if ast.transformed_by is not None:
379 if ast.transformed_by is True:
380 rv += " transformed"
381 else:
382 rv += " transformed by %s" % ast.transformed_by
383 pass
384 pass
385 if key.kind in table:
386 rv += ": %s" % str(table[key.kind])
387
388 rv = indent + rv
389 indent += " "
390 i = 0
391 for node in ast:
392 if hasattr(node, "__repr1__"):
393 if enumerate_children:
394 child = self.str_with_template1(node, indent, i)
395 else:
396 child = self.str_with_template1(node, indent, None)
397 else:
398 inst = node.format(line_prefix="L.")
399 if inst.startswith("\n"):
400 # Nuke leading \n
401 inst = inst[1:]
402 if enumerate_children:
403 child = indent + "%2d. %s" % (i, inst)
404 else:
405 child = indent + inst
406 pass
407 rv += "\n" + child
408 i += 1
409 return rv
410
411 def indent_if_source_nl(self, line_number: int, indent_spaces: str):
412 if line_number != self.line_number:

Callers 1

str_with_templateMethod · 0.95

Calls 2

_get_mappingMethod · 0.95
formatMethod · 0.80

Tested by

no test coverage detected