tstr 0.1.0__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.
@@ -0,0 +1,20 @@
1
+ FROM koxudaxi/python:3.14-rc-bullseye
2
+
3
+ # # Allow PYO3 to build even though the configured interpreter version (3.14)
4
+ # # is greater than PYO3's stated limit (3.12)
5
+ # ENV PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
6
+
7
+ # Tell pip not to worry about the user environment
8
+ ENV PIP_ROOT_USER_ACTION=ignore
9
+
10
+ # Various things to make devcontainers run smoothly
11
+ ENV EDITOR="code --wait"
12
+
13
+ # # Install locales and locales-all, required to build sphinx docs
14
+ # # in the devcontainer, since sphinx main starts sith `locale.setlocale(LC_ALL, '')`
15
+ # #
16
+ # # Also, install jq (required for building the playground)
17
+ # RUN apt-get update && apt-get install -y locales locales-all jq
18
+
19
+ # # Install rust and cargo to support watchfiles, rpds-py, and metadata
20
+ # RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
@@ -0,0 +1,44 @@
1
+ {
2
+ "build": {
3
+ "dockerfile": "Dockerfile"
4
+ },
5
+ "postCreateCommand": {
6
+ "install dependencies": "pip install -e . && pip install pytest && . .venv/bin/activate"
7
+ },
8
+ "features": {
9
+ "git": "os-provided",
10
+ "sshd": "latest"
11
+ },
12
+ "customizations": {
13
+ "vscode": {
14
+ "extensions": [
15
+ // Python auto-complete -- although, of course, it doesn't
16
+ // support the new tagstring syntax in the PEP
17
+ "ms-python.python",
18
+ // Edit the devcontainer and other dockerfiles.
19
+ "ms-azuretools.vscode-docker"
20
+ ],
21
+ "settings": {
22
+ "editor.insertSpaces": true,
23
+ "editor.rulers": [
24
+ 80
25
+ ],
26
+ "editor.tabSize": 4,
27
+ "editor.trimAutoWhitespace": true,
28
+ "files.encoding": "utf8",
29
+ "files.eol": "\n",
30
+ "files.insertFinalNewline": true,
31
+ "files.trimTrailingWhitespace": true,
32
+ "[restructuredtext]": {
33
+ "editor.tabSize": 3
34
+ },
35
+ "[python]": {
36
+ "editor.formatOnSave": false
37
+ },
38
+ "python.testing.unittestEnabled": false,
39
+ "python.testing.pytestEnabled": true,
40
+ "python.defaultInterpreterPath": "/usr/local/bin/python"
41
+ }
42
+ }
43
+ }
44
+ }
tstr-0.1.0/.gitignore ADDED
@@ -0,0 +1,166 @@
1
+ # Custom gitignores
2
+ _ignore*
3
+ .ignore[-_]*
4
+
5
+ # Byte-compiled / optimized / DLL files
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+
10
+ # C extensions
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ share/python-wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # PyInstaller
34
+ # Usually these files are written by a python script from a template
35
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *.cover
53
+ *.py,cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+ cover/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+ db.sqlite3-journal
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # Sphinx documentation
76
+ docs/_build/
77
+
78
+ # PyBuilder
79
+ .pybuilder/
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # pyenv
90
+ # For a library or package, you might want to ignore these files since the code is
91
+ # intended to run in multiple environments; otherwise, check them in:
92
+ # .python-version
93
+
94
+ # pipenv
95
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
97
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
98
+ # install all needed dependencies.
99
+ #Pipfile.lock
100
+
101
+ # poetry
102
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
104
+ # commonly ignored for libraries.
105
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106
+ #poetry.lock
107
+
108
+ # pdm
109
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110
+ #pdm.lock
111
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112
+ # in version control.
113
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
114
+ .pdm.toml
115
+ .pdm-python
116
+ .pdm-build/
117
+
118
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
119
+ __pypackages__/
120
+
121
+ # Celery stuff
122
+ celerybeat-schedule
123
+ celerybeat.pid
124
+
125
+ # SageMath parsed files
126
+ *.sage.py
127
+
128
+ # Environments
129
+ .env
130
+ .venv
131
+ env/
132
+ venv/
133
+ ENV/
134
+ env.bak/
135
+ venv.bak/
136
+
137
+ # Spyder project settings
138
+ .spyderproject
139
+ .spyproject
140
+
141
+ # Rope project settings
142
+ .ropeproject
143
+
144
+ # mkdocs documentation
145
+ /site
146
+
147
+ # mypy
148
+ .mypy_cache/
149
+ .dmypy.json
150
+ dmypy.json
151
+
152
+ # Pyre type checker
153
+ .pyre/
154
+
155
+ # pytype static type analyzer
156
+ .pytype/
157
+
158
+ # Cython debug symbols
159
+ cython_debug/
160
+
161
+ # PyCharm
162
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
163
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
164
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
165
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
166
+ #.idea/
@@ -0,0 +1,7 @@
1
+ {
2
+ "cSpell.words": [
3
+ "tstr",
4
+ "tstr"
5
+ ],
6
+ "python.analysis.typeCheckingMode": "standard"
7
+ }
tstr-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
tstr-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.4
2
+ Name: tstr
3
+ Version: 0.1.0
4
+ Summary: Template string utilities and backports
5
+ Project-URL: Repository, https://github.com/ilotoki0804/tstr
6
+ Author-email: ilotoki0804 <ilotoki0804@gmail.com>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: backport,string,template,utility
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: >=3.13
15
+ Description-Content-Type: text/markdown
16
+
17
+ # tstr
18
+
19
+ `tstr` is a Python library that provides convenient utility functions for working with [PEP 750 template strings](https://peps.python.org/pep-0750/). While template strings (`t"..."`) are powerful on their own, `tstr` makes them even easier to use by providing common processing patterns and utilities.
20
+
21
+ For Python versions older than 3.14, `tstr` includes a backport implementation allowing you to use template strings functionality in earlier Python versions.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install tstr
27
+ ```
28
+
29
+ ## Requirements
30
+
31
+ - Python 3.14+ (template strings were introduced in Python 3.14 via PEP 750)
32
+
33
+ ## Quick Start
34
+
35
+ ```python
36
+ from tstr import f
37
+
38
+ # Use template strings
39
+ name = "world"
40
+ template = t"Hello, {name}!"
41
+
42
+ # Convert to a string (just like f-strings)
43
+ result = f(template) # "Hello, world!"
44
+ ```
45
+
46
+ ## Core Functions
47
+
48
+ ### Working with Template Strings
49
+
50
+ - **`f(template)` / `evaluate(template)`**: Convert a template to a string (like f-strings)
51
+ - **`normalize(interpolation)`**: Process an interpolation to get its value or string representation
52
+ - **`normalize_str(interpolation)`**: Convert an interpolation to a formatted string
53
+
54
+ ### Template Processing
55
+
56
+ - **`bind(template, binder, *, joiner="".join)`**: Apply a function to each interpolation in a template
57
+ - **`binder(function, joiner="".join)`**: Create a reusable template processor function
58
+ - **`converter(conversion)`**: Get a conversion function (ascii, repr, str) for a conversion specifier
59
+ - **`convert(value, conversion)`**: Apply a conversion to a value
60
+
61
+ ## Examples
62
+
63
+ ### Basic Usage: Template to String
64
+
65
+ ```python
66
+ from tstr import f, evaluate
67
+
68
+ name = "world"
69
+ template = t"Hello, {name}!"
70
+
71
+ # Both functions do the same thing
72
+ result1 = f(template) # "Hello, world!"
73
+ result2 = evaluate(template) # "Hello, world!"
74
+ ```
75
+
76
+ ### Creating Custom Template Processors
77
+
78
+ ```python
79
+ from tstr import bind, normalize_str
80
+
81
+ def html_escape(text):
82
+ return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
83
+
84
+ def safe_html(template):
85
+ # Apply HTML escaping to each interpolation
86
+ return bind(template, lambda i: html_escape(normalize_str(i)))
87
+
88
+ user_content = "<script>alert('XSS attack')</script>"
89
+ template = t"<div>{user_content}</div>"
90
+ safe_output = safe_html(template)
91
+ # "<div>&lt;script&gt;alert('XSS attack')&lt;/script&gt;</div>"
92
+ ```
93
+
94
+ ### Using Binders for Reusable Processors
95
+
96
+ ```python
97
+ from tstr import binder, normalize_str
98
+
99
+ # Create a custom template processor
100
+ uppercase = binder(lambda i: normalize_str(i).upper())
101
+
102
+ # Use it on multiple templates
103
+ name = "world"
104
+ place = "Python"
105
+ template1 = t"Hello, {name}!"
106
+ template2 = t"Welcome to {place}!"
107
+
108
+ result1 = uppercase(template1) # "Hello, WORLD!"
109
+ result2 = uppercase(template2) # "Welcome to PYTHON!"
110
+ ```
111
+
112
+ ### Advanced Template Comparison
113
+
114
+ ```python
115
+ from tstr import template_equivalent
116
+
117
+ name = "World"
118
+ template1 = t"Hello {name}"
119
+ template2 = t"Hello {name}"
120
+
121
+ # Compare templates with full equality check
122
+ assert template_equivalent(template1, template2)
123
+
124
+ # Compare only structure, not values
125
+ template3 = t"Hello {name}"
126
+ name = "Python"
127
+ template4 = t"Hello {name}"
128
+ assert template_equivalent(template3, template4, compare_value=False)
129
+ ```
130
+
131
+ ## Why Use Template Strings?
132
+
133
+ Template strings allow you to work with both the literal string parts and interpolated values before they're combined. This enables:
134
+
135
+ 1. **Security**: Sanitize user input before rendering (prevent XSS, SQL injection)
136
+ 2. **Custom formatting**: Format values based on their types or context
137
+ 3. **Domain-specific languages**: Build HTML, SQL, or other languages safely
138
+ 4. **Structural analysis**: Examine template structure for validation or optimization
139
+
140
+ ## Documentation
141
+
142
+ For more detailed documentation, see the [API Reference](https://tstr.readthedocs.io/).
143
+
144
+ ## License
145
+
146
+ Apache License 2.0