GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pythonparser/pythonparser/__init__.py at master · m-labs/pythonparser

This repository was archived by the owner on Jan 3, 2026. It is now read-only.

Expand file tree

/

__init__.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
60 lines (50 loc) · 2.37 KB
/

__init__.py

Copy path

File metadata and controls

60 lines (50 loc) · 2.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from __future__ import absolute_import, division, print_function, unicode_literals
import sys, pythonparser.source, pythonparser.lexer, pythonparser.parser, pythonparser.diagnostic
def parse_buffer(buffer, mode="exec", flags=[], version=None, engine=None):
"""
Like :meth:`parse`, but accepts a :class:`source.Buffer` instead of
source and filename, and returns comments as well.
:see: :meth:`parse`
:return: (:class:`ast.AST`, list of :class:`source.Comment`)
Abstract syntax tree and comments
"""
if version is None:
version = (3, 6)
if engine is None:
engine = pythonparser.diagnostic.Engine()
lexer = pythonparser.lexer.Lexer(buffer, version, engine)
if mode in ("single", "eval"):
lexer.interactive = True
parser = pythonparser.parser.Parser(lexer, version, engine)
parser.add_flags(flags)
if mode == "exec":
return parser.file_input(), lexer.comments
elif mode == "single":
return parser.single_input(), lexer.comments
elif mode == "eval":
return parser.eval_input(), lexer.comments
def parse(source, filename="<unknown>", mode="exec",
flags=[], version=None, engine=None):
"""
Parse a string into an abstract syntax tree.
This is the replacement for the built-in :meth:`..ast.parse`.
:param source: (string) Source code in the correct encoding
:param filename: (string) Filename of the source (used in diagnostics)
:param mode: (string) Execution mode. Pass ``"exec"`` to parse a module,
``"single"`` to parse a single (interactive) statement,
and ``"eval"`` to parse an expression. In the last two cases,
``source`` must be terminated with an empty line
(i.e. end with ``"\\n\\n"``).
:param flags: (list of string) Future flags.
Equivalent to ``from __future__ import <flags>``.
:param version: (2-tuple of int) Major and minor version of Python
syntax to recognize, ``(3, 6)`` by default.
:param engine: (:class:`diagnostic.Engine`) Diagnostic engine,
a fresh one is created by default
:return: (:class:`ast.AST`) Abstract syntax tree
:raise: :class:`diagnostic.Error`
if the source code is not well-formed
"""
ast, comments = parse_buffer(pythonparser.source.Buffer(source, filename),
mode, flags, version, engine)
return ast
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.