strverify 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.
- strverify-0.1.0/.gitattributes +2 -0
- strverify-0.1.0/.gitignore +181 -0
- strverify-0.1.0/Cargo.lock +146 -0
- strverify-0.1.0/Cargo.toml +27 -0
- strverify-0.1.0/LICENSE +21 -0
- strverify-0.1.0/PKG-INFO +280 -0
- strverify-0.1.0/README.md +251 -0
- strverify-0.1.0/docs/README.ru.md +249 -0
- strverify-0.1.0/docs/README.zh.md +243 -0
- strverify-0.1.0/pyproject.toml +52 -0
- strverify-0.1.0/python/strverify/__init__.py +15 -0
- strverify-0.1.0/python/strverify/__init__.pyi +70 -0
- strverify-0.1.0/python/strverify/py.typed +0 -0
- strverify-0.1.0/requirements.txt +5 -0
- strverify-0.1.0/src/charset.rs +449 -0
- strverify-0.1.0/src/filter.rs +472 -0
- strverify-0.1.0/src/lib.rs +39 -0
- strverify-0.1.0/tests/test_filters.py +313 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
116
|
+
.pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
121
|
+
__pypackages__/
|
|
122
|
+
|
|
123
|
+
# Celery stuff
|
|
124
|
+
celerybeat-schedule
|
|
125
|
+
celerybeat.pid
|
|
126
|
+
|
|
127
|
+
# SageMath parsed files
|
|
128
|
+
*.sage.py
|
|
129
|
+
|
|
130
|
+
# Environments
|
|
131
|
+
.env
|
|
132
|
+
.venv
|
|
133
|
+
env/
|
|
134
|
+
venv/
|
|
135
|
+
ENV/
|
|
136
|
+
env.bak/
|
|
137
|
+
venv.bak/
|
|
138
|
+
|
|
139
|
+
# Spyder project settings
|
|
140
|
+
.spyderproject
|
|
141
|
+
.spyproject
|
|
142
|
+
|
|
143
|
+
# Rope project settings
|
|
144
|
+
.ropeproject
|
|
145
|
+
|
|
146
|
+
# mkdocs documentation
|
|
147
|
+
/site
|
|
148
|
+
|
|
149
|
+
# mypy
|
|
150
|
+
.mypy_cache/
|
|
151
|
+
.dmypy.json
|
|
152
|
+
dmypy.json
|
|
153
|
+
|
|
154
|
+
# Pyre type checker
|
|
155
|
+
.pyre/
|
|
156
|
+
|
|
157
|
+
# pytype static type analyzer
|
|
158
|
+
.pytype/
|
|
159
|
+
|
|
160
|
+
# Cython debug symbols
|
|
161
|
+
cython_debug/
|
|
162
|
+
|
|
163
|
+
# PyCharm
|
|
164
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
165
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
166
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
167
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
168
|
+
#.idea/
|
|
169
|
+
|
|
170
|
+
# Ruff stuff:
|
|
171
|
+
.ruff_cache/
|
|
172
|
+
|
|
173
|
+
# PyPI configuration file
|
|
174
|
+
.pypirc
|
|
175
|
+
|
|
176
|
+
# Cursor
|
|
177
|
+
# Cursor is an AI-powered code editor.`.cursorignore` specifies files/directories to
|
|
178
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
179
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
180
|
+
.cursorignore
|
|
181
|
+
.cursorindexingignore
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "heck"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "libc"
|
|
13
|
+
version = "0.2.191"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "once_cell"
|
|
19
|
+
version = "1.21.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "portable-atomic"
|
|
25
|
+
version = "1.15.0"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "proc-macro2"
|
|
31
|
+
version = "1.0.107"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
34
|
+
dependencies = [
|
|
35
|
+
"unicode-ident",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[[package]]
|
|
39
|
+
name = "pyo3"
|
|
40
|
+
version = "0.30.1"
|
|
41
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
+
checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
|
|
43
|
+
dependencies = [
|
|
44
|
+
"libc",
|
|
45
|
+
"once_cell",
|
|
46
|
+
"portable-atomic",
|
|
47
|
+
"pyo3-build-config",
|
|
48
|
+
"pyo3-ffi",
|
|
49
|
+
"pyo3-macros",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[[package]]
|
|
53
|
+
name = "pyo3-build-config"
|
|
54
|
+
version = "0.30.1"
|
|
55
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
+
checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
|
|
57
|
+
dependencies = [
|
|
58
|
+
"target-lexicon",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[[package]]
|
|
62
|
+
name = "pyo3-ffi"
|
|
63
|
+
version = "0.30.1"
|
|
64
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
65
|
+
checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
|
|
66
|
+
dependencies = [
|
|
67
|
+
"libc",
|
|
68
|
+
"pyo3-build-config",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[[package]]
|
|
72
|
+
name = "pyo3-macros"
|
|
73
|
+
version = "0.30.1"
|
|
74
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
75
|
+
checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
|
|
76
|
+
dependencies = [
|
|
77
|
+
"proc-macro2",
|
|
78
|
+
"pyo3-macros-backend",
|
|
79
|
+
"quote",
|
|
80
|
+
"syn",
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
[[package]]
|
|
84
|
+
name = "pyo3-macros-backend"
|
|
85
|
+
version = "0.30.1"
|
|
86
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
+
checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
|
|
88
|
+
dependencies = [
|
|
89
|
+
"heck",
|
|
90
|
+
"proc-macro2",
|
|
91
|
+
"quote",
|
|
92
|
+
"syn",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[[package]]
|
|
96
|
+
name = "quote"
|
|
97
|
+
version = "1.0.47"
|
|
98
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
99
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
100
|
+
dependencies = [
|
|
101
|
+
"proc-macro2",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
[[package]]
|
|
105
|
+
name = "strverify"
|
|
106
|
+
version = "0.1.0"
|
|
107
|
+
dependencies = [
|
|
108
|
+
"pyo3",
|
|
109
|
+
"unicode-general-category",
|
|
110
|
+
"unicode-script",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
[[package]]
|
|
114
|
+
name = "syn"
|
|
115
|
+
version = "3.0.10"
|
|
116
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
117
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
118
|
+
dependencies = [
|
|
119
|
+
"proc-macro2",
|
|
120
|
+
"quote",
|
|
121
|
+
"unicode-ident",
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
[[package]]
|
|
125
|
+
name = "target-lexicon"
|
|
126
|
+
version = "0.13.5"
|
|
127
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
128
|
+
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
|
129
|
+
|
|
130
|
+
[[package]]
|
|
131
|
+
name = "unicode-general-category"
|
|
132
|
+
version = "1.1.0"
|
|
133
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
134
|
+
checksum = "0b993bddc193ae5bd0d623b49ec06ac3e9312875fdae725a975c51db1cc1677f"
|
|
135
|
+
|
|
136
|
+
[[package]]
|
|
137
|
+
name = "unicode-ident"
|
|
138
|
+
version = "1.0.27"
|
|
139
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
140
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
141
|
+
|
|
142
|
+
[[package]]
|
|
143
|
+
name = "unicode-script"
|
|
144
|
+
version = "0.5.9"
|
|
145
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
146
|
+
checksum = "aa04c955db05429d464c74d495c1ee677e1866e783a4c3747f9c0cef7756cabf"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "strverify"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
rust-version = "1.85"
|
|
6
|
+
description = "Composable string content filters implemented in Rust"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
keywords = ["string", "filter", "validation", "unicode", "pyo3"]
|
|
10
|
+
categories = ["text-processing"]
|
|
11
|
+
|
|
12
|
+
[lib]
|
|
13
|
+
name = "_strverify"
|
|
14
|
+
crate-type = ["cdylib", "rlib"]
|
|
15
|
+
|
|
16
|
+
[dependencies]
|
|
17
|
+
pyo3 = { version = "0.30.1", features = ["abi3-py39"] }
|
|
18
|
+
unicode-general-category = "1.1.0"
|
|
19
|
+
unicode-script = "0.5.9"
|
|
20
|
+
|
|
21
|
+
[features]
|
|
22
|
+
default = []
|
|
23
|
+
extension-module = ["pyo3/extension-module"]
|
|
24
|
+
|
|
25
|
+
[profile.release]
|
|
26
|
+
codegen-units = 1
|
|
27
|
+
lto = "thin"
|
strverify-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zhukoff74
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
strverify-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: strverify
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Development Status :: 3 - Alpha
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: Operating System :: OS Independent
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
|
+
Classifier: Programming Language :: Rust
|
|
17
|
+
Classifier: Topic :: Text Processing :: General
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: pytest>=8.0 ; extra == 'test'
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Summary: Fast, composable string-content filters implemented in Rust
|
|
23
|
+
Keywords: string,filter,validation,text,unicode,rust,pyo3
|
|
24
|
+
Author: zhukoff74
|
|
25
|
+
License-Expression: MIT
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
28
|
+
|
|
29
|
+
# strverify
|
|
30
|
+
|
|
31
|
+
A fast string-content validation library with a Rust core and a Python API.
|
|
32
|
+
Filters are immutable and compose with the logical operators `&`, `|`, and `~`.
|
|
33
|
+
|
|
34
|
+
**English** | [Русский](docs/README.ru.md) | [中文](docs/README.zh.md)
|
|
35
|
+
|
|
36
|
+
> **Package names.** The PyPI distribution and the importable package share the
|
|
37
|
+
> same name: **`strverify`**.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install strverify
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Python 3.9+ is required. Wheels are built as `abi3`, so a single wheel works
|
|
46
|
+
on every supported CPython version.
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from strverify import CharSet, Filter
|
|
52
|
+
|
|
53
|
+
Filter.only_cyrillic()("Привет") # True
|
|
54
|
+
Filter.only_cyrillic()("Привет!") # False
|
|
55
|
+
Filter.only_latin()("Hello") # True
|
|
56
|
+
|
|
57
|
+
# Either entirely Cyrillic or entirely Latin:
|
|
58
|
+
(Filter.only_cyrillic() | Filter.only_latin())("Привет") # True
|
|
59
|
+
|
|
60
|
+
Filter.only_digits()("12345") # True
|
|
61
|
+
Filter.only_digits()("12.3") # False
|
|
62
|
+
|
|
63
|
+
Filter.no_digits()("Привет") # True
|
|
64
|
+
Filter.no_digits()("Привет1") # False
|
|
65
|
+
|
|
66
|
+
Filter.only_digits_and(".,")("1 234,50") # False
|
|
67
|
+
Filter.only_digits_and(".,")("1234,50") # True
|
|
68
|
+
|
|
69
|
+
Filter.contains("!")("Привет!") # True
|
|
70
|
+
Filter.contains("!")("Привет") # False
|
|
71
|
+
|
|
72
|
+
Filter.only_digits_and_cyrillic()("Привет123") # True
|
|
73
|
+
Filter.only_digits_and_cyrillic()("Hello123") # False
|
|
74
|
+
|
|
75
|
+
Filter.only_symbols()("!@#$%^&*") # True
|
|
76
|
+
Filter.only_symbols()("Hello!") # False
|
|
77
|
+
|
|
78
|
+
Filter.only_digits_and_underscore()("12_34") # True
|
|
79
|
+
Filter.only_digits_and_underscore()("12.34") # False
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Every filter can be called like a function (`filter_obj(text)`) or via
|
|
83
|
+
`.matches(text)`, so it works with `filter()` and any code that expects a
|
|
84
|
+
predicate.
|
|
85
|
+
|
|
86
|
+
## Combining filters
|
|
87
|
+
|
|
88
|
+
Predicates compose with operators:
|
|
89
|
+
|
|
90
|
+
| Operator | Meaning |
|
|
91
|
+
|----------|---------|
|
|
92
|
+
| `a & b` | AND: the string must satisfy both filters |
|
|
93
|
+
| `a \| b` | OR: satisfying either one is enough |
|
|
94
|
+
| `~a` | NOT: inverts the filter |
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from strverify import Filter
|
|
98
|
+
|
|
99
|
+
f = Filter.only_cyrillic() & ~Filter.contains("!") & Filter.non_empty()
|
|
100
|
+
|
|
101
|
+
f("Привет") # True
|
|
102
|
+
f("Привет!") # False
|
|
103
|
+
f("") # False
|
|
104
|
+
f("Hello") # False
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Function-style equivalents are available for those who prefer explicit calls:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
Filter.all_of(Filter.only_cyrillic(), Filter.non_empty())
|
|
111
|
+
Filter.any_of(Filter.contains("!"), Filter.contains("?"))
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`Filter.all_of()` with no arguments accepts everything, while
|
|
115
|
+
`Filter.any_of()` with no arguments accepts nothing.
|
|
116
|
+
|
|
117
|
+
> **Important:** use `&`, `|`, and `~`, not Python's `and`, `or`, and `not`.
|
|
118
|
+
> Filters intentionally have no truth value: `bool(Filter...)` raises
|
|
119
|
+
> `TypeError`, so an accidental `f1 and f2` cannot fail silently.
|
|
120
|
+
|
|
121
|
+
`~` is the logical negation of the entire predicate, not a swapped operation:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
~Filter.only_digits() # negation of "all characters are digits"
|
|
125
|
+
Filter.no_digits() # "no digits at all"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Character classes vs. predicates
|
|
129
|
+
|
|
130
|
+
`CharSet` describes a **set of allowed characters**, while `Filter` describes a
|
|
131
|
+
**condition on the whole string**. These are different operations and must not
|
|
132
|
+
be confused:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from strverify import CharSet, Filter
|
|
136
|
+
|
|
137
|
+
# Correct: the character set is digits OR Cyrillic
|
|
138
|
+
f = Filter.only(CharSet.DIGITS | CharSet.CYRILLIC)
|
|
139
|
+
f("Привет123") # True
|
|
140
|
+
|
|
141
|
+
# This is NOT the same: "the whole string consists only of digits" OR
|
|
142
|
+
# "the whole string consists only of Cyrillic"
|
|
143
|
+
g = Filter.only_digits() | Filter.only_cyrillic()
|
|
144
|
+
g("Привет123") # False
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Combining two `only` filters with `&` does not merge their classes either: it
|
|
148
|
+
requires both conditions to hold. To combine character classes, use `CharSet`
|
|
149
|
+
and a single `Filter.only`.
|
|
150
|
+
|
|
151
|
+
Ready-made presets cover common cases:
|
|
152
|
+
`Filter.only_digits_and_cyrillic()` and `Filter.only_digits_and(".,")`.
|
|
153
|
+
|
|
154
|
+
## Character sets
|
|
155
|
+
|
|
156
|
+
`CharSet` is an immutable set. Sets are combined with the `|` operator:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
allowed = CharSet.DIGITS | CharSet.of(".,_")
|
|
160
|
+
assert "5" in allowed
|
|
161
|
+
assert "_" in allowed
|
|
162
|
+
assert "a" not in allowed
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
| Class | Meaning |
|
|
166
|
+
|-------|---------|
|
|
167
|
+
| `CharSet.CYRILLIC` | Unicode Cyrillic script |
|
|
168
|
+
| `CharSet.LATIN` | Unicode Latin script |
|
|
169
|
+
| `CharSet.LETTERS` | any Unicode letters (`L*`) |
|
|
170
|
+
| `CharSet.DIGITS` | any Unicode decimal digits (`Nd`), including `0-9` |
|
|
171
|
+
| `CharSet.ASCII_DIGITS` | ASCII digits `0-9` only |
|
|
172
|
+
| `CharSet.PUNCTUATION` | Unicode punctuation (`P*`) |
|
|
173
|
+
| `CharSet.SYMBOLS` | Unicode symbols (`S*`): `+`, `€`, `😀` |
|
|
174
|
+
| `CharSet.WHITESPACE` | Unicode whitespace characters |
|
|
175
|
+
| `CharSet.ASCII` | all ASCII characters `U+0000..U+007F` |
|
|
176
|
+
|
|
177
|
+
`CharSet.of("...")` adds specific characters. `CharSet.empty()` creates an
|
|
178
|
+
empty set.
|
|
179
|
+
|
|
180
|
+
For example, Cyrillic with spaces and hyphens:
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
Filter.only(CharSet.CYRILLIC | CharSet.of(" -"))
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
`Filter.only_symbols()` is a preset over `PUNCTUATION | SYMBOLS`; it does not
|
|
187
|
+
include whitespace. If you need spaces:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
Filter.only(CharSet.PUNCTUATION | CharSet.SYMBOLS | CharSet.WHITESPACE)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Empty strings
|
|
194
|
+
|
|
195
|
+
Character-class filters formally accept an empty string: it contains no
|
|
196
|
+
characters that violate the constraint. `Filter.no_digits()`,
|
|
197
|
+
`Filter.only_digits()`, and `Filter.only_symbols()` return `True` for `""`,
|
|
198
|
+
while `Filter.contains("!")` returns `False`.
|
|
199
|
+
|
|
200
|
+
If an empty string is not acceptable, add `Filter.non_empty()`:
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
f = Filter.only_digits() & Filter.non_empty()
|
|
204
|
+
f("") # False
|
|
205
|
+
f("123") # True
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## API
|
|
209
|
+
|
|
210
|
+
### `Filter`
|
|
211
|
+
|
|
212
|
+
In every method with a `chars` parameter, you can pass either a `str` (a set of
|
|
213
|
+
literal characters) or a `CharSet`.
|
|
214
|
+
|
|
215
|
+
Construction:
|
|
216
|
+
|
|
217
|
+
- `Filter.only(chars)` — every character in the string belongs to `chars`
|
|
218
|
+
(a string or a `CharSet`).
|
|
219
|
+
- `Filter.none_of(chars)` — no characters from `chars`.
|
|
220
|
+
- `Filter.contains(chars)` — at least one character from `chars`.
|
|
221
|
+
- `Filter.non_empty()` — the string is not empty.
|
|
222
|
+
- `Filter.always()` / `Filter.never()` — tautology and contradiction.
|
|
223
|
+
- `Filter.only_cyrillic()`, `Filter.only_latin()`, `Filter.only_digits()`,
|
|
224
|
+
`Filter.no_digits()`, `Filter.only_digits_and(chars)`,
|
|
225
|
+
`Filter.only_digits_and_cyrillic()`, `Filter.only_digits_and_underscore()`,
|
|
226
|
+
`Filter.only_symbols()`.
|
|
227
|
+
- `Filter.all_of(*filters)`, `Filter.any_of(*filters)`.
|
|
228
|
+
|
|
229
|
+
Matching and combining:
|
|
230
|
+
|
|
231
|
+
- `f.matches(text)` and `f(text)`.
|
|
232
|
+
- `f & g`, `f | g`, `~f`.
|
|
233
|
+
- `repr(f)` shows the expression tree.
|
|
234
|
+
|
|
235
|
+
### `CharSet`
|
|
236
|
+
|
|
237
|
+
- The constants from the table above.
|
|
238
|
+
- `CharSet.of(chars)` — literal characters.
|
|
239
|
+
- `CharSet.empty()`.
|
|
240
|
+
- `set | set` — union.
|
|
241
|
+
- `"x" in set` — membership test for a single character.
|
|
242
|
+
|
|
243
|
+
## Development
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
python3 -m venv .venv
|
|
247
|
+
source .venv/bin/activate
|
|
248
|
+
pip install maturin pytest
|
|
249
|
+
|
|
250
|
+
maturin develop --release
|
|
251
|
+
pytest
|
|
252
|
+
cargo test
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Building a wheel and an sdist:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
maturin build --release
|
|
259
|
+
maturin sdist
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The artifacts appear in `target/wheels/`.
|
|
263
|
+
|
|
264
|
+
Publishing to PyPI (requires a token in `MATURIN_PYPI_TOKEN` or interactive
|
|
265
|
+
input):
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
maturin publish
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
It is a good idea to test the package on TestPyPI first:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
maturin publish --repository testpypi
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## License
|
|
278
|
+
|
|
279
|
+
MIT. See [LICENSE](LICENSE).
|
|
280
|
+
|