token-utils 0.3.6__tar.gz → 0.3.7__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.
Files changed (176) hide show
  1. {token_utils-0.3.6 → token_utils-0.3.7}/PKG-INFO +1 -1
  2. token_utils-0.3.7/docs/doctrees/environment.pickle +0 -0
  3. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/tips.doctree +0 -0
  4. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/tokenizing_methods.doctree +0 -0
  5. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/untokenizing.doctree +0 -0
  6. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/utils.doctree +0 -0
  7. token_utils-0.3.6/docs/html/.buildinfo.bak → token_utils-0.3.7/docs/html/.buildinfo +1 -1
  8. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_modules/index.html +2 -2
  9. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_modules/token_utils/token_class.html +2 -2
  10. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_modules/token_utils/tokenizing.html +41 -75
  11. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_modules/token_utils/utils.html +15 -12
  12. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/tips.rst.txt +11 -9
  13. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/untokenizing.rst.txt +28 -46
  14. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/documentation_options.js +1 -1
  15. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/about_tokens.html +2 -2
  16. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/custom_warnings.html +2 -2
  17. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/genindex.html +2 -2
  18. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/index.html +2 -2
  19. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/objects.inv +0 -0
  20. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/py-modindex.html +2 -2
  21. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/search.html +2 -2
  22. token_utils-0.3.7/docs/html/searchindex.js +1 -0
  23. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/tips.html +13 -11
  24. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/todo.html +2 -2
  25. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/token_class.html +2 -2
  26. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/tokenizing_methods.html +4 -16
  27. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/tutorial_prelude.html +2 -2
  28. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/untokenizing.html +30 -80
  29. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/utils.html +4 -3
  30. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/tips.rst +11 -9
  31. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/untokenizing.rst +28 -46
  32. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/__about__.py +1 -1
  33. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/_py_tokenize.py +1 -2
  34. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/_py_tokenize.pyi +13 -0
  35. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/tokenizing.py +37 -71
  36. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/utils.py +13 -10
  37. token_utils-0.3.7/tests/add_decorator.py +24 -0
  38. token_utils-0.3.7/tests/decorator_example.txt +23 -0
  39. token_utils-0.3.7/tests/decorator_example_out.txt +19 -0
  40. token_utils-0.3.7/tests/factorial.py +40 -0
  41. token_utils-0.3.7/tests/nobreak.py +27 -0
  42. token_utils-0.3.7/tests/nobreak.txt +31 -0
  43. token_utils-0.3.7/tests/nobreak_out.txt +25 -0
  44. {token_utils-0.3.6 → token_utils-0.3.7}/tests/test_utils.py +33 -0
  45. token_utils-0.3.6/docs/doctrees/environment.pickle +0 -0
  46. token_utils-0.3.6/docs/html/searchindex.js +0 -1
  47. {token_utils-0.3.6 → token_utils-0.3.7}/.flake8 +0 -0
  48. {token_utils-0.3.6 → token_utils-0.3.7}/.gitignore +0 -0
  49. {token_utils-0.3.6 → token_utils-0.3.7}/.idea/.gitignore +0 -0
  50. {token_utils-0.3.6 → token_utils-0.3.7}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
  51. {token_utils-0.3.6 → token_utils-0.3.7}/.idea/modules.xml +0 -0
  52. {token_utils-0.3.6 → token_utils-0.3.7}/.idea/token-utils.iml +0 -0
  53. {token_utils-0.3.6 → token_utils-0.3.7}/.idea/vcs.xml +0 -0
  54. {token_utils-0.3.6 → token_utils-0.3.7}/.idea/workspace.xml +0 -0
  55. {token_utils-0.3.6 → token_utils-0.3.7}/.nojekyll +0 -0
  56. {token_utils-0.3.6 → token_utils-0.3.7}/.vscode/settings.json +0 -0
  57. {token_utils-0.3.6 → token_utils-0.3.7}/LICENSE +0 -0
  58. {token_utils-0.3.6 → token_utils-0.3.7}/README.md +0 -0
  59. {token_utils-0.3.6 → token_utils-0.3.7}/ae.bat +0 -0
  60. {token_utils-0.3.6 → token_utils-0.3.7}/docs/Makefile +0 -0
  61. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/about_tokens.doctree +0 -0
  62. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/custom_warnings.doctree +0 -0
  63. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/index.doctree +0 -0
  64. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/todo.doctree +0 -0
  65. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/token_class.doctree +0 -0
  66. {token_utils-0.3.6 → token_utils-0.3.7}/docs/doctrees/tutorial_prelude.doctree +0 -0
  67. /token_utils-0.3.6/docs/html/.buildinfo → /token_utils-0.3.7/docs/html/.buildinfo.bak +0 -0
  68. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/.nojekyll +0 -0
  69. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_modules/token_utils/custom_warnings.html +0 -0
  70. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/about_tokens.rst.txt +0 -0
  71. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/custom_warnings.rst.txt +0 -0
  72. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/index.rst.txt +0 -0
  73. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/todo.rst.txt +0 -0
  74. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/token_class.rst.txt +0 -0
  75. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/tokenizing_methods.rst.txt +0 -0
  76. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/tutorial_prelude.rst.txt +0 -0
  77. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_sources/utils.rst.txt +0 -0
  78. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/_sphinx_javascript_frameworks_compat.js +0 -0
  79. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/basic.css +0 -0
  80. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/badge_only.css +0 -0
  81. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/Roboto-Slab-Bold.woff +0 -0
  82. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/Roboto-Slab-Bold.woff2 +0 -0
  83. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/Roboto-Slab-Regular.woff +0 -0
  84. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/Roboto-Slab-Regular.woff2 +0 -0
  85. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/fontawesome-webfont.eot +0 -0
  86. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/fontawesome-webfont.svg +0 -0
  87. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/fontawesome-webfont.ttf +0 -0
  88. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/fontawesome-webfont.woff +0 -0
  89. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/fontawesome-webfont.woff2 +0 -0
  90. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-bold-italic.woff +0 -0
  91. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-bold-italic.woff2 +0 -0
  92. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-bold.woff +0 -0
  93. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-bold.woff2 +0 -0
  94. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-normal-italic.woff +0 -0
  95. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-normal-italic.woff2 +0 -0
  96. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-normal.woff +0 -0
  97. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/fonts/lato-normal.woff2 +0 -0
  98. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/css/theme.css +0 -0
  99. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/custom.css +0 -0
  100. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/doctools.js +0 -0
  101. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/file.png +0 -0
  102. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bold.eot +0 -0
  103. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bold.ttf +0 -0
  104. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bold.woff +0 -0
  105. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bold.woff2 +0 -0
  106. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bolditalic.eot +0 -0
  107. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bolditalic.ttf +0 -0
  108. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bolditalic.woff +0 -0
  109. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-bolditalic.woff2 +0 -0
  110. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-italic.eot +0 -0
  111. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-italic.ttf +0 -0
  112. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-italic.woff +0 -0
  113. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-italic.woff2 +0 -0
  114. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-regular.eot +0 -0
  115. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-regular.ttf +0 -0
  116. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-regular.woff +0 -0
  117. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/Lato/lato-regular.woff2 +0 -0
  118. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot +0 -0
  119. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf +0 -0
  120. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff +0 -0
  121. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2 +0 -0
  122. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot +0 -0
  123. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf +0 -0
  124. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff +0 -0
  125. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2 +0 -0
  126. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/jquery.js +0 -0
  127. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/js/badge_only.js +0 -0
  128. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/js/theme.js +0 -0
  129. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/js/versions.js +0 -0
  130. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/language_data.js +0 -0
  131. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/minus.png +0 -0
  132. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/plus.png +0 -0
  133. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/pygments.css +0 -0
  134. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/searchtools.js +0 -0
  135. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/sphinx-new-tab-link.css +0 -0
  136. {token_utils-0.3.6 → token_utils-0.3.7}/docs/html/_static/sphinx_highlight.js +0 -0
  137. {token_utils-0.3.6 → token_utils-0.3.7}/docs/make.bat +0 -0
  138. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/_static/custom.css +0 -0
  139. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/about_tokens.rst +0 -0
  140. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/conf.py +0 -0
  141. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/custom_warnings.rst +0 -0
  142. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/index.rst +0 -0
  143. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/todo.rst +0 -0
  144. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/token_class.rst +0 -0
  145. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/tokenizing_methods.rst +0 -0
  146. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/tutorial_prelude.rst +0 -0
  147. {token_utils-0.3.6 → token_utils-0.3.7}/docs/source/utils.rst +0 -0
  148. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/add_decorator.py +0 -0
  149. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/decimal_py.py +0 -0
  150. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/decimal_tok.py +0 -0
  151. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/decimal_tok2.py +0 -0
  152. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/decorator_example.txt +0 -0
  153. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/factorial_1.py +0 -0
  154. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/factorial_2.py +0 -0
  155. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/inside_blocks.py +0 -0
  156. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/nobreak.py +0 -0
  157. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/nobreak.txt +0 -0
  158. {token_utils-0.3.6 → token_utils-0.3.7}/docs_examples/view_stack.py +0 -0
  159. {token_utils-0.3.6 → token_utils-0.3.7}/pypi_upload.bat +0 -0
  160. {token_utils-0.3.6 → token_utils-0.3.7}/pyproject.toml +0 -0
  161. {token_utils-0.3.6 → token_utils-0.3.7}/run_all_tests.bat +0 -0
  162. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/__about__.pyi +0 -0
  163. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/__init__.py +0 -0
  164. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/__init__.pyi +0 -0
  165. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/_token_plus.py +0 -0
  166. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/_token_plus.pyi +0 -0
  167. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/custom_warnings.py +0 -0
  168. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/custom_warnings.pyi +0 -0
  169. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/py.typed +0 -0
  170. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/token_class.py +0 -0
  171. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/token_class.pyi +0 -0
  172. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/tokenizing.pyi +0 -0
  173. {token_utils-0.3.6 → token_utils-0.3.7}/src/token_utils/utils.pyi +0 -0
  174. {token_utils-0.3.6 → token_utils-0.3.7}/tests/__init__.py +0 -0
  175. {token_utils-0.3.6 → token_utils-0.3.7}/tests/test_roundtrip.py +0 -0
  176. {token_utils-0.3.6 → token_utils-0.3.7}/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.6
3
+ Version: 0.3.7
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
@@ -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: b9c10ae8ced3d23e68e16580bf3535f3
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 &mdash; token-utils 0.3.4 documentation</title>
8
+ <title>Overview: module code &mdash; 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=1e28cc32"></script>
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 &mdash; token-utils 0.3.4 documentation</title>
8
+ <title>token_utils.token_class &mdash; 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=1e28cc32"></script>
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 &mdash; token-utils 0.3.4 documentation</title>
8
+ <title>token_utils.tokenizing &mdash; 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=1e28cc32"></script>
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">"""Return source code based on tokens.</span>
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="c1"># Main changes from original:</span>
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">&gt;</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">&gt;</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">&gt;</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">&gt;</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
- <span class="k">if</span> <span class="n">token</span><span class="o">.</span><span class="n">start_col</span> <span class="o">&gt;</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>
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">&gt;</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">&gt;</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 NEWLINE token</span>
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></div>
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 &mdash; token-utils 0.3.4 documentation</title>
8
+ <title>token_utils.utils &mdash; 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=1e28cc32"></script>
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">"""docstring"""</span>
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, with, match, case</span>
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 of keeping track</span>
165
- <span class="c1"># of such keywords when they introduce a change in indentation. When they do so, and ignoring</span>
166
- <span class="c1"># end of line comments, they will appear as the first non-space token</span>
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, the last token</span>
169
- <span class="c1"># of each such line will always be a ``NEWLINE`` token, preceded by a colon.</span>
170
- <span class="c1"># This allowed us to define the utility class ``IndentStack``.</span>
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"># is dedenting occuring?</span>
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">&gt;</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 will attempt to demonstrate how to use these functions,
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, it would return ``False``,
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' ``immediately_after()`` instead
123
- of ``immediately_before()`` as it looks more natural in this example.
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 would have to go backwards, retrieve
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
- created in 2013, is unmaintained and apparently
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
- Below is the slightly modified ``untokenize`` used in
58
- token-utils,
59
- based on the clever algorithm designed by Steven Mynt,
60
- which guarantees to recover every character
61
- initially present in the source, thus enabling a perfect
62
- tokenize/untokenize round trip.
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
- Other than adapting to use with token-utils tokens rather
65
- that those coming from Python's ``tokenize`` module,
66
- the only addition we made was to allow the insertion of
67
- simple strings (instead of tokens) as a way to insert
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
- Also note:
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 having::
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 has::
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
- ``stringify()`` also has an extra parameter, ``remove_comments=False``. If sets to ``True``,
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.
@@ -1,5 +1,5 @@
1
1
  const DOCUMENTATION_OPTIONS = {
2
- VERSION: '0.3.4',
2
+ VERSION: '0.3.7',
3
3
  LANGUAGE: 'en',
4
4
  COLLAPSE_INDEX: false,
5
5
  BUILDER: 'html',
@@ -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 &mdash; token-utils 0.3.4 documentation</title>
9
+ <title>About tokens: Python vs token-utils &mdash; 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=1e28cc32"></script>
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 &mdash; token-utils 0.3.4 documentation</title>
9
+ <title>Custom warnings &mdash; 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=1e28cc32"></script>
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 &mdash; token-utils 0.3.4 documentation</title>
8
+ <title>Index &mdash; 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=1e28cc32"></script>
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>