MCPcopy Index your code
hub / github.com/rocky/python-uncompyle6 / template_engine

Method template_engine

uncompyle6/semantics/pysource.py:720–897  ·  view source on GitHub ↗

The format template interpretation engine. See the comment at the beginning of this module for how we interpret format specifications such as %c, %C, and so on.

(self, entry, startnode)

Source from the content-addressed store, hash-verified

718 pass
719
720 def template_engine(self, entry, startnode):
721 """The format template interpretation engine. See the comment at the
722 beginning of this module for how we interpret format
723 specifications such as %c, %C, and so on.
724 """
725
726 # print("-----")
727 # print(startnode.kind)
728 # print(entry[0])
729 # print('======')
730
731 fmt = entry[0]
732 arg = 1
733 i = 0
734
735 m = escape.search(fmt)
736 while m:
737 i = m.end()
738 self.write(m.group("prefix"))
739
740 typ = m.group("type") or "{"
741 node = startnode
742 if m.group("child"):
743 node = node[int(m.group("child"))]
744
745 if typ == "%":
746 self.write("%")
747 elif typ == "+":
748 self.line_number += 1
749 self.indent_more()
750 elif typ == "-":
751 self.line_number += 1
752 self.indent_less()
753 elif typ == "|":
754 self.line_number += 1
755 self.write(self.indent)
756 # Used mostly on the LHS of an assignment
757 # BUILD_TUPLE_n is pretty printed and may take care of other uses.
758 elif typ == ",":
759 if node.kind in ("unpack", "unpack_w_parens") and node[0].attr == 1:
760 self.write(",")
761 elif typ == "c":
762 index = entry[arg]
763 if isinstance(index, tuple):
764 if isinstance(index[1], str):
765 # if node[index[0]] != index[1]:
766 # from trepan.api import debug; debug()
767 assert (
768 node[index[0]] == index[1]
769 ), "at %s[%d], expected '%s' node; got '%s'" % (
770 node.kind,
771 arg,
772 index[1],
773 node[index[0]].kind,
774 )
775 else:
776 assert (
777 node[index[0]] in index[1]

Callers 15

print_super_classes3Method · 0.95
defaultMethod · 0.95
call_ex_kwFunction · 0.45
call_ex_kw2Function · 0.45
n_call_kw36Function · 0.45
starredFunction · 0.45
n_dictMethod · 0.45
n_returnMethod · 0.45
n_yieldMethod · 0.45
except_return_valueFunction · 0.45
try_except38r3Function · 0.45
n_list_aforFunction · 0.45

Calls 4

writeMethod · 0.95
indent_moreMethod · 0.95
indent_lessMethod · 0.95
preorderMethod · 0.95

Tested by

no test coverage detected