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

Function get_scanner

uncompyle6/scanner.py:608–661  ·  view source on GitHub ↗

Import the right scanner module for ``version`` and return the Scanner class in that module.

(version: Union[str, tuple], is_pypy=False, show_asm=None)

Source from the content-addressed store, hash-verified

606
607
608def get_scanner(version: Union[str, tuple], is_pypy=False, show_asm=None) -> Scanner:
609 """
610 Import the right scanner module for ``version`` and return the Scanner class
611 in that module.
612 """
613 # If version is a string, turn that into the corresponding float.
614 if isinstance(version, str):
615 if version not in canonic_python_version:
616 raise RuntimeError(f"Unknown Python version in xdis {version}")
617 canonic_version = canonic_python_version[version]
618 if canonic_version not in CANONIC2VERSION:
619 raise RuntimeError(
620 f"Unsupported Python version {version} (canonic {canonic_version})"
621 )
622 version = CANONIC2VERSION[canonic_version]
623
624 # Pick up appropriate scanner
625 if version[:2] in PYTHON_VERSIONS:
626 v_str = version_tuple_to_str(version, start=0, end=2, delimiter="")
627 try:
628 import importlib
629
630 if is_pypy:
631 scan = importlib.import_module("uncompyle6.scanners.pypy%s" % v_str)
632 else:
633 scan = importlib.import_module("uncompyle6.scanners.scanner%s" % v_str)
634 if False:
635 print(scan) # Avoid unused scan
636 except ImportError:
637 if is_pypy:
638 exec(
639 "import uncompyle6.scanners.pypy%s as scan" % v_str,
640 locals(),
641 globals(),
642 )
643 else:
644 exec(
645 "import uncompyle6.scanners.scanner%s as scan" % v_str,
646 locals(),
647 globals(),
648 )
649 if is_pypy:
650 scanner = eval(
651 "scan.ScannerPyPy%s(show_asm=show_asm)" % v_str, locals(), globals()
652 )
653 else:
654 scanner = eval(
655 "scan.Scanner%s(show_asm=show_asm)" % v_str, locals(), globals()
656 )
657 else:
658 raise RuntimeError(
659 f"Unsupported Python version, {version_tuple_to_str(version)}, for decompilation"
660 )
661 return scanner
662
663
664if __name__ == "__main__":

Callers 15

python_parserFunction · 0.90
cmp_code_objectsFunction · 0.90
discoFunction · 0.90
parse38.pyFile · 0.90
parse31.pyFile · 0.90
parse37.pyFile · 0.90
parse35.pyFile · 0.90
parse36.pyFile · 0.90
parse26.pyFile · 0.90
parse34.pyFile · 0.90
parse30.pyFile · 0.90
parse27.pyFile · 0.90

Calls

no outgoing calls

Tested by 3

test_grammarFunction · 0.72
test_get_scannerFunction · 0.72
test_if_in_forFunction · 0.72