token-utils 0.3.6__tar.gz → 0.3.8__tar.gz
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.
- {token_utils-0.3.6 → token_utils-0.3.8}/PKG-INFO +1 -1
- token_utils-0.3.8/docs/doctrees/environment.pickle +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/tips.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/tokenizing_methods.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/untokenizing.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/utils.doctree +0 -0
- token_utils-0.3.6/docs/html/.buildinfo.bak → token_utils-0.3.8/docs/html/.buildinfo +1 -1
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_modules/index.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_modules/token_utils/token_class.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_modules/token_utils/tokenizing.html +41 -75
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_modules/token_utils/utils.html +15 -12
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/tips.rst.txt +11 -9
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/untokenizing.rst.txt +28 -46
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/documentation_options.js +1 -1
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/about_tokens.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/custom_warnings.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/genindex.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/index.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/objects.inv +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/py-modindex.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/search.html +2 -2
- token_utils-0.3.8/docs/html/searchindex.js +1 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/tips.html +13 -11
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/todo.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/token_class.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/tokenizing_methods.html +4 -16
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/tutorial_prelude.html +2 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/untokenizing.html +30 -80
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/utils.html +4 -3
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/tips.rst +11 -9
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/untokenizing.rst +28 -46
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/__about__.py +1 -1
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/_py_tokenize.py +1 -2
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/_py_tokenize.pyi +13 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/tokenizing.py +37 -71
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/utils.py +15 -12
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/utils.pyi +1 -1
- token_utils-0.3.8/tests/add_decorator.py +24 -0
- token_utils-0.3.8/tests/decorator_example.txt +23 -0
- token_utils-0.3.8/tests/decorator_example_out.txt +19 -0
- token_utils-0.3.8/tests/factorial.py +40 -0
- token_utils-0.3.8/tests/nobreak.py +27 -0
- token_utils-0.3.8/tests/nobreak.txt +31 -0
- token_utils-0.3.8/tests/nobreak_out.txt +25 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/tests/test_utils.py +33 -0
- token_utils-0.3.6/docs/doctrees/environment.pickle +0 -0
- token_utils-0.3.6/docs/html/searchindex.js +0 -1
- {token_utils-0.3.6 → token_utils-0.3.8}/.flake8 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.gitignore +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.idea/.gitignore +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.idea/modules.xml +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.idea/token-utils.iml +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.idea/vcs.xml +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.idea/workspace.xml +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.nojekyll +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/.vscode/settings.json +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/LICENSE +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/README.md +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/ae.bat +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/Makefile +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/about_tokens.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/custom_warnings.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/index.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/todo.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/token_class.doctree +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/doctrees/tutorial_prelude.doctree +0 -0
- /token_utils-0.3.6/docs/html/.buildinfo → /token_utils-0.3.8/docs/html/.buildinfo.bak +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/.nojekyll +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_modules/token_utils/custom_warnings.html +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/about_tokens.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/custom_warnings.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/index.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/todo.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/token_class.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/tokenizing_methods.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/tutorial_prelude.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_sources/utils.rst.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/_sphinx_javascript_frameworks_compat.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/basic.css +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/badge_only.css +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/Roboto-Slab-Bold.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/Roboto-Slab-Bold.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/Roboto-Slab-Regular.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/Roboto-Slab-Regular.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/fontawesome-webfont.eot +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/fontawesome-webfont.svg +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/fontawesome-webfont.ttf +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/fontawesome-webfont.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/fontawesome-webfont.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-bold-italic.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-bold-italic.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-bold.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-bold.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-normal-italic.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-normal-italic.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-normal.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/fonts/lato-normal.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/css/theme.css +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/custom.css +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/doctools.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/file.png +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bold.eot +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bold.ttf +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bold.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bold.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bolditalic.eot +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bolditalic.ttf +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bolditalic.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-bolditalic.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-italic.eot +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-italic.ttf +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-italic.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-italic.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-regular.eot +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-regular.ttf +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-regular.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/Lato/lato-regular.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2 +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/jquery.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/js/badge_only.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/js/theme.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/js/versions.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/language_data.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/minus.png +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/plus.png +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/pygments.css +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/searchtools.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/sphinx-new-tab-link.css +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/html/_static/sphinx_highlight.js +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/make.bat +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/_static/custom.css +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/about_tokens.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/conf.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/custom_warnings.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/index.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/todo.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/token_class.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/tokenizing_methods.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/tutorial_prelude.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs/source/utils.rst +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/add_decorator.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/decimal_py.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/decimal_tok.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/decimal_tok2.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/decorator_example.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/factorial_1.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/factorial_2.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/inside_blocks.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/nobreak.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/nobreak.txt +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/docs_examples/view_stack.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/pypi_upload.bat +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/pyproject.toml +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/run_all_tests.bat +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/__about__.pyi +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/__init__.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/__init__.pyi +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/_token_plus.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/_token_plus.pyi +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/custom_warnings.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/custom_warnings.pyi +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/py.typed +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/token_class.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/token_class.pyi +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/src/token_utils/tokenizing.pyi +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/tests/__init__.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/tests/test_roundtrip.py +0 -0
- {token_utils-0.3.6 → token_utils-0.3.8}/tests/test_token_methods.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: token-utils
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
4
4
|
Summary: Convenient tools to deal with tokens.
|
|
5
5
|
Project-URL: Documentation, https://aroberge.github.io/token-utils/docs/html/
|
|
6
6
|
Project-URL: Issues, https://github.com/aroberge/token-utils/issues
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
# Sphinx build info version 1
|
|
2
2
|
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
|
|
3
|
-
config:
|
|
3
|
+
config: f132fb79544289f226bc9b5fb5cb2b7f
|
|
4
4
|
tags: 645f666f9bcd5a90fca523b33c5a78b7
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="utf-8" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
-
<title>Overview: module code — token-utils 0.3.
|
|
8
|
+
<title>Overview: module code — token-utils 0.3.7 documentation</title>
|
|
9
9
|
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=03e43079" />
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=9edc463e" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="../_static/sphinx-new-tab-link.css?v=d87cb1ac" />
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<script src="../_static/jquery.js?v=5d32c60e"></script>
|
|
16
16
|
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
17
|
-
<script src="../_static/documentation_options.js?v=
|
|
17
|
+
<script src="../_static/documentation_options.js?v=29d04658"></script>
|
|
18
18
|
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
|
19
19
|
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
20
20
|
<script src="../_static/js/theme.js"></script>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="utf-8" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
-
<title>token_utils.token_class — token-utils 0.3.
|
|
8
|
+
<title>token_utils.token_class — token-utils 0.3.7 documentation</title>
|
|
9
9
|
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=03e43079" />
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=9edc463e" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="../../_static/sphinx-new-tab-link.css?v=d87cb1ac" />
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<script src="../../_static/jquery.js?v=5d32c60e"></script>
|
|
16
16
|
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
17
|
-
<script src="../../_static/documentation_options.js?v=
|
|
17
|
+
<script src="../../_static/documentation_options.js?v=29d04658"></script>
|
|
18
18
|
<script src="../../_static/doctools.js?v=9bcbadda"></script>
|
|
19
19
|
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
20
20
|
<script src="../../_static/js/theme.js"></script>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="utf-8" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
-
<title>token_utils.tokenizing — token-utils 0.3.
|
|
8
|
+
<title>token_utils.tokenizing — token-utils 0.3.7 documentation</title>
|
|
9
9
|
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=03e43079" />
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=9edc463e" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="../../_static/sphinx-new-tab-link.css?v=d87cb1ac" />
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<script src="../../_static/jquery.js?v=5d32c60e"></script>
|
|
16
16
|
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
17
|
-
<script src="../../_static/documentation_options.js?v=
|
|
17
|
+
<script src="../../_static/documentation_options.js?v=29d04658"></script>
|
|
18
18
|
<script src="../../_static/doctools.js?v=9bcbadda"></script>
|
|
19
19
|
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
20
20
|
<script src="../../_static/js/theme.js"></script>
|
|
@@ -275,10 +275,7 @@
|
|
|
275
275
|
<div class="viewcode-block" id="untokenize">
|
|
276
276
|
<a class="viewcode-back" href="../../tokenizing_methods.html#token_utils.tokenizing.untokenize">[docs]</a>
|
|
277
277
|
<span class="k">def</span><span class="w"> </span><span class="nf">untokenize</span><span class="p">(</span><span class="n">tokens</span><span class="p">):</span>
|
|
278
|
-
<span class="w"> </span><span class="sd">"""
|
|
279
|
-
|
|
280
|
-
<span class="sd"> Adapted from https://github.com/myint/untokenize,</span>
|
|
281
|
-
<span class="sd"> Copyright (C) 2013-2018 Steven Myint, MIT License (same as this project).</span>
|
|
278
|
+
<span class="w"> </span><span class="sd">"""Returns a string built from tokens, or list of tokens.</span>
|
|
282
279
|
|
|
283
280
|
<span class="sd"> This is similar to Python's own tokenize.untokenize(), except that it</span>
|
|
284
281
|
<span class="sd"> preserves spacing between tokens, by using the line</span>
|
|
@@ -289,77 +286,15 @@
|
|
|
289
286
|
<span class="sd"> in the source code produced by untokenize.</span>
|
|
290
287
|
|
|
291
288
|
<span class="sd"> Thus ``source == untokenize(tokenize(source))``.</span>
|
|
292
|
-
|
|
293
|
-
<span class="sd"> Note: if you you modifying tokens from an original source:</span>
|
|
294
|
-
|
|
295
|
-
<span class="sd"> Instead of full token object, ``untokenize`` will accept simple</span>
|
|
296
|
-
<span class="sd"> strings; however, it will only insert them *as is* without taking them</span>
|
|
297
|
-
<span class="sd"> into account when it comes with figuring out spacing between tokens.</span>
|
|
298
|
-
|
|
299
|
-
<span class="sd"> It is often more effective to "mutate" a token string to insert new</span>
|
|
300
|
-
<span class="sd"> content.</span>
|
|
301
|
-
|
|
302
|
-
<span class="sd"> Finally, while token_utils only deals with sources as string,</span>
|
|
303
|
-
<span class="sd"> and doesn't do encoding, this function will drop tokens</span>
|
|
304
|
-
<span class="sd"> identified as being of type ``ENCODING``, which would mean that they</span>
|
|
305
|
-
<span class="sd"> came from another source.</span>
|
|
306
289
|
<span class="sd"> """</span>
|
|
307
|
-
<span class="
|
|
308
|
-
<span class="c1"># 1. We accumulate substrings in a list, rather than concatenating them</span>
|
|
309
|
-
<span class="c1"># as we go along</span>
|
|
310
|
-
<span class="c1"># 2. We allow the inclusion of pure strings as token, but without</span>
|
|
311
|
-
<span class="c1"># taking their length into consideration.</span>
|
|
312
|
-
<span class="c1"># 3. We accept lines of lines of tokens</span>
|
|
313
|
-
<span class="c1"># Begin code (for extraction by Sphinx)</span>
|
|
314
|
-
<span class="c1"># Allow both lists of Tokens or strings, or lists of lists of Tokens or strings</span>
|
|
315
|
-
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">list</span><span class="p">):</span>
|
|
316
|
-
<span class="n">tokens</span> <span class="o">=</span> <span class="p">[</span><span class="n">token</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">tokens</span> <span class="k">for</span> <span class="n">token</span> <span class="ow">in</span> <span class="n">line</span><span class="p">]</span>
|
|
317
|
-
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">Token</span><span class="p">,</span> <span class="nb">str</span><span class="p">))</span>
|
|
318
|
-
|
|
319
|
-
<span class="n">words</span> <span class="o">=</span> <span class="p">[]</span>
|
|
320
|
-
<span class="n">previous_line</span> <span class="o">=</span> <span class="s2">""</span>
|
|
321
|
-
<span class="n">last_row</span> <span class="o">=</span> <span class="mi">0</span>
|
|
322
|
-
<span class="n">last_column</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
|
|
323
|
-
<span class="n">last_non_whitespace_token_type</span> <span class="o">=</span> <span class="kc">None</span>
|
|
324
|
-
<span class="k">for</span> <span class="n">token</span> <span class="ow">in</span> <span class="n">tokens</span><span class="p">:</span>
|
|
325
|
-
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">token</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
|
|
326
|
-
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
|
|
327
|
-
<span class="k">continue</span>
|
|
328
|
-
<span class="k">if</span> <span class="n">token</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">_py_tokenize</span><span class="o">.</span><span class="n">ENCODING</span><span class="p">:</span>
|
|
329
|
-
<span class="k">continue</span>
|
|
330
|
-
|
|
331
|
-
<span class="c1"># Preserve escaped newlines.</span>
|
|
332
|
-
<span class="k">if</span> <span class="p">(</span>
|
|
333
|
-
<span class="n">last_non_whitespace_token_type</span> <span class="o">!=</span> <span class="n">_py_tokenize</span><span class="o">.</span><span class="n">COMMENT</span>
|
|
334
|
-
<span class="ow">and</span> <span class="n">token</span><span class="o">.</span><span class="n">start_row</span> <span class="o">></span> <span class="n">last_row</span>
|
|
335
|
-
<span class="ow">and</span> <span class="n">previous_line</span><span class="o">.</span><span class="n">endswith</span><span class="p">((</span><span class="s2">"</span><span class="se">\\\n</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"</span><span class="se">\\\r\n</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"</span><span class="se">\\\r</span><span class="s2">"</span><span class="p">))</span>
|
|
336
|
-
<span class="p">):</span>
|
|
337
|
-
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">previous_line</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">previous_line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s2">" </span><span class="se">\t\n\r\\</span><span class="s2">"</span><span class="p">))</span> <span class="p">:])</span>
|
|
338
|
-
|
|
339
|
-
<span class="c1"># Preserve spacing.</span>
|
|
340
|
-
<span class="k">if</span> <span class="n">token</span><span class="o">.</span><span class="n">start_row</span> <span class="o">></span> <span class="n">last_row</span><span class="p">:</span>
|
|
341
|
-
<span class="n">last_column</span> <span class="o">=</span> <span class="mi">0</span>
|
|
342
|
-
<span class="k">if</span> <span class="n">token</span><span class="o">.</span><span class="n">start_col</span> <span class="o">></span> <span class="n">last_column</span><span class="p">:</span>
|
|
343
|
-
<span class="c1"># Insert the content that was skipped between tokens</span>
|
|
344
|
-
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">token</span><span class="o">.</span><span class="n">line</span><span class="p">[</span><span class="n">last_column</span> <span class="p">:</span> <span class="n">token</span><span class="o">.</span><span class="n">start_col</span><span class="p">])</span>
|
|
345
|
-
|
|
346
|
-
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">token</span><span class="o">.</span><span class="n">string</span><span class="p">)</span>
|
|
347
|
-
|
|
348
|
-
<span class="n">previous_line</span> <span class="o">=</span> <span class="n">token</span><span class="o">.</span><span class="n">line</span>
|
|
349
|
-
<span class="n">last_row</span> <span class="o">=</span> <span class="n">token</span><span class="o">.</span><span class="n">end_row</span>
|
|
350
|
-
<span class="n">last_column</span> <span class="o">=</span> <span class="n">token</span><span class="o">.</span><span class="n">end_col</span>
|
|
351
|
-
<span class="k">if</span> <span class="ow">not</span> <span class="n">token</span><span class="o">.</span><span class="n">is_space</span><span class="p">():</span>
|
|
352
|
-
<span class="n">last_non_whitespace_token_type</span> <span class="o">=</span> <span class="n">token</span><span class="o">.</span><span class="n">type</span>
|
|
353
|
-
|
|
354
|
-
<span class="k">return</span> <span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">words</span><span class="p">)</span></div>
|
|
290
|
+
<span class="k">return</span> <span class="n">_untokenize</span><span class="p">(</span><span class="n">tokens</span><span class="p">)</span></div>
|
|
355
291
|
|
|
356
|
-
<span class="c1"># End code (for extraction by Sphinx)</span>
|
|
357
292
|
|
|
358
293
|
|
|
359
294
|
<div class="viewcode-block" id="stringify">
|
|
360
295
|
<a class="viewcode-back" href="../../tokenizing_methods.html#token_utils.tokenizing.stringify">[docs]</a>
|
|
361
296
|
<span class="k">def</span><span class="w"> </span><span class="nf">stringify</span><span class="p">(</span><span class="n">tokens</span><span class="p">,</span> <span class="n">remove_comments</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
|
362
|
-
<span class="w"> </span><span class="sd">"""Returns a string built from tokens.</span>
|
|
297
|
+
<span class="w"> </span><span class="sd">"""Returns a string built from tokens, or list of tokens.</span>
|
|
363
298
|
|
|
364
299
|
<span class="sd"> It is somewhat similar to untokenize except that it doesn't add any</span>
|
|
365
300
|
<span class="sd"> missing information from tokens that might have been removed,</span>
|
|
@@ -382,15 +317,42 @@
|
|
|
382
317
|
|
|
383
318
|
<span class="sd"> ideas.utils.remove_comments(source)</span>
|
|
384
319
|
<span class="sd"> """</span>
|
|
320
|
+
<span class="k">return</span> <span class="n">_untokenize</span><span class="p">(</span>
|
|
321
|
+
<span class="n">tokens</span><span class="p">,</span> <span class="n">recover_missing_text</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">remove_comments</span><span class="o">=</span><span class="n">remove_comments</span>
|
|
322
|
+
<span class="p">)</span></div>
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
<span class="k">def</span><span class="w"> </span><span class="nf">_untokenize</span><span class="p">(</span><span class="n">tokens</span><span class="p">,</span> <span class="n">recover_missing_text</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">remove_comments</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
|
327
|
+
<span class="w"> </span><span class="sd">"""Private function: do not use. Use either untokenize() or stringify()."""</span>
|
|
328
|
+
|
|
329
|
+
<span class="c1"># This was adapted from https://github.com/myint/untokenize,</span>
|
|
330
|
+
<span class="c1"># Copyright (C) 2013-2018 Steven Myint, MIT License (same as this project).</span>
|
|
331
|
+
<span class="c1"># Changes from original:</span>
|
|
332
|
+
<span class="c1"># 1. We accumulate substrings in a list, rather than concatenating them</span>
|
|
333
|
+
<span class="c1"># as we go along</span>
|
|
334
|
+
<span class="c1"># 2. We allow the inclusion of pure strings as token, but without</span>
|
|
335
|
+
<span class="c1"># taking their length into consideration.</span>
|
|
336
|
+
<span class="c1"># 3. We accept lines of lines of tokens</span>
|
|
337
|
+
<span class="c1"># 4. tokens are token_utils tokens instead of Python tokenize tokens.</span>
|
|
338
|
+
<span class="c1"># 5. We give the possibility of replacing missing content by spaces</span>
|
|
339
|
+
<span class="c1"># instead of retrieving that content by using the line attribute of tokens.</span>
|
|
340
|
+
<span class="c1"># 6. We give the possibility of removing comments; this is only possible</span>
|
|
341
|
+
<span class="c1"># when we replace the missing content by spaces, otherwise the comments</span>
|
|
342
|
+
<span class="c1"># would be recovered even if we attempt to not include comments tokens.</span>
|
|
343
|
+
|
|
344
|
+
<span class="k">if</span> <span class="n">remove_comments</span> <span class="ow">and</span> <span class="n">recover_missing_text</span><span class="p">:</span>
|
|
345
|
+
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Incompatible values in private function _untokenize()."</span><span class="p">)</span>
|
|
346
|
+
|
|
385
347
|
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">list</span><span class="p">):</span>
|
|
386
348
|
<span class="n">tokens</span> <span class="o">=</span> <span class="p">[</span><span class="n">token</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">tokens</span> <span class="k">for</span> <span class="n">token</span> <span class="ow">in</span> <span class="n">line</span><span class="p">]</span>
|
|
349
|
+
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="n">Token</span><span class="p">,</span> <span class="nb">str</span><span class="p">))</span>
|
|
387
350
|
|
|
388
351
|
<span class="n">words</span> <span class="o">=</span> <span class="p">[]</span>
|
|
389
352
|
<span class="n">previous_line</span> <span class="o">=</span> <span class="s2">""</span>
|
|
390
353
|
<span class="n">last_row</span> <span class="o">=</span> <span class="mi">0</span>
|
|
391
354
|
<span class="n">last_column</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
|
|
392
355
|
<span class="n">last_non_whitespace_token_type</span> <span class="o">=</span> <span class="kc">None</span>
|
|
393
|
-
|
|
394
356
|
<span class="k">for</span> <span class="n">token</span> <span class="ow">in</span> <span class="n">tokens</span><span class="p">:</span>
|
|
395
357
|
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">token</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
|
|
396
358
|
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
|
|
@@ -412,9 +374,14 @@
|
|
|
412
374
|
<span class="c1"># Preserve spacing.</span>
|
|
413
375
|
<span class="k">if</span> <span class="n">token</span><span class="o">.</span><span class="n">start_row</span> <span class="o">></span> <span class="n">last_row</span><span class="p">:</span>
|
|
414
376
|
<span class="n">last_column</span> <span class="o">=</span> <span class="mi">0</span>
|
|
415
|
-
|
|
377
|
+
|
|
378
|
+
<span class="k">if</span> <span class="n">recover_missing_text</span><span class="p">:</span>
|
|
379
|
+
<span class="k">if</span> <span class="n">token</span><span class="o">.</span><span class="n">start_col</span> <span class="o">></span> <span class="n">last_column</span><span class="p">:</span>
|
|
380
|
+
<span class="c1"># Insert the content that was skipped between tokens</span>
|
|
381
|
+
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">token</span><span class="o">.</span><span class="n">line</span><span class="p">[</span><span class="n">last_column</span> <span class="p">:</span> <span class="n">token</span><span class="o">.</span><span class="n">start_col</span><span class="p">])</span>
|
|
382
|
+
<span class="k">elif</span> <span class="n">token</span><span class="o">.</span><span class="n">start_col</span> <span class="o">></span> <span class="n">last_column</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">token</span><span class="o">.</span><span class="n">is_space</span><span class="p">():</span>
|
|
416
383
|
<span class="c1"># Insert spaces instead of the content that was skipped between tokens</span>
|
|
417
|
-
<span class="c1"># except at the end of line before a NL or
|
|
384
|
+
<span class="c1"># except at the end of line before a NL, NEWLINE, or ENDMARKER token</span>
|
|
418
385
|
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">" "</span> <span class="o">*</span> <span class="p">(</span><span class="n">token</span><span class="o">.</span><span class="n">start_col</span> <span class="o">-</span> <span class="n">last_column</span><span class="p">))</span>
|
|
419
386
|
|
|
420
387
|
<span class="n">words</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">token</span><span class="o">.</span><span class="n">string</span><span class="p">)</span>
|
|
@@ -425,8 +392,7 @@
|
|
|
425
392
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">token</span><span class="o">.</span><span class="n">is_space</span><span class="p">():</span>
|
|
426
393
|
<span class="n">last_non_whitespace_token_type</span> <span class="o">=</span> <span class="n">token</span><span class="o">.</span><span class="n">type</span>
|
|
427
394
|
|
|
428
|
-
<span class="k">return</span> <span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">words</span><span class="p">)</span
|
|
429
|
-
|
|
395
|
+
<span class="k">return</span> <span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">words</span><span class="p">)</span>
|
|
430
396
|
|
|
431
397
|
|
|
432
398
|
<div class="viewcode-block" id="print_tokens">
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="utf-8" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
-
<title>token_utils.utils — token-utils 0.3.
|
|
8
|
+
<title>token_utils.utils — token-utils 0.3.7 documentation</title>
|
|
9
9
|
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=03e43079" />
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=9edc463e" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="../../_static/sphinx-new-tab-link.css?v=d87cb1ac" />
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<script src="../../_static/jquery.js?v=5d32c60e"></script>
|
|
16
16
|
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
17
|
-
<script src="../../_static/documentation_options.js?v=
|
|
17
|
+
<script src="../../_static/documentation_options.js?v=29d04658"></script>
|
|
18
18
|
<script src="../../_static/doctools.js?v=9bcbadda"></script>
|
|
19
19
|
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
20
20
|
<script src="../../_static/js/theme.js"></script>
|
|
@@ -154,20 +154,23 @@
|
|
|
154
154
|
<div class="viewcode-block" id="IndentStack">
|
|
155
155
|
<a class="viewcode-back" href="../../utils.html#token_utils.utils.IndentStack">[docs]</a>
|
|
156
156
|
<span class="k">class</span><span class="w"> </span><span class="nc">IndentStack</span><span class="p">:</span>
|
|
157
|
-
<span class="w"> </span><span class="sd">"""
|
|
157
|
+
<span class="w"> </span><span class="sd">"""Class designed to help keep track of indentation associated with the use</span>
|
|
158
|
+
<span class="sd"> of specific keywords."""</span>
|
|
158
159
|
|
|
159
160
|
<span class="c1"># In Python, the following keywords, or soft keywords, can signal the introduction</span>
|
|
160
161
|
<span class="c1"># of an indented block::</span>
|
|
161
162
|
|
|
162
|
-
<span class="c1"># class, def, if/elif/else, for/else, try/except/else/finally, while/else
|
|
163
|
+
<span class="c1"># class, def, if/elif/else, for/else, try/except/else/finally, while/else,</span>
|
|
164
|
+
<span class="c1"># with, match, case</span>
|
|
163
165
|
|
|
164
|
-
<span class="c1"># For some code analysis or code modification, it might be very useful
|
|
165
|
-
<span class="c1"># of such keywords when they introduce a change in indentation
|
|
166
|
-
<span class="c1">#
|
|
166
|
+
<span class="c1"># For some code analysis or code modification, it might be very useful to track</span>
|
|
167
|
+
<span class="c1"># of such keywords when they introduce a change in indentation.</span>
|
|
168
|
+
<span class="c1"># When they do so, and ignoring end of line comments,</span>
|
|
169
|
+
<span class="c1"># they will appear as the first non-space token</span>
|
|
167
170
|
<span class="c1"># on a **logical line** terminated by a colon ``:``.</span>
|
|
168
|
-
<span class="c1"># If we use token-utils' ``get_logical_lines()`` to analyze some source code
|
|
169
|
-
<span class="c1"># of each such line will always be a ``NEWLINE`` token
|
|
170
|
-
<span class="c1">#
|
|
171
|
+
<span class="c1"># If we use token-utils' ``get_logical_lines()`` to analyze some source code,</span>
|
|
172
|
+
<span class="c1"># the last token of each such line will always be a ``NEWLINE`` token,</span>
|
|
173
|
+
<span class="c1"># preceded by a colon.</span>
|
|
171
174
|
<div class="viewcode-block" id="IndentStack.__init__">
|
|
172
175
|
<a class="viewcode-back" href="../../utils.html#token_utils.utils.IndentStack.__init__">[docs]</a>
|
|
173
176
|
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
@@ -283,7 +286,7 @@
|
|
|
283
286
|
<span class="c1"># beginning of an indented block. So, we only care to see if it signal</span>
|
|
284
287
|
<span class="c1"># that we are leaving an indented block and dedenting the code</span>
|
|
285
288
|
|
|
286
|
-
<span class="k">if</span> <span class="ow">not</span> <span class="n">indenting_line</span><span class="p">:</span> <span class="c1">#
|
|
289
|
+
<span class="k">if</span> <span class="ow">not</span> <span class="n">indenting_line</span><span class="p">:</span> <span class="c1"># perhaps dedenting is occuring</span>
|
|
287
290
|
<span class="n">popped</span> <span class="o">=</span> <span class="mi">0</span>
|
|
288
291
|
<span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="p">:</span>
|
|
289
292
|
<span class="n">top_item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
|
|
@@ -301,7 +304,7 @@
|
|
|
301
304
|
<span class="k">if</span> <span class="n">popped</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span>
|
|
302
305
|
<span class="k">return</span> <span class="n">top_item</span>
|
|
303
306
|
<span class="k">else</span><span class="p">:</span>
|
|
304
|
-
<span class="k">return</span> <span class="n">NULL</span>
|
|
307
|
+
<span class="k">return</span> <span class="n">NULL</span> <span class="c1"># no change: dedenting did not occur</span>
|
|
305
308
|
<span class="k">return</span> <span class="n">NULL</span>
|
|
306
309
|
|
|
307
310
|
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="p">:</span>
|
|
@@ -42,13 +42,15 @@ the following:
|
|
|
42
42
|
- ``split_at_token()``, which is useful when changes are needed in two distant
|
|
43
43
|
parts of a list of tokens.
|
|
44
44
|
|
|
45
|
-
- ``add_operator()``, which is useful for exploring potential addition to Python's syntax
|
|
45
|
+
- ``add_operator()``, which is useful for exploring potential addition to Python's syntax
|
|
46
|
+
and simplify the analysis as previously separate Python tokens can be combined
|
|
47
|
+
into a single token.
|
|
46
48
|
|
|
47
49
|
In addition, the ``Token`` class has well over 30 different methods which are very useful
|
|
48
50
|
to identify types of tokens (and more) in a very readable way.
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
In what follows, I
|
|
53
|
+
In what follows, I briefly demonstrate how to use these functions,
|
|
52
54
|
using examples of modifying Python's syntax.
|
|
53
55
|
|
|
54
56
|
|
|
@@ -99,14 +101,14 @@ be really useful to add new operators to the tokenizer.
|
|
|
99
101
|
We can see that, not only ``!`` is a valid operator token, but it is also
|
|
100
102
|
recognized as such by the ``Token`` method ``is_operator()``.
|
|
101
103
|
The function ``add_operator()`` returned ``True``. If we were to add
|
|
102
|
-
a string already known to be an operator,
|
|
103
|
-
with no negative consequence.
|
|
104
|
+
a string already known to be an operator, ``add_operator()``
|
|
105
|
+
would return ``False``, with no negative consequence.
|
|
104
106
|
|
|
105
107
|
.. sidebar:: '!' in Python 3.12+
|
|
106
108
|
|
|
107
109
|
For Python 3.12+, if you use Python's ``tokenize``
|
|
108
110
|
module directly, you will see that ``!``
|
|
109
|
-
is defined as an operator.
|
|
111
|
+
is already defined as an operator.
|
|
110
112
|
|
|
111
113
|
While Python does not care about spaces between tokens, humans do.
|
|
112
114
|
For the mathematically inclined, it wouldn't be appropriate to write something
|
|
@@ -119,8 +121,8 @@ require ``!`` to come **immediately after** either a variable name (identifier)
|
|
|
119
121
|
or an integer; by 'immediately after', we mean no space between the two
|
|
120
122
|
tokens.
|
|
121
123
|
|
|
122
|
-
Here is how we can do it, using token-utils' ``
|
|
123
|
-
of ``
|
|
124
|
+
Here is how we can do it, using token-utils' ``immediately_before()`` instead
|
|
125
|
+
of ``immediately_after()`` as it looks more natural in this example.
|
|
124
126
|
|
|
125
127
|
.. literalinclude:: ../../docs_examples/factorial_1.py
|
|
126
128
|
|
|
@@ -188,7 +190,7 @@ Here's a sample session::
|
|
|
188
190
|
[ ] True
|
|
189
191
|
|
|
190
192
|
Going back to our factorial: in addition to appearing after
|
|
191
|
-
integers or variable names, the factorial symbol, ``!``,
|
|
193
|
+
integers or variable names, in mathematics, the factorial symbol, ``!``,
|
|
192
194
|
can appear after a closing parenthesis, ``)``,
|
|
193
195
|
as in ``(n + 1)!``, for example.
|
|
194
196
|
We can modify our ``make_factorial()`` function to include
|
|
@@ -203,7 +205,7 @@ like the following::
|
|
|
203
205
|
A B C D E ( a b c )!
|
|
204
206
|
|
|
205
207
|
If we proceed to add tokens as we find them to a ``new_tokens`` list,
|
|
206
|
-
when we arrive at ``)!``, we
|
|
208
|
+
when we arrive at ``)!``, we have to go backwards, retrieve
|
|
207
209
|
all the previously added tokens (``a b c``), until we find the
|
|
208
210
|
right open parenthesis, do the appropriate modification and add back
|
|
209
211
|
the extracted material. This can actually be done easily using
|
|
@@ -49,33 +49,25 @@ and the second **begins at column 8**. For both tokens, the
|
|
|
49
49
|
|
|
50
50
|
.. sidebar:: Original version
|
|
51
51
|
|
|
52
|
-
`The original version <https://github.com/myint/untokenize>`_
|
|
53
|
-
|
|
52
|
+
`The original untokenize() version <https://github.com/myint/untokenize>`_
|
|
53
|
+
designed to work with Python's tokenize tokens and which we
|
|
54
|
+
modified, was created in 2013, is currently unmaintained and apparently
|
|
54
55
|
can no longer be installed from Pypi as it is uses
|
|
55
56
|
an old ``setup.py`` version.
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
When tokenizing a source code, Python's tokenizer consider the
|
|
59
|
+
space between tokens as irrelevant. However, the entire content
|
|
60
|
+
of a line in which a token is found is stored in the ``line``
|
|
61
|
+
attribute of a token. We can use that information to retrieve
|
|
62
|
+
the content, such as number of space and tab characters,
|
|
63
|
+
that was present in the original source and put it back
|
|
64
|
+
between each tokens when we convert the source from tokens
|
|
65
|
+
back into a string.
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
content into an original source.
|
|
69
|
-
|
|
70
|
-
.. literalinclude:: ../../src/token_utils/tokenizing.py
|
|
71
|
-
:language: python
|
|
72
|
-
:start-after: # Begin code (for extraction by Sphinx)
|
|
73
|
-
:end-before: # End code (for extraction by Sphinx)
|
|
74
|
-
:linenos:
|
|
75
|
-
:emphasize-lines: 12-14, 29-31, 36
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Let's focus on the following for the example we just saw.
|
|
67
|
+
However, this can cause some problems as we in the
|
|
68
|
+
example above. Let's focus on the following for that
|
|
69
|
+
example and write down a simplfied version of the
|
|
70
|
+
code that is executed.
|
|
79
71
|
|
|
80
72
|
.. code-block:: none
|
|
81
73
|
|
|
@@ -83,27 +75,19 @@ Let's focus on the following for the example we just saw.
|
|
|
83
75
|
( ).....( )
|
|
84
76
|
3 8
|
|
85
77
|
|
|
86
|
-
...
|
|
87
78
|
if token.start_col > last_column:
|
|
88
79
|
# Insert the content that was skipped between tokens
|
|
89
80
|
words.append(token.line[last_column : token.start_col])
|
|
90
|
-
...
|
|
91
81
|
|
|
82
|
+
# this translates as
|
|
92
83
|
if 8 > 3:
|
|
93
|
-
words.append(line[3:8])
|
|
84
|
+
words.append(line[3:8]) # --> ' two '
|
|
94
85
|
|
|
95
86
|
Now we see why ``two`` was included in the untokenized output
|
|
96
87
|
even though we removed the token having it as a string.
|
|
97
88
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.. code-block::
|
|
101
|
-
|
|
102
|
-
...
|
|
103
|
-
if isinstance(token, str):
|
|
104
|
-
words.append(token)
|
|
105
|
-
continue
|
|
106
|
-
|
|
89
|
+
Note that, in addition to working with tokens,
|
|
90
|
+
we also allow the insertion of normal string.
|
|
107
91
|
So, in order to modify the source code, there are two
|
|
108
92
|
ways to proceed when using ``untokenize()`` to recover modified source:
|
|
109
93
|
|
|
@@ -154,7 +138,7 @@ Let's use it::
|
|
|
154
138
|
Inserting tokens?
|
|
155
139
|
------------------
|
|
156
140
|
|
|
157
|
-
What if we were to insert tokens like the example in the Python documentation
|
|
141
|
+
What if we were to insert tokens like the example in the Python documentation?
|
|
158
142
|
|
|
159
143
|
We can create additional tokens with token-utils in a fairly simple way::
|
|
160
144
|
|
|
@@ -199,7 +183,8 @@ why the weird-looking result is produced, and why this is definitely not recomme
|
|
|
199
183
|
About stringify()
|
|
200
184
|
-----------------
|
|
201
185
|
|
|
202
|
-
``stringify()`` is nearly identical to ``untokenize()``. However, instead of
|
|
186
|
+
``stringify()`` is nearly identical to ``untokenize()``. However, instead of
|
|
187
|
+
effectively doing::
|
|
203
188
|
|
|
204
189
|
...
|
|
205
190
|
if token.start_col > last_column:
|
|
@@ -207,26 +192,23 @@ About stringify()
|
|
|
207
192
|
words.append(token.line[last_column : token.start_col])
|
|
208
193
|
...
|
|
209
194
|
|
|
210
|
-
it
|
|
195
|
+
it does something like the following::
|
|
211
196
|
|
|
212
|
-
|
|
213
|
-
if token.start_col > last_column and not token.is_space():
|
|
197
|
+
if token.start_col > last_column:
|
|
214
198
|
# Insert spaces instead of the content that was skipped between tokens
|
|
215
|
-
# except at the end of line before a NL or NEWLINE token
|
|
216
199
|
words.append(" " * (token.start_col - last_column))
|
|
217
|
-
...
|
|
218
200
|
|
|
219
201
|
Thus, as long as one does not care about tab characters being converted into single space
|
|
220
202
|
characters, one can **remove** tokens safely, and their content will not be
|
|
221
203
|
reinserted by ``stringify()``.
|
|
222
204
|
|
|
223
|
-
|
|
224
|
-
it returns a source with end of line comments removed.
|
|
225
|
-
|
|
226
|
-
Here's the result using ``stringify()``::
|
|
205
|
+
Here's the result of inserting tokens using ``stringify()``::
|
|
227
206
|
|
|
228
207
|
>>> stringify(tokens)
|
|
229
208
|
'one | two | three | '
|
|
230
209
|
|
|
231
210
|
While ``stringify()`` "does the right thing" when adding tokens, it is usually
|
|
232
211
|
preferable to simply add ordinary strings.
|
|
212
|
+
|
|
213
|
+
Note that ``stringify()`` also has an extra parameter, ``remove_comments=False``.
|
|
214
|
+
If it is set to ``True``, ``stringify()`` returns a source with end of line comments removed.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
7
|
|
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
9
|
-
<title>About tokens: Python vs token-utils — token-utils 0.3.
|
|
9
|
+
<title>About tokens: Python vs token-utils — token-utils 0.3.7 documentation</title>
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=9edc463e" />
|
|
12
12
|
<link rel="stylesheet" type="text/css" href="_static/sphinx-new-tab-link.css?v=d87cb1ac" />
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<script src="_static/jquery.js?v=5d32c60e"></script>
|
|
17
17
|
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
18
|
-
<script src="_static/documentation_options.js?v=
|
|
18
|
+
<script src="_static/documentation_options.js?v=29d04658"></script>
|
|
19
19
|
<script src="_static/doctools.js?v=9bcbadda"></script>
|
|
20
20
|
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
21
21
|
<script src="_static/js/theme.js"></script>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
7
|
|
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
9
|
-
<title>Custom warnings — token-utils 0.3.
|
|
9
|
+
<title>Custom warnings — token-utils 0.3.7 documentation</title>
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=9edc463e" />
|
|
12
12
|
<link rel="stylesheet" type="text/css" href="_static/sphinx-new-tab-link.css?v=d87cb1ac" />
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<script src="_static/jquery.js?v=5d32c60e"></script>
|
|
17
17
|
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
18
|
-
<script src="_static/documentation_options.js?v=
|
|
18
|
+
<script src="_static/documentation_options.js?v=29d04658"></script>
|
|
19
19
|
<script src="_static/doctools.js?v=9bcbadda"></script>
|
|
20
20
|
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
21
21
|
<script src="_static/js/theme.js"></script>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="utf-8" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
-
<title>Index — token-utils 0.3.
|
|
8
|
+
<title>Index — token-utils 0.3.7 documentation</title>
|
|
9
9
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=9edc463e" />
|
|
11
11
|
<link rel="stylesheet" type="text/css" href="_static/sphinx-new-tab-link.css?v=d87cb1ac" />
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<script src="_static/jquery.js?v=5d32c60e"></script>
|
|
16
16
|
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
17
|
-
<script src="_static/documentation_options.js?v=
|
|
17
|
+
<script src="_static/documentation_options.js?v=29d04658"></script>
|
|
18
18
|
<script src="_static/doctools.js?v=9bcbadda"></script>
|
|
19
19
|
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
20
20
|
<script src="_static/js/theme.js"></script>
|