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

Function get_python_parser

uncompyle6/parser.py:660–866  ·  view source on GitHub ↗

Returns parser object for Python version 2 or 3, 3.2, 3.5on, etc., depending on the parameters passed. *compile_mode* is either 'exec', 'eval', or 'single'. See https://docs.python.org/3.6/library/functions.html#compile for an explanation of the different modes.

(
    version, debug_parser=PARSER_DEFAULT_DEBUG, compile_mode="exec", is_pypy=False
)

Source from the content-addressed store, hash-verified

658
659
660def get_python_parser(
661 version, debug_parser=PARSER_DEFAULT_DEBUG, compile_mode="exec", is_pypy=False
662):
663 """Returns parser object for Python version 2 or 3, 3.2, 3.5on,
664 etc., depending on the parameters passed. *compile_mode* is either
665 'exec', 'eval', or 'single'. See
666 https://docs.python.org/3.6/library/functions.html#compile for an
667 explanation of the different modes.
668 """
669
670 # If version is a string, turn that into the corresponding float.
671 if isinstance(version, str):
672 version = tuple([int(v) for v in version.split(".")[:2]])
673
674 version = version[:2]
675
676 p = None
677
678 # FIXME: there has to be a better way...
679 # We could do this as a table lookup, but that would force us
680 # in import all of the parsers all of the time. Perhaps there is
681 # a lazy way of doing the import?
682
683 if version < (3, 0):
684 if version < (2, 2):
685 if version == (1, 0):
686 import uncompyle6.parsers.parse10 as parse10
687
688 if compile_mode == "exec":
689 p = parse10.Python10Parser(debug_parser)
690 else:
691 p = parse10.Python10ParserSingle(debug_parser)
692 elif version == (1, 1):
693 import uncompyle6.parsers.parse11 as parse11
694
695 if compile_mode == "exec":
696 p = parse11.Python11Parser(debug_parser)
697 else:
698 p = parse11.Python11ParserSingle(debug_parser)
699 if version == (1, 2):
700 import uncompyle6.parsers.parse12 as parse12
701
702 if compile_mode == "exec":
703 p = parse12.Python12Parser(debug_parser)
704 else:
705 p = parse12.Python12ParserSingle(debug_parser)
706 if version == (1, 3):
707 import uncompyle6.parsers.parse13 as parse13
708
709 if compile_mode == "exec":
710 p = parse13.Python13Parser(debug_parser)
711 else:
712 p = parse13.Python13ParserSingle(debug_parser)
713 elif version == (1, 4):
714 import uncompyle6.parsers.parse14 as parse14
715
716 if compile_mode == "exec":
717 p = parse14.Python14Parser(debug_parser)

Callers 6

__init__Method · 0.90
comprehension_walkMethod · 0.90
test_grammarFunction · 0.90
test_get_parserFunction · 0.90
python_parserFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_grammarFunction · 0.72
test_get_parserFunction · 0.72