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

Function cmp_code_objects

uncompyle6/verify.py:172–449  ·  view source on GitHub ↗

Compare two code-objects. This is the main part of this module.

(version, is_pypy, code_obj1, code_obj2, verify, name="")

Source from the content-addressed store, hash-verified

170
171
172def cmp_code_objects(version, is_pypy, code_obj1, code_obj2, verify, name=""):
173 """
174 Compare two code-objects.
175
176 This is the main part of this module.
177 """
178 # print code_obj1, type(code_obj2)
179 assert iscode(
180 code_obj1
181 ), "cmp_code_object first object type is %s, not code" % type(code_obj1)
182 assert iscode(
183 code_obj2
184 ), "cmp_code_object second object type is %s, not code" % type(code_obj2)
185 # print dir(code_obj1)
186 if isinstance(code_obj1, object):
187 # new style classes (Python 2.2)
188 # assume _both_ code objects to be new style classes
189 assert dir(code_obj1) == dir(code_obj2)
190 else:
191 # old style classes
192 assert dir(code_obj1) == code_obj1.__members__
193 assert dir(code_obj2) == code_obj2.__members__
194 assert code_obj1.__members__ == code_obj2.__members__
195
196 if name == "__main__":
197 name = code_obj1.co_name
198 else:
199 name = "%s.%s" % (name, code_obj1.co_name)
200 if name == ".?":
201 name = "__main__"
202
203 if isinstance(code_obj1, object) and code_equal(code_obj1, code_obj2):
204 # use the new style code-classes' __cmp__ method, which
205 # should be faster and more sophisticated
206 # if this compare fails, we use the old routine to
207 # find out, what exactly is nor equal
208 # if this compare succeeds, simply return
209 # return
210 pass
211
212 if isinstance(code_obj1, object):
213 members = [x for x in dir(code_obj1) if x.startswith("co_")]
214 else:
215 members = dir(code_obj1)
216 members.sort() # ; members.reverse()
217
218 tokens1 = None
219 for member in members:
220 if member in __IGNORE_CODE_MEMBERS__ or verify != "verify":
221 pass
222 elif member == "co_code":
223 if verify != "strong":
224 continue
225 scanner = get_scanner(version, is_pypy, show_asm=False)
226
227 global JUMP_OPS
228 JUMP_OPS = list(JUMP_OPS) + ["JUMP_BACK"]
229

Callers 2

compare_filesFunction · 0.70

Calls 12

get_scannerFunction · 0.90
code_equalFunction · 0.85
CmpErrorCodeLenClass · 0.85
CmpErrorCodeClass · 0.85
CmpErrorMemberClass · 0.85
sortMethod · 0.80
setTokenClassMethod · 0.80
resetTokenClassMethod · 0.80
fFunction · 0.50
ingestMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected