()
| 1725 | |
| 1726 | |
| 1727 | def main(): |
| 1728 | import argparse |
| 1729 | |
| 1730 | parser = argparse.ArgumentParser(prog='python -m ast') |
| 1731 | parser.add_argument('infile', type=argparse.FileType(mode='rb'), nargs='?', |
| 1732 | default='-', |
| 1733 | help='the file to parse; defaults to stdin') |
| 1734 | parser.add_argument('-m', '--mode', default='exec', |
| 1735 | choices=('exec', 'single', 'eval', 'func_type'), |
| 1736 | help='specify what kind of code must be parsed') |
| 1737 | parser.add_argument('--no-type-comments', default=True, action='store_false', |
| 1738 | help="don't add information about type comments") |
| 1739 | parser.add_argument('-a', '--include-attributes', action='store_true', |
| 1740 | help='include attributes such as line numbers and ' |
| 1741 | 'column offsets') |
| 1742 | parser.add_argument('-i', '--indent', type=int, default=3, |
| 1743 | help='indentation of nodes (number of spaces)') |
| 1744 | args = parser.parse_args() |
| 1745 | |
| 1746 | with args.infile as infile: |
| 1747 | source = infile.read() |
| 1748 | tree = parse(source, args.infile.name, args.mode, type_comments=args.no_type_comments) |
| 1749 | print(dump(tree, include_attributes=args.include_attributes, indent=args.indent)) |
| 1750 | |
| 1751 | if __name__ == '__main__': |
| 1752 | main() |
no test coverage detected