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

Function n_joined_str

uncompyle6/semantics/customize36.py:659–698  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

657 self.n_formatted_value2 = n_formatted_value2
658
659 def n_joined_str(node):
660 p = self.prec
661 self.prec = 100
662
663 old_in_format_string = self.in_format_string
664 self.in_format_string = "joined_str"
665 result = ""
666 for expr in node[:-1]:
667 assert expr == "expr"
668 value = self.traverse(expr, indent="")
669 if expr[0].kind.startswith("formatted_value"):
670 # remove leading 'f'
671 if value.startswith("f"):
672 value = value[1:]
673 pass
674 else:
675 # {{ and }} in Python source-code format strings mean
676 # { and } respectively. But only when *not* part of a
677 # formatted value. However, in the LOAD_STR
678 # bytecode, the escaping of the braces has been
679 # removed. So we need to put back the braces escaping in
680 # reconstructing the source.
681 assert (
682 expr[0] == "LOAD_STR"
683 or expr[0] == "LOAD_CONST"
684 and isinstance(expr[0].attr, unicode)
685 )
686 value = value.replace("{", "{{").replace("}", "}}")
687
688 # Remove leading quotes
689 result += strip_quotes(value)
690 pass
691 self.in_format_string = old_in_format_string
692 if self.in_format_string:
693 self.write(result)
694 else:
695 self.write("f%s" % escape_string(result))
696
697 self.prec = p
698 self.prune()
699
700 self.n_joined_str = n_joined_str
701

Callers

nothing calls this directly

Calls 4

strip_quotesFunction · 0.90
escape_stringFunction · 0.90
traverseMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected