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

Function compare_code_with_srcfile

uncompyle6/verify.py:479–513  ·  view source on GitHub ↗

Compare a .pyc with a source code file. If everything is okay, None is returned. Otherwise a string message describing the mismatch is returned.

(pyc_filename, src_filename, verify)

Source from the content-addressed store, hash-verified

477
478
479def compare_code_with_srcfile(pyc_filename, src_filename, verify):
480 """Compare a .pyc with a source code file. If everything is okay, None
481 is returned. Otherwise a string message describing the mismatch is returned.
482 """
483 (
484 version,
485 timestamp,
486 magic_int,
487 code_obj1,
488 is_pypy,
489 source_size,
490 sip_hash,
491 ) = load_module(pyc_filename)
492 if magic_int != PYTHON_MAGIC_INT:
493 msg = (
494 "Can't compare code - Python is running with magic %s, but code is magic %s "
495 % (PYTHON_MAGIC_INT, magic_int)
496 )
497 return msg
498 try:
499 code_obj2 = load_file(src_filename)
500 except SyntaxError as e:
501 # src_filename can be the first of a group sometimes
502 return str(e).replace(src_filename, pyc_filename)
503 cmp_code_objects(version, is_pypy, code_obj1, code_obj2, verify)
504 if verify == "verify-run":
505 try:
506 retcode = call("%s %s" % (sys.executable, src_filename), shell=True)
507 if retcode != 0:
508 return "Child was terminated by signal %d" % retcode
509 pass
510 except OSError as e:
511 return "Execution failed: %s" % e
512 pass
513 return None
514
515
516def compare_files(pyc_filename1, pyc_filename2, verify):

Callers

nothing calls this directly

Calls 2

cmp_code_objectsFunction · 0.70
callFunction · 0.50

Tested by

no test coverage detected