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

Function validate_uncompyle

pytest/validate.py:114–149  ·  view source on GitHub ↗

Validate decompilation of the given source code. :param text: Source to validate decompilation of.

(text, mode="exec")

Source from the content-addressed store, hash-verified

112
113
114def validate_uncompyle(text, mode="exec"):
115 """
116 Validate decompilation of the given source code.
117
118 :param text: Source to validate decompilation of.
119 """
120 original_code = compile(text, "<string>", mode)
121 original_dis = _dis_to_text(original_code)
122 original_text = text
123
124 deparsed = code_deparse(
125 original_code, out=six.StringIO(), version=PYTHON_VERSION_TRIPLE, compile_mode=mode
126 )
127 uncompyled_text = deparsed.text
128 uncompyled_code = compile(uncompyled_text, "<string>", "exec")
129
130 if not are_code_objects_equal(uncompyled_code, original_code):
131
132 uncompyled_dis = _dis_to_text(uncompyled_text)
133
134 def output(text, dis):
135 width = 60
136 return "\n\n".join(
137 [
138 " SOURCE CODE ".center(width, "#"),
139 text.strip(),
140 " BYTECODE ".center(width, "#"),
141 dis,
142 ]
143 )
144
145 original = output(original_text, original_dis)
146 uncompyled = output(uncompyled_text, uncompyled_dis)
147 print_diff(original, uncompyled)
148
149 assert "original" == "uncompyled"

Callers 1

test_build_const_key_mapFunction · 0.90

Calls 5

code_deparseFunction · 0.90
_dis_to_textFunction · 0.85
are_code_objects_equalFunction · 0.85
outputFunction · 0.85
print_diffFunction · 0.85

Tested by 1

test_build_const_key_mapFunction · 0.72