pyscript-programming-language 1.12.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyscript/__init__.py +49 -0
- pyscript/__init__.pyi +96 -0
- pyscript/__main__.py +303 -0
- pyscript/core/__init__.py +61 -0
- pyscript/core/analyzer.py +531 -0
- pyscript/core/bases.py +2 -0
- pyscript/core/buffer.py +43 -0
- pyscript/core/cache.py +70 -0
- pyscript/core/checks.py +42 -0
- pyscript/core/constants.py +123 -0
- pyscript/core/context.py +63 -0
- pyscript/core/editor/__init__.py +15 -0
- pyscript/core/editor/bases.py +35 -0
- pyscript/core/editor/gui.py +144 -0
- pyscript/core/editor/terminal.py +175 -0
- pyscript/core/exceptions.py +123 -0
- pyscript/core/handlers.py +57 -0
- pyscript/core/highlight.py +552 -0
- pyscript/core/interpreter.py +1546 -0
- pyscript/core/lexer.py +863 -0
- pyscript/core/mapping.py +139 -0
- pyscript/core/nodes.py +663 -0
- pyscript/core/objects.py +213 -0
- pyscript/core/parser.py +2456 -0
- pyscript/core/position.py +114 -0
- pyscript/core/pysbuiltins.py +703 -0
- pyscript/core/results.py +186 -0
- pyscript/core/runner.py +363 -0
- pyscript/core/shell.py +287 -0
- pyscript/core/symtab.py +103 -0
- pyscript/core/token.py +25 -0
- pyscript/core/utils/__init__.py +27 -0
- pyscript/core/utils/ansi.py +127 -0
- pyscript/core/utils/debug.py +60 -0
- pyscript/core/utils/decorators.py +53 -0
- pyscript/core/utils/generic.py +46 -0
- pyscript/core/utils/jsdict.py +32 -0
- pyscript/core/utils/module.py +28 -0
- pyscript/core/utils/path.py +29 -0
- pyscript/core/utils/similarity.py +22 -0
- pyscript/core/utils/string.py +49 -0
- pyscript/core/version.py +120 -0
- pyscript/lib/__hello__.pys +7 -0
- pyscript/lib/ansi.pys +14 -0
- pyscript/lib/ast/__init__.pys +36 -0
- pyscript/lib/ast/ast_dump.py +433 -0
- pyscript/lib/ast/ast_literal_eval.py +80 -0
- pyscript/lib/ast/ast_unparse.py +540 -0
- pyscript/lib/ast/ast_walk.py +256 -0
- pyscript/lib/brainfuck.pys +190 -0
- pyscript/lib/dis.pys +7 -0
- pyscript/lib/explorer.pys +218 -0
- pyscript/lib/fpstimer/__init__.pys +6 -0
- pyscript/lib/fpstimer/py_fpstimer.py +54 -0
- pyscript/lib/getch.pys +28 -0
- pyscript/lib/inspect.pys +25 -0
- pyscript/lib/jsdict.pys +5 -0
- pyscript/lib/keyword.pys +2 -0
- pyscript/lib/opcode.pys +1 -0
- pyscript/lib/parser.pys +165 -0
- pyscript/lib/site.pys +55 -0
- pyscript/lib/symtable.pys +5 -0
- pyscript/lib/token.pys +12 -0
- pyscript/lib/tokenize/__init__.pys +14 -0
- pyscript/lib/tokenize/tok_untokenize.py +64 -0
- pyscript/other/.nomedia +0 -0
- pyscript/other/PyScript.ico +0 -0
- pyscript/other/copyright +2 -0
- pyscript/other/credits +2 -0
- pyscript/other/license +21 -0
- pyscript/site-packages/this.pys +19 -0
- pyscript/this.py +8 -0
- pyscript_programming_language-1.12.0.dist-info/METADATA +133 -0
- pyscript_programming_language-1.12.0.dist-info/RECORD +76 -0
- pyscript_programming_language-1.12.0.dist-info/WHEEL +5 -0
- pyscript_programming_language-1.12.0.dist-info/top_level.txt +1 -0
pyscript/__init__.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PyScript is a programming language written 100% in Python. \
|
|
3
|
+
This language is not isolated and is directly integrated with the Python's library and namespace levels.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
if __import__('sys').version_info < (3, 10):
|
|
7
|
+
raise ImportError("Python version 3.10 and above is required to run PyScript")
|
|
8
|
+
|
|
9
|
+
from . import core
|
|
10
|
+
|
|
11
|
+
from .core.constants import (
|
|
12
|
+
DEFAULT, NO_COLOR, DEBUG, SILENT, RETURN_RESULT, DONT_SHOW_BANNER_ON_SHELL, CLASSIC_LINE_SHELL, LEXER_HIGHLIGHT,
|
|
13
|
+
DICT_TO_JSDICT
|
|
14
|
+
)
|
|
15
|
+
from .core.cache import undefined
|
|
16
|
+
from .core.highlight import (
|
|
17
|
+
HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight, PygmentsPyScriptStyle, PygmentsPyScriptLexer,
|
|
18
|
+
PygmentsPyScriptShellLexer
|
|
19
|
+
)
|
|
20
|
+
from .core.runner import pys_runner, pys_exec, pys_eval, pys_require, pys_shell
|
|
21
|
+
from .core.version import version, version_info, __version__, __date__
|
|
22
|
+
|
|
23
|
+
__all__ = (
|
|
24
|
+
'core',
|
|
25
|
+
'DEFAULT',
|
|
26
|
+
'NO_COLOR',
|
|
27
|
+
'DEBUG',
|
|
28
|
+
'SILENT',
|
|
29
|
+
'RETURN_RESULT',
|
|
30
|
+
'DONT_SHOW_BANNER_ON_SHELL',
|
|
31
|
+
'CLASSIC_LINE_SHELL',
|
|
32
|
+
'LEXER_HIGHLIGHT',
|
|
33
|
+
'DICT_TO_JSDICT',
|
|
34
|
+
'HLFMT_HTML',
|
|
35
|
+
'HLFMT_ANSI',
|
|
36
|
+
'HLFMT_BBCODE',
|
|
37
|
+
'undefined',
|
|
38
|
+
'version',
|
|
39
|
+
'version_info',
|
|
40
|
+
'pys_highlight',
|
|
41
|
+
'pys_runner',
|
|
42
|
+
'pys_exec',
|
|
43
|
+
'pys_eval',
|
|
44
|
+
'pys_require',
|
|
45
|
+
'pys_shell',
|
|
46
|
+
'PygmentsPyScriptStyle',
|
|
47
|
+
'PygmentsPyScriptLexer',
|
|
48
|
+
'PygmentsPyScriptShellLexer'
|
|
49
|
+
)
|
pyscript/__init__.pyi
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, Optional
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from .core.buffer import PysFileBuffer
|
|
5
|
+
from .core.cache import PysUndefined
|
|
6
|
+
from .core.context import PysContext
|
|
7
|
+
from .core.highlight import _PysHighlightFormatter
|
|
8
|
+
from .core.position import PysPosition
|
|
9
|
+
from .core.results import PysExecuteResult
|
|
10
|
+
from .core.symtab import PysSymbolTable
|
|
11
|
+
from .core.version import PysVersionInfo
|
|
12
|
+
|
|
13
|
+
from io import IOBase
|
|
14
|
+
from types import BuiltinMethodType, ModuleType
|
|
15
|
+
|
|
16
|
+
from . import core as core
|
|
17
|
+
from .core.highlight import (
|
|
18
|
+
PygmentsPyScriptStyle as PygmentsPyScriptStyle,
|
|
19
|
+
PygmentsPyScriptLexer as PygmentsPyScriptLexer,
|
|
20
|
+
PygmentsPyScriptShellLexer as PygmentsPyScriptShellLexer
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
DEFAULT: int
|
|
24
|
+
NO_COLOR: int
|
|
25
|
+
DEBUG: int
|
|
26
|
+
SILENT: int
|
|
27
|
+
RETURN_RESULT: int
|
|
28
|
+
DONT_SHOW_BANNER_ON_SHELL: int
|
|
29
|
+
CLASSIC_LINE_SHELL: int
|
|
30
|
+
LEXER_HIGHLIGHT: int
|
|
31
|
+
DICT_TO_JSDICT: int
|
|
32
|
+
|
|
33
|
+
HLFMT_HTML: _PysHighlightFormatter
|
|
34
|
+
HLFMT_ANSI: _PysHighlightFormatter
|
|
35
|
+
HLFMT_BBCODE: _PysHighlightFormatter
|
|
36
|
+
|
|
37
|
+
undefined: PysUndefined
|
|
38
|
+
version: str
|
|
39
|
+
version_info: PysVersionInfo
|
|
40
|
+
|
|
41
|
+
def pys_highlight(
|
|
42
|
+
source: str | bytes | bytearray | Iterable | BuiltinMethodType | IOBase | PysFileBuffer,
|
|
43
|
+
formatter: Optional[
|
|
44
|
+
Callable[
|
|
45
|
+
[
|
|
46
|
+
str | Literal[
|
|
47
|
+
'start', 'default', 'newline', 'keyword', 'keyword-constant', 'identifier', 'identifier-constant',
|
|
48
|
+
'identifier-function', 'identifier-type', 'number', 'string', 'comment', 'invalid', 'end'
|
|
49
|
+
],
|
|
50
|
+
PysPosition,
|
|
51
|
+
str
|
|
52
|
+
],
|
|
53
|
+
str
|
|
54
|
+
]
|
|
55
|
+
] = None,
|
|
56
|
+
max_bracket_level: int = 3
|
|
57
|
+
) -> str: ...
|
|
58
|
+
|
|
59
|
+
def pys_runner(
|
|
60
|
+
file: PysFileBuffer,
|
|
61
|
+
mode: Literal['exec', 'eval', 'single'],
|
|
62
|
+
symbol_table: PysSymbolTable,
|
|
63
|
+
flags: Optional[int] = None,
|
|
64
|
+
parser_flags: int = DEFAULT,
|
|
65
|
+
context_parent: Optional[PysContext] = None,
|
|
66
|
+
context_parent_entry_position: Optional[PysPosition] = None
|
|
67
|
+
) -> PysExecuteResult: ...
|
|
68
|
+
|
|
69
|
+
def pys_exec(
|
|
70
|
+
source: str | bytes | bytearray | Iterable | BuiltinMethodType | IOBase | PysFileBuffer,
|
|
71
|
+
globals: Optional[dict[str, Any] | PysSymbolTable | PysUndefined] = None,
|
|
72
|
+
flags: int = DEFAULT,
|
|
73
|
+
parser_flags: int = DEFAULT
|
|
74
|
+
) -> None | PysExecuteResult: ...
|
|
75
|
+
|
|
76
|
+
def pys_eval(
|
|
77
|
+
source: str | bytes | bytearray | Iterable | BuiltinMethodType | IOBase | PysFileBuffer,
|
|
78
|
+
globals: Optional[dict[str, Any] | PysSymbolTable | PysUndefined] = None,
|
|
79
|
+
flags: int = DEFAULT,
|
|
80
|
+
parser_flags: int = DEFAULT
|
|
81
|
+
) -> Any | PysExecuteResult: ...
|
|
82
|
+
|
|
83
|
+
def pys_require(
|
|
84
|
+
name: str | bytes,
|
|
85
|
+
flags: int = DEFAULT
|
|
86
|
+
) -> ModuleType | Any: ...
|
|
87
|
+
|
|
88
|
+
def pys_shell(
|
|
89
|
+
globals: Optional[dict[str, Any] | PysSymbolTable | PysUndefined] = None,
|
|
90
|
+
flags: int = DEFAULT,
|
|
91
|
+
parser_flags: int = DEFAULT
|
|
92
|
+
) -> int | Any: ...
|
|
93
|
+
|
|
94
|
+
__version__: str
|
|
95
|
+
__date__: str
|
|
96
|
+
__all__: tuple[str]
|
pyscript/__main__.py
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
from .core.buffer import PysFileBuffer
|
|
2
|
+
from .core.cache import pys_sys, undefined
|
|
3
|
+
from .core.constants import (
|
|
4
|
+
ENV_PYSCRIPT_CLASSIC_LINE_SHELL, DEFAULT, DEBUG, NO_COLOR, DONT_SHOW_BANNER_ON_SHELL, CLASSIC_LINE_SHELL
|
|
5
|
+
)
|
|
6
|
+
from .core.editor.gui import PysGUIEditor, GUI_SUPPORT
|
|
7
|
+
from .core.editor.terminal import PysTerminalEditor, TERMINAL_SUPPORT
|
|
8
|
+
from .core.highlight import (
|
|
9
|
+
PYGMENTS, HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight, PygmentsPyScriptStyle, PygmentsPyScriptLexer
|
|
10
|
+
)
|
|
11
|
+
from .core.runner import _normalize_namespace, pys_runner, pys_shell
|
|
12
|
+
from .core.utils.module import remove_python_path
|
|
13
|
+
from .core.utils.path import getcwd, normpath, get_name_from_path
|
|
14
|
+
from .core.version import __version__
|
|
15
|
+
|
|
16
|
+
if PYGMENTS:
|
|
17
|
+
from pygments import highlight
|
|
18
|
+
from pygments.formatters import (
|
|
19
|
+
BBCodeFormatter, HtmlFormatter, LatexFormatter, TerminalFormatter, TerminalTrueColorFormatter,
|
|
20
|
+
Terminal256Formatter
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
FORMAT_PYGMENTS_MAP = {
|
|
24
|
+
'pm-bbcode': BBCodeFormatter,
|
|
25
|
+
'pm-html': HtmlFormatter,
|
|
26
|
+
'pm-latex': LatexFormatter,
|
|
27
|
+
'pm-terminal': TerminalFormatter,
|
|
28
|
+
'pm-true-terminal': TerminalTrueColorFormatter,
|
|
29
|
+
'pm-256-terminal': Terminal256Formatter
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
from argparse import OPTIONAL, REMAINDER, ArgumentParser
|
|
33
|
+
from os import environ
|
|
34
|
+
|
|
35
|
+
import sys
|
|
36
|
+
|
|
37
|
+
FORMAT_HIGHLIGHT_MAP = {
|
|
38
|
+
'html': HLFMT_HTML,
|
|
39
|
+
'ansi': HLFMT_ANSI,
|
|
40
|
+
'bbcode': HLFMT_BBCODE
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
EDITOR_MAP = {}
|
|
44
|
+
|
|
45
|
+
if GUI_SUPPORT:
|
|
46
|
+
EDITOR_MAP['gui'] = PysGUIEditor
|
|
47
|
+
if TERMINAL_SUPPORT:
|
|
48
|
+
EDITOR_MAP['terminal'] = PysTerminalEditor
|
|
49
|
+
|
|
50
|
+
parser = ArgumentParser(
|
|
51
|
+
prog=f'{get_name_from_path(sys.executable)} -m pyscript',
|
|
52
|
+
description=f'PyScript Launcher for Python Version {".".join(map(str, sys.version_info))}'
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
'-c', '--command',
|
|
57
|
+
type=str,
|
|
58
|
+
default=None,
|
|
59
|
+
help="Execute program from a string argument",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
'-d', '-O', '--debug',
|
|
64
|
+
action='store_true',
|
|
65
|
+
help="Set a debug flag, this will ignore assert statement. Check the flag is active with the __debug__ keyword"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if EDITOR_MAP:
|
|
69
|
+
parser.add_argument(
|
|
70
|
+
'-e', '--editor',
|
|
71
|
+
choices=tuple(EDITOR_MAP.keys()),
|
|
72
|
+
default=None,
|
|
73
|
+
help="Open the editor panel from a 'file'",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
'-i', '--inspect',
|
|
78
|
+
action='store_true',
|
|
79
|
+
help="Inspect interactively after running a code",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
parser.add_argument(
|
|
83
|
+
'-k', '--classic-line-shell',
|
|
84
|
+
action='store_true',
|
|
85
|
+
help="Use a classic command line shell"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
parser.add_argument(
|
|
89
|
+
'-l', '--highlight',
|
|
90
|
+
choices=tuple(FORMAT_HIGHLIGHT_MAP.keys()) + tuple(FORMAT_PYGMENTS_MAP.keys() if PYGMENTS else ()),
|
|
91
|
+
default=None,
|
|
92
|
+
help="Generate highlight code from a 'file'"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
parser.add_argument(
|
|
96
|
+
'-n', '--no-color',
|
|
97
|
+
action='store_true',
|
|
98
|
+
help="Suppress colored output"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
parser.add_argument(
|
|
102
|
+
'-r', '--py-recursion',
|
|
103
|
+
type=int,
|
|
104
|
+
default=None,
|
|
105
|
+
help="Set a Python recursion limit"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
parser.add_argument(
|
|
109
|
+
'-t', '--terminal',
|
|
110
|
+
action='store_true',
|
|
111
|
+
help="Configure terminal encoding to UTF-8 and enable ANSI escape code processing on Windows"
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
parser.add_argument(
|
|
115
|
+
'-q',
|
|
116
|
+
action='store_true',
|
|
117
|
+
help="Don't print version and copyright messages on interactive startup"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
parser.add_argument(
|
|
121
|
+
'-v', '-V', '--version',
|
|
122
|
+
action='version',
|
|
123
|
+
version=f"PyScript {__version__}",
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
parser.add_argument(
|
|
127
|
+
'-P',
|
|
128
|
+
action='store_true',
|
|
129
|
+
help="Don't prepend a potentially unsafe path to sys.path (python sys.path)"
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
parser.add_argument(
|
|
133
|
+
'file',
|
|
134
|
+
type=str,
|
|
135
|
+
nargs=OPTIONAL,
|
|
136
|
+
default=None,
|
|
137
|
+
help="File path to be executed"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
parser.add_argument(
|
|
141
|
+
'arg',
|
|
142
|
+
nargs=REMAINDER,
|
|
143
|
+
help="Remaining arguments stored in sys_module.argv (sys.argv)"
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def argument_error(argument, message):
|
|
147
|
+
parser.print_usage(sys.stderr)
|
|
148
|
+
parser.exit(2, f"{parser.prog}: error: argument {argument}: {message}\n")
|
|
149
|
+
|
|
150
|
+
args = parser.parse_args()
|
|
151
|
+
|
|
152
|
+
if args.terminal:
|
|
153
|
+
|
|
154
|
+
for fd in (sys.stdout, sys.stderr, sys.stdin):
|
|
155
|
+
try:
|
|
156
|
+
fd.reconfigure(encoding='utf-8')
|
|
157
|
+
except:
|
|
158
|
+
continue
|
|
159
|
+
|
|
160
|
+
if sys.platform == 'win32':
|
|
161
|
+
try:
|
|
162
|
+
import ctypes
|
|
163
|
+
kernel32 = ctypes.windll.kernel32
|
|
164
|
+
for i in (-11, -12, -10):
|
|
165
|
+
try:
|
|
166
|
+
kernel32.SetConsoleMode(kernel32.GetStdHandle(i), 7)
|
|
167
|
+
except:
|
|
168
|
+
continue
|
|
169
|
+
except:
|
|
170
|
+
pass
|
|
171
|
+
|
|
172
|
+
if args.file is None:
|
|
173
|
+
if EDITOR_MAP and args.editor:
|
|
174
|
+
argument_error('-e/--editor', "argument 'file' is required")
|
|
175
|
+
elif args.highlight:
|
|
176
|
+
argument_error('-l/--highlight', "argument 'file' is required")
|
|
177
|
+
|
|
178
|
+
if args.py_recursion is not None:
|
|
179
|
+
try:
|
|
180
|
+
sys.setrecursionlimit(args.py_recursion)
|
|
181
|
+
except BaseException as e:
|
|
182
|
+
argument_error('-r/--py-recursion', e)
|
|
183
|
+
|
|
184
|
+
code = 0
|
|
185
|
+
flags = DEFAULT
|
|
186
|
+
|
|
187
|
+
if args.debug:
|
|
188
|
+
flags |= DEBUG
|
|
189
|
+
if args.no_color or environ.get('NO_COLOR') is not None:
|
|
190
|
+
flags |= NO_COLOR
|
|
191
|
+
if args.classic_line_shell or environ.get(ENV_PYSCRIPT_CLASSIC_LINE_SHELL) is not None:
|
|
192
|
+
flags |= CLASSIC_LINE_SHELL
|
|
193
|
+
if args.q:
|
|
194
|
+
flags |= DONT_SHOW_BANNER_ON_SHELL
|
|
195
|
+
if args.P:
|
|
196
|
+
for cwd in {'', '.', getcwd()}:
|
|
197
|
+
remove_python_path(cwd)
|
|
198
|
+
|
|
199
|
+
pys_sys.argv = argv = ['', *args.arg]
|
|
200
|
+
|
|
201
|
+
if args.file is not None:
|
|
202
|
+
argv[0] = args.file
|
|
203
|
+
path = normpath(args.file)
|
|
204
|
+
|
|
205
|
+
try:
|
|
206
|
+
with open(path, 'r', encoding='utf-8') as file:
|
|
207
|
+
file = PysFileBuffer(file, path)
|
|
208
|
+
except FileNotFoundError:
|
|
209
|
+
if EDITOR_MAP and args.editor:
|
|
210
|
+
file = PysFileBuffer('', path)
|
|
211
|
+
else:
|
|
212
|
+
parser.error(f"can't open file {path!r}: No such file or directory")
|
|
213
|
+
except PermissionError:
|
|
214
|
+
parser.error(f"can't open file {path!r}: Permission denied")
|
|
215
|
+
except IsADirectoryError:
|
|
216
|
+
parser.error(f"can't open file {path!r}: Path is not a file")
|
|
217
|
+
except NotADirectoryError:
|
|
218
|
+
parser.error(f"can't open file {path!r}: Attempting to access directory from file")
|
|
219
|
+
except (OSError, IOError):
|
|
220
|
+
parser.error(f"can't open file {path!r}: Attempting to access a system directory or file")
|
|
221
|
+
except UnicodeDecodeError:
|
|
222
|
+
parser.error(f"can't read file {path!r}: Bad file")
|
|
223
|
+
except BaseException as e:
|
|
224
|
+
parser.error(f"file {path!r}: Unexpected error: {e}")
|
|
225
|
+
|
|
226
|
+
if EDITOR_MAP and args.editor:
|
|
227
|
+
try:
|
|
228
|
+
EDITOR_MAP[args.editor](file).run()
|
|
229
|
+
except BaseException as e:
|
|
230
|
+
argument_error('-e/--editor', e)
|
|
231
|
+
|
|
232
|
+
elif args.highlight:
|
|
233
|
+
try:
|
|
234
|
+
if args.highlight in FORMAT_HIGHLIGHT_MAP:
|
|
235
|
+
print(
|
|
236
|
+
pys_highlight(
|
|
237
|
+
source=file,
|
|
238
|
+
formatter=FORMAT_HIGHLIGHT_MAP[args.highlight]
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
else:
|
|
242
|
+
print(
|
|
243
|
+
highlight(
|
|
244
|
+
code=file.text,
|
|
245
|
+
lexer=PygmentsPyScriptLexer(),
|
|
246
|
+
formatter=FORMAT_PYGMENTS_MAP[args.highlight](style=PygmentsPyScriptStyle, full=True)
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
except BaseException as e:
|
|
250
|
+
argument_error('-l/--highlight', e)
|
|
251
|
+
|
|
252
|
+
else:
|
|
253
|
+
result = pys_runner(
|
|
254
|
+
file=file,
|
|
255
|
+
mode='exec',
|
|
256
|
+
symbol_table=_normalize_namespace(file, undefined),
|
|
257
|
+
flags=flags
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
code, _ = result.end_process()
|
|
261
|
+
|
|
262
|
+
if args.inspect and not (sys.stdout.closed or sys.stderr.closed):
|
|
263
|
+
if sys.stdin.closed:
|
|
264
|
+
print("Can't run interactive shell: sys.stdin closed", file=sys.stderr)
|
|
265
|
+
code = 1
|
|
266
|
+
else:
|
|
267
|
+
code = pys_shell(
|
|
268
|
+
globals=result.context.symbol_table,
|
|
269
|
+
flags=result.context.flags | DONT_SHOW_BANNER_ON_SHELL,
|
|
270
|
+
parser_flags=result.parser_flags
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
elif args.command is not None:
|
|
274
|
+
argv[0] = '-c'
|
|
275
|
+
|
|
276
|
+
file = PysFileBuffer(args.command, '<arg-command>')
|
|
277
|
+
result = pys_runner(
|
|
278
|
+
file=file,
|
|
279
|
+
mode='exec',
|
|
280
|
+
symbol_table=_normalize_namespace(file, undefined),
|
|
281
|
+
flags=flags
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
code, _ = result.end_process()
|
|
285
|
+
|
|
286
|
+
if args.inspect and not (sys.stdout.closed or sys.stderr.closed):
|
|
287
|
+
if sys.stdin.closed:
|
|
288
|
+
print("Can't run interactive shell: sys.stdin closed", file=sys.stderr)
|
|
289
|
+
code = 1
|
|
290
|
+
else:
|
|
291
|
+
code = pys_shell(
|
|
292
|
+
globals=result.context.symbol_table,
|
|
293
|
+
flags=result.context.flags | DONT_SHOW_BANNER_ON_SHELL,
|
|
294
|
+
parser_flags=result.parser_flags
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
else:
|
|
298
|
+
code = pys_shell(
|
|
299
|
+
globals=undefined,
|
|
300
|
+
flags=flags
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
sys.exit(code)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The Core of PyScript Implementations.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from . import (
|
|
6
|
+
analyzer,
|
|
7
|
+
bases,
|
|
8
|
+
buffer,
|
|
9
|
+
cache,
|
|
10
|
+
checks,
|
|
11
|
+
constants,
|
|
12
|
+
context,
|
|
13
|
+
editor,
|
|
14
|
+
exceptions,
|
|
15
|
+
handlers,
|
|
16
|
+
highlight,
|
|
17
|
+
interpreter,
|
|
18
|
+
lexer,
|
|
19
|
+
mapping,
|
|
20
|
+
nodes,
|
|
21
|
+
objects,
|
|
22
|
+
parser,
|
|
23
|
+
position,
|
|
24
|
+
pysbuiltins,
|
|
25
|
+
results,
|
|
26
|
+
runner,
|
|
27
|
+
shell,
|
|
28
|
+
symtab,
|
|
29
|
+
token,
|
|
30
|
+
utils,
|
|
31
|
+
version
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
__all__ = (
|
|
35
|
+
'analyzer',
|
|
36
|
+
'bases',
|
|
37
|
+
'buffer',
|
|
38
|
+
'cache',
|
|
39
|
+
'checks',
|
|
40
|
+
'constants',
|
|
41
|
+
'context',
|
|
42
|
+
'editor',
|
|
43
|
+
'exceptions',
|
|
44
|
+
'handlers',
|
|
45
|
+
'highlight',
|
|
46
|
+
'interpreter',
|
|
47
|
+
'lexer',
|
|
48
|
+
'mapping',
|
|
49
|
+
'nodes',
|
|
50
|
+
'objects',
|
|
51
|
+
'parser',
|
|
52
|
+
'position',
|
|
53
|
+
'pysbuiltins',
|
|
54
|
+
'results',
|
|
55
|
+
'runner',
|
|
56
|
+
'shell',
|
|
57
|
+
'symtab',
|
|
58
|
+
'token',
|
|
59
|
+
'utils',
|
|
60
|
+
'version'
|
|
61
|
+
)
|