pyvarcheck 0.0.2__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.
- pyvarcheck-0.0.2/LICENSE +21 -0
- pyvarcheck-0.0.2/PKG-INFO +73 -0
- pyvarcheck-0.0.2/README.md +52 -0
- pyvarcheck-0.0.2/setup.cfg +4 -0
- pyvarcheck-0.0.2/setup.py +32 -0
- pyvarcheck-0.0.2/src/P/pyvarcheck/__init__.py +147 -0
- pyvarcheck-0.0.2/src/P/pyvarcheck.egg-info/PKG-INFO +73 -0
- pyvarcheck-0.0.2/src/P/pyvarcheck.egg-info/SOURCES.txt +12 -0
- pyvarcheck-0.0.2/src/P/pyvarcheck.egg-info/dependency_links.txt +1 -0
- pyvarcheck-0.0.2/src/P/pyvarcheck.egg-info/top_level.txt +1 -0
pyvarcheck-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Benjamin Winter
|
|
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.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyvarcheck
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Easy, high-level var testing for python with auto-conversion features
|
|
5
|
+
Author: Benjamin Winter
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: python,var,arg,check,convert
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: keywords
|
|
18
|
+
Dynamic: license
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
# pyvarcheck
|
|
23
|
+
Easy, high-level var testing for python with auto-conversion features.
|
|
24
|
+
|
|
25
|
+
Test INT, STR, BYTEARRAY, BOOL, and many other data types for your requirements and auto-convert them.
|
|
26
|
+
There's pre-defined functions to match strings for hostnames, arguments, IP addresses, ports and many more. *pyvarcheck* tells you the index of a failed regex match.
|
|
27
|
+
|
|
28
|
+
> [!NOTE]
|
|
29
|
+
> This project is in use by **MPSS - Multi-platform shared storage**, a brand-new way to combine, share and access storage over LAN and WAN. Run servers, workstations and clients, multiple OSs and huge numbers of devices simultaneously.
|
|
30
|
+
[Take a look here if that sounds interesting! \[core2000.com\]](https://core2000.com/software/mpss/)
|
|
31
|
+
|
|
32
|
+
[Supporters](#now-for-the-boring-part) and contributors are welcome any day of the week :)
|
|
33
|
+
|
|
34
|
+
## Fast track
|
|
35
|
+
Install with `pip install pyvarcheck`; import into your project with `import pyvarcheck`; then open and run example file [`/samples/pyvarcheck_sample1.py`](https://github.com/core2000-eU/pyvarcheck/blob/main/samples/pyvarcheck_sample1.py) from GitHub.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
For documentation, please use the example file [`/samples/pyvarcheck_sample1.py`](https://github.com/core2000-eU/pyvarcheck/blob/main/samples/pyvarcheck_sample1.py) from GitHub.
|
|
39
|
+
Everything's neatly documented in there.
|
|
40
|
+
|
|
41
|
+
- Whenever a check succeeds, every function of *pyvarcheck* returns True. When parameter [convert] is set True, it converts the input item properly and returns it.
|
|
42
|
+
- Whenever a check fails, every function of *pyvarcheck* raises Exception type `pyvarcheck.varcheck_exc`.
|
|
43
|
+
- On the occasion that there's a programmatic error in any *pyvarcheck* function (sorry, my bad), *pyvarcheck* raises the original exception to the caller. Feel free report such occasions.
|
|
44
|
+
|
|
45
|
+
## Basics
|
|
46
|
+
**Compatibility** in short: any platform on Python 3.10+. OS-independent.
|
|
47
|
+
**Status:** *public beta*. Should work without issues, waiting for community response before releasing final v1.
|
|
48
|
+
**Built** on W11 25H2 with python 3.14.2, pip 26.2.1, build 1.5.0, twine 7.0.0. Standard settings.
|
|
49
|
+
|
|
50
|
+
## Build from source
|
|
51
|
+
The library is built witout any special options - as per the pypi manual. It uses `setuptools` (`setup.py`) and not the toml file.
|
|
52
|
+
- change into the library source code root folder
|
|
53
|
+
- python3 -m build
|
|
54
|
+
- I recommend you use a venv for this proceduce, and alter the `py -m build` command accordingly.
|
|
55
|
+
|
|
56
|
+
## Official Sources
|
|
57
|
+
|
|
58
|
+
| Site | URL |
|
|
59
|
+
|------|---------|
|
|
60
|
+
| **GitHub** | [github.com/core2000-eU/pyvarcheck](https://github.com/core2000-eU/pyvarcheck) |
|
|
61
|
+
| **pypi.org** | [pypi.org/project/pyvarcheck](https://pypi.org/project/pyvarcheck) |
|
|
62
|
+
| core2000.com (Website/info only, no release) | [core2000.com/software](https://core2000.com/software/) |
|
|
63
|
+
|
|
64
|
+
## Now for the boring part
|
|
65
|
+
**This library is created and maintained free of cost by a real human being /bla /bla /bla ...** You know the deal by now.
|
|
66
|
+
But seriously, monetary support a serious subject and without some income, I cannot continue to publish and maintain.
|
|
67
|
+
|
|
68
|
+
Not that anyone needs my gibberish anyways, but if you find it helpful, **please consider the below. Thanks :)**
|
|
69
|
+
--> [**buymeacoffee.com/core2000**](https://buymeacoffee.com/core2000)
|
|
70
|
+
|
|
71
|
+
## About
|
|
72
|
+
Created on 10.2026 and happily maintained since by **core2000** and it's owner, Benjamin Winter.
|
|
73
|
+
For more details, you can pay us a visit over on [**core2000.com**](https://core2000.com/).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# pyvarcheck
|
|
2
|
+
Easy, high-level var testing for python with auto-conversion features.
|
|
3
|
+
|
|
4
|
+
Test INT, STR, BYTEARRAY, BOOL, and many other data types for your requirements and auto-convert them.
|
|
5
|
+
There's pre-defined functions to match strings for hostnames, arguments, IP addresses, ports and many more. *pyvarcheck* tells you the index of a failed regex match.
|
|
6
|
+
|
|
7
|
+
> [!NOTE]
|
|
8
|
+
> This project is in use by **MPSS - Multi-platform shared storage**, a brand-new way to combine, share and access storage over LAN and WAN. Run servers, workstations and clients, multiple OSs and huge numbers of devices simultaneously.
|
|
9
|
+
[Take a look here if that sounds interesting! \[core2000.com\]](https://core2000.com/software/mpss/)
|
|
10
|
+
|
|
11
|
+
[Supporters](#now-for-the-boring-part) and contributors are welcome any day of the week :)
|
|
12
|
+
|
|
13
|
+
## Fast track
|
|
14
|
+
Install with `pip install pyvarcheck`; import into your project with `import pyvarcheck`; then open and run example file [`/samples/pyvarcheck_sample1.py`](https://github.com/core2000-eU/pyvarcheck/blob/main/samples/pyvarcheck_sample1.py) from GitHub.
|
|
15
|
+
|
|
16
|
+
## Documentation
|
|
17
|
+
For documentation, please use the example file [`/samples/pyvarcheck_sample1.py`](https://github.com/core2000-eU/pyvarcheck/blob/main/samples/pyvarcheck_sample1.py) from GitHub.
|
|
18
|
+
Everything's neatly documented in there.
|
|
19
|
+
|
|
20
|
+
- Whenever a check succeeds, every function of *pyvarcheck* returns True. When parameter [convert] is set True, it converts the input item properly and returns it.
|
|
21
|
+
- Whenever a check fails, every function of *pyvarcheck* raises Exception type `pyvarcheck.varcheck_exc`.
|
|
22
|
+
- On the occasion that there's a programmatic error in any *pyvarcheck* function (sorry, my bad), *pyvarcheck* raises the original exception to the caller. Feel free report such occasions.
|
|
23
|
+
|
|
24
|
+
## Basics
|
|
25
|
+
**Compatibility** in short: any platform on Python 3.10+. OS-independent.
|
|
26
|
+
**Status:** *public beta*. Should work without issues, waiting for community response before releasing final v1.
|
|
27
|
+
**Built** on W11 25H2 with python 3.14.2, pip 26.2.1, build 1.5.0, twine 7.0.0. Standard settings.
|
|
28
|
+
|
|
29
|
+
## Build from source
|
|
30
|
+
The library is built witout any special options - as per the pypi manual. It uses `setuptools` (`setup.py`) and not the toml file.
|
|
31
|
+
- change into the library source code root folder
|
|
32
|
+
- python3 -m build
|
|
33
|
+
- I recommend you use a venv for this proceduce, and alter the `py -m build` command accordingly.
|
|
34
|
+
|
|
35
|
+
## Official Sources
|
|
36
|
+
|
|
37
|
+
| Site | URL |
|
|
38
|
+
|------|---------|
|
|
39
|
+
| **GitHub** | [github.com/core2000-eU/pyvarcheck](https://github.com/core2000-eU/pyvarcheck) |
|
|
40
|
+
| **pypi.org** | [pypi.org/project/pyvarcheck](https://pypi.org/project/pyvarcheck) |
|
|
41
|
+
| core2000.com (Website/info only, no release) | [core2000.com/software](https://core2000.com/software/) |
|
|
42
|
+
|
|
43
|
+
## Now for the boring part
|
|
44
|
+
**This library is created and maintained free of cost by a real human being /bla /bla /bla ...** You know the deal by now.
|
|
45
|
+
But seriously, monetary support a serious subject and without some income, I cannot continue to publish and maintain.
|
|
46
|
+
|
|
47
|
+
Not that anyone needs my gibberish anyways, but if you find it helpful, **please consider the below. Thanks :)**
|
|
48
|
+
--> [**buymeacoffee.com/core2000**](https://buymeacoffee.com/core2000)
|
|
49
|
+
|
|
50
|
+
## About
|
|
51
|
+
Created on 10.2026 and happily maintained since by **core2000** and it's owner, Benjamin Winter.
|
|
52
|
+
For more details, you can pay us a visit over on [**core2000.com**](https://core2000.com/).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#Copyright (c) 2026 Benjamin Winter
|
|
2
|
+
#This file is part of pyvarcheck which is released under the MIT License.
|
|
3
|
+
#See file LICENSE or go to https://github.com/core2000-eU/pyvarcheck for full license details.
|
|
4
|
+
|
|
5
|
+
#DESCRIPTION
|
|
6
|
+
#Easy, high-level var testing for python with auto-conversion features.
|
|
7
|
+
|
|
8
|
+
import setuptools
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
parent_dir = Path(__file__).parent
|
|
12
|
+
long_description = (parent_dir / "README.md").read_text(encoding="utf-8")
|
|
13
|
+
|
|
14
|
+
setuptools.setup (
|
|
15
|
+
name = "pyvarcheck",
|
|
16
|
+
version = '0.0.2',
|
|
17
|
+
author = "Benjamin Winter",
|
|
18
|
+
license= "MIT",
|
|
19
|
+
description = "Easy, high-level var testing for python with auto-conversion features",
|
|
20
|
+
long_description = long_description,
|
|
21
|
+
long_description_content_type = "text/markdown",
|
|
22
|
+
keywords = ['python', 'var', 'arg', 'check', 'convert'],
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 4 - Beta",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Operating System :: OS Independent"
|
|
27
|
+
],
|
|
28
|
+
packages = setuptools.find_namespace_packages(where="src/P"),
|
|
29
|
+
package_dir = {"": "src/P"},
|
|
30
|
+
install_requires = [],
|
|
31
|
+
package_data = {},
|
|
32
|
+
)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#Copyright (c) 2026 Benjamin Winter
|
|
2
|
+
#This file is part of pyvarcheck which is released under the MIT License.
|
|
3
|
+
#See file LICENSE or go to https://github.com/core2000-eU/pyvarcheck for full license details.
|
|
4
|
+
|
|
5
|
+
#DESCRIPTION
|
|
6
|
+
#Easy, high-level var testing for python with auto-conversion features.
|
|
7
|
+
|
|
8
|
+
#imports
|
|
9
|
+
import inspect
|
|
10
|
+
import uuid
|
|
11
|
+
import ipaddress
|
|
12
|
+
import re
|
|
13
|
+
|
|
14
|
+
#global vars
|
|
15
|
+
precomp_regex_1 = re.compile(r"^[a-zA-Z0-9_.]+$") #used often
|
|
16
|
+
precomp_regex_2 = re.compile(r"^[a-zA-Z0-9_\-.]+$") #used often
|
|
17
|
+
gen_char_limit = 1024**2 #diced; just to have some theoretical yet practical limit
|
|
18
|
+
|
|
19
|
+
#exception types
|
|
20
|
+
class pyvarcheck_exc(Exception):
|
|
21
|
+
def __init__(self,error): super().__init__(error); self.error=error; self.is_exception_from_lib_pyvarcheck=True;
|
|
22
|
+
def __str__(self): return f"{self.error}"
|
|
23
|
+
|
|
24
|
+
#frontend user-facing functions
|
|
25
|
+
def str_utf8(obj_in,convert=False,exc_prepend="",exc_append=""):
|
|
26
|
+
try:
|
|
27
|
+
try: _=obj_in.encode("utf-8", errors="strict")
|
|
28
|
+
except Exception as e: raise pyvarcheck_exc(f"{exc_prepend}cannot encode in UTF-8. *.encode('utf-8', errors='strict') failed with exception {e.__repr__()}{exc_append}")
|
|
29
|
+
if(convert): return str(obj_in)
|
|
30
|
+
return True
|
|
31
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
32
|
+
def uuid4(obj_in,convert=False,exc_prepend="",exc_append=""):
|
|
33
|
+
try:
|
|
34
|
+
try: _=uuid.UUID(obj_in,version=4)
|
|
35
|
+
except Exception as e: raise pyvarcheck_exc(f"{exc_prepend}cannot convert to UUID. Operation failed with exception {e.__repr__()}{exc_append}")
|
|
36
|
+
if(convert): return uuid.UUID(obj_in,version=4)
|
|
37
|
+
return True
|
|
38
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
39
|
+
def arg_name(obj_in,maxlen=128,reservedchars=[],convert=False,exc_prepend="",exc_append=""):
|
|
40
|
+
try:
|
|
41
|
+
_=helpers.check_utf8_maxlen_reservedchars(obj_in,gen_char_limit,reservedchars,exc_prepend,exc_append)
|
|
42
|
+
_=helpers.do_regex_match_and_find_err_pos(precomp_regex_2,obj_in,exc_prepend,exc_append)
|
|
43
|
+
if(convert): return str(obj_in)
|
|
44
|
+
return True
|
|
45
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
46
|
+
def generic_name(obj_in,maxlen=128,reservedchars=[],convert=False,exc_prepend="",exc_append=""):
|
|
47
|
+
try:
|
|
48
|
+
_=helpers.check_utf8_maxlen_reservedchars(obj_in,maxlen,reservedchars,exc_prepend,exc_append)
|
|
49
|
+
if(convert): return str(obj_in)
|
|
50
|
+
return True
|
|
51
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
52
|
+
def hostname(obj_in,maxlen=64,reservedchars=[],convert=False,exc_prepend="",exc_append=""):
|
|
53
|
+
try:
|
|
54
|
+
_=helpers.check_utf8_maxlen_reservedchars(obj_in,maxlen,reservedchars,exc_prepend,exc_append)
|
|
55
|
+
_=helpers.do_regex_match_and_find_err_pos(precomp_regex_2,obj_in,exc_prepend,exc_append)
|
|
56
|
+
if(convert): return str(obj_in)
|
|
57
|
+
return True
|
|
58
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
59
|
+
def generic_description(obj_in,maxlen=gen_char_limit,reservedchars=[],re_match=r"",convert=False,exc_prepend="",exc_append=""):
|
|
60
|
+
try:
|
|
61
|
+
_=helpers.check_utf8_maxlen_reservedchars(obj_in,maxlen,reservedchars,exc_prepend,exc_append)
|
|
62
|
+
if(re_match!=r""): _=helpers.do_regex_match_and_find_err_pos(re_match,obj_in,exc_prepend,exc_append) #regex match only when given, it's quite slow
|
|
63
|
+
if(convert): return str(obj_in)
|
|
64
|
+
return True
|
|
65
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
66
|
+
def ipv4_addr(obj_in,convert=False,exc_prepend="",exc_append=""):
|
|
67
|
+
try:
|
|
68
|
+
try: _=ipaddress.IPv4Address(obj_in)
|
|
69
|
+
except Exception as e: raise pyvarcheck_exc(f"{exc_prepend}not an IPv4 address. ipaddress.IPv4Address(*) failed with exception {e.__repr__()}{exc_append}")
|
|
70
|
+
if(convert): return ipaddress.IPv4Address(obj_in)
|
|
71
|
+
return True
|
|
72
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
73
|
+
def ipv6_addr(obj_in,convert=False,exc_prepend="",exc_append=""):
|
|
74
|
+
try:
|
|
75
|
+
try: _=ipaddress.IPv6Address(obj_in)
|
|
76
|
+
except Exception as e: raise pyvarcheck_exc(f"{exc_prepend}not an IPv6 address. ipaddress.IPv6Address(*) failed with exception {e.__repr__()}{exc_append}")
|
|
77
|
+
if(convert): return ipaddress.IPv6Address(obj_in)
|
|
78
|
+
return True
|
|
79
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
80
|
+
def tcpip_port(obj_in,convert=False,exc_prepend="",exc_append=""):
|
|
81
|
+
try:
|
|
82
|
+
try: obj_in_tmp=int(obj_in)
|
|
83
|
+
except Exception as e: raise pyvarcheck_exc(f"{exc_prepend}expected datatype compatible with (convertible to) [int] but got [{type(obj_in).__qualname__}({obj_in})]{exc_append}")
|
|
84
|
+
if( not obj_in_tmp > 0 ) or ( not obj_in_tmp <= 65535 ): raise pyvarcheck_exc(f"{exc_prepend}expected TCP/IP Port number in range [1-65535]; to make it clear: (0 ≤ x ≤ 65535, x ∈ ℤ){exc_append}")
|
|
85
|
+
if(convert): return int(obj_in)
|
|
86
|
+
return True
|
|
87
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
88
|
+
def int_minmax(obj_in,value_min,value_max,convert=False,exc_prepend="",exc_append=""):
|
|
89
|
+
try:
|
|
90
|
+
try: obj_in_tmp=int(obj_in)
|
|
91
|
+
except Exception as e: raise pyvarcheck_exc(f"{exc_prepend}expected datatype compatible with (convertible to) [int] but got [{type(obj_in).__qualname__}({obj_in})]{exc_append}")
|
|
92
|
+
if( not obj_in_tmp >= value_min ) or ( not obj_in_tmp <= value_max ): raise pyvarcheck_exc(f"{exc_prepend}expected integer value between (incl.) [{value_min}] and (incl.) [{value_max}]; to make it clear: ({value_min} ≤ x ≤ {value_max}, x ∈ ℤ){exc_append}")
|
|
93
|
+
if(convert): return int(obj_in)
|
|
94
|
+
return True
|
|
95
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
96
|
+
def bool_compatible(obj_in,convert=False,exc_prepend="",exc_append=""):
|
|
97
|
+
try:
|
|
98
|
+
dataout=None
|
|
99
|
+
if(isinstance(obj_in,int)):
|
|
100
|
+
_=int_minmax(obj_in,0,1,exc_prepend,exc_append)
|
|
101
|
+
dataout=bool(obj_in)
|
|
102
|
+
elif(isinstance(obj_in,str)):
|
|
103
|
+
_=helpers.check_utf8_maxlen_reservedchars(obj_in,5,[],exc_prepend,exc_append)
|
|
104
|
+
obj_in_tmp = obj_in.lower()
|
|
105
|
+
match obj_in_tmp:
|
|
106
|
+
case "true": dataout=True
|
|
107
|
+
case "false": dataout=False
|
|
108
|
+
case "1": dataout=True
|
|
109
|
+
case "0": dataout=False
|
|
110
|
+
case _: raise pyvarcheck_exc(f"{exc_prepend}expected value convertable to bool. Either integer [0|1] or str ['true'|'false'] but got [{type(obj_in).__qualname__}({obj_in})]{exc_append}")
|
|
111
|
+
else: raise pyvarcheck_exc(f"{exc_prepend}expected datatype either [int] or [str] but got [{type(obj_in).__qualname__}({obj_in})]{exc_append}")
|
|
112
|
+
if(dataout==None): raise Exception(f"unexpected value [None] for var [dataout]. Please report. For debugging: [obj_in]={obj_in}, [exc_prepend]={exc_prepend}, [exc_append]={exc_append}, [convert]={convert}; end of debug")
|
|
113
|
+
if(convert): return bool(dataout)
|
|
114
|
+
return True
|
|
115
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
116
|
+
|
|
117
|
+
#backend functions
|
|
118
|
+
class helpers:
|
|
119
|
+
def check_utf8_maxlen_reservedchars(obj_in,maxlen,reservedchars,exc_prepend,exc_append):
|
|
120
|
+
try:
|
|
121
|
+
pass; _=str_utf8(obj_in,exc_prepend,exc_append)
|
|
122
|
+
if( len(obj_in) > maxlen ): raise pyvarcheck_exc(f"{exc_prepend}max length is [{maxlen}] but actual length is [{len(obj_in)}]{exc_append}")
|
|
123
|
+
if( obj_in in reservedchars ): raise pyvarcheck_exc(f"{exc_prepend}contains string that is in 'reservedchars' list. 'reservedchars' list is {reservedchars}{exc_append}")
|
|
124
|
+
for i,char in enumerate(obj_in):
|
|
125
|
+
if( char in reservedchars ):
|
|
126
|
+
char_hex = f"(byte value 0x{char.encode("utf-8",errors="ignore").hex()})";
|
|
127
|
+
raise pyvarcheck_exc(f"{exc_prepend}contains char {char_hex} at position [{i}] that is in 'reservedchars' list. position is 0-based. 'reservedchars' list is {reservedchars}{exc_append}")
|
|
128
|
+
return True
|
|
129
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
130
|
+
def do_regex_match_and_find_err_pos(regex_match,obj_in,exc_prepend,exc_append):
|
|
131
|
+
try:
|
|
132
|
+
if( not bool(re.match(regex_match, obj_in)) ):
|
|
133
|
+
for i, char in enumerate(obj_in):
|
|
134
|
+
if( not bool(re.match(regex_match, char)) ):
|
|
135
|
+
raise pyvarcheck_exc(f"{exc_prepend}contains invalid char (byte value 0x{char.encode("utf-8",errors="ignore").hex()}) at position [{i}]. re.match(r'{regex_match}') failed. position is 0-based.{exc_append}")
|
|
136
|
+
return True;
|
|
137
|
+
except Exception as e: helpers.raise_exc_properly(e,inspect.currentframe().f_code.co_name,exc_prepend,exc_append)
|
|
138
|
+
def raise_exc_properly(exc,funcname,exc_prepend="",exc_append=""):
|
|
139
|
+
if(isinstance(exc,pyvarcheck_exc)): raise exc
|
|
140
|
+
else:
|
|
141
|
+
tb = exc.__traceback__
|
|
142
|
+
while tb.tb_next:
|
|
143
|
+
tb = tb.tb_next
|
|
144
|
+
line_number = tb.tb_lineno
|
|
145
|
+
absolute_path = pathlib.Path(tb.tb_frame.f_code.co_filename).resolve()
|
|
146
|
+
addl_file_info=f" at file {absolute_path}, line {line_number}"
|
|
147
|
+
raise type(exc)(f"{exc_prepend}lib pyvarcheck: function {funcname}() raised internal Exception {exc} {addl_file_info}{exc_append}") from exc #raise the same orig. exception type with prepended message
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyvarcheck
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Easy, high-level var testing for python with auto-conversion features
|
|
5
|
+
Author: Benjamin Winter
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: python,var,arg,check,convert
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: keywords
|
|
18
|
+
Dynamic: license
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
# pyvarcheck
|
|
23
|
+
Easy, high-level var testing for python with auto-conversion features.
|
|
24
|
+
|
|
25
|
+
Test INT, STR, BYTEARRAY, BOOL, and many other data types for your requirements and auto-convert them.
|
|
26
|
+
There's pre-defined functions to match strings for hostnames, arguments, IP addresses, ports and many more. *pyvarcheck* tells you the index of a failed regex match.
|
|
27
|
+
|
|
28
|
+
> [!NOTE]
|
|
29
|
+
> This project is in use by **MPSS - Multi-platform shared storage**, a brand-new way to combine, share and access storage over LAN and WAN. Run servers, workstations and clients, multiple OSs and huge numbers of devices simultaneously.
|
|
30
|
+
[Take a look here if that sounds interesting! \[core2000.com\]](https://core2000.com/software/mpss/)
|
|
31
|
+
|
|
32
|
+
[Supporters](#now-for-the-boring-part) and contributors are welcome any day of the week :)
|
|
33
|
+
|
|
34
|
+
## Fast track
|
|
35
|
+
Install with `pip install pyvarcheck`; import into your project with `import pyvarcheck`; then open and run example file [`/samples/pyvarcheck_sample1.py`](https://github.com/core2000-eU/pyvarcheck/blob/main/samples/pyvarcheck_sample1.py) from GitHub.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
For documentation, please use the example file [`/samples/pyvarcheck_sample1.py`](https://github.com/core2000-eU/pyvarcheck/blob/main/samples/pyvarcheck_sample1.py) from GitHub.
|
|
39
|
+
Everything's neatly documented in there.
|
|
40
|
+
|
|
41
|
+
- Whenever a check succeeds, every function of *pyvarcheck* returns True. When parameter [convert] is set True, it converts the input item properly and returns it.
|
|
42
|
+
- Whenever a check fails, every function of *pyvarcheck* raises Exception type `pyvarcheck.varcheck_exc`.
|
|
43
|
+
- On the occasion that there's a programmatic error in any *pyvarcheck* function (sorry, my bad), *pyvarcheck* raises the original exception to the caller. Feel free report such occasions.
|
|
44
|
+
|
|
45
|
+
## Basics
|
|
46
|
+
**Compatibility** in short: any platform on Python 3.10+. OS-independent.
|
|
47
|
+
**Status:** *public beta*. Should work without issues, waiting for community response before releasing final v1.
|
|
48
|
+
**Built** on W11 25H2 with python 3.14.2, pip 26.2.1, build 1.5.0, twine 7.0.0. Standard settings.
|
|
49
|
+
|
|
50
|
+
## Build from source
|
|
51
|
+
The library is built witout any special options - as per the pypi manual. It uses `setuptools` (`setup.py`) and not the toml file.
|
|
52
|
+
- change into the library source code root folder
|
|
53
|
+
- python3 -m build
|
|
54
|
+
- I recommend you use a venv for this proceduce, and alter the `py -m build` command accordingly.
|
|
55
|
+
|
|
56
|
+
## Official Sources
|
|
57
|
+
|
|
58
|
+
| Site | URL |
|
|
59
|
+
|------|---------|
|
|
60
|
+
| **GitHub** | [github.com/core2000-eU/pyvarcheck](https://github.com/core2000-eU/pyvarcheck) |
|
|
61
|
+
| **pypi.org** | [pypi.org/project/pyvarcheck](https://pypi.org/project/pyvarcheck) |
|
|
62
|
+
| core2000.com (Website/info only, no release) | [core2000.com/software](https://core2000.com/software/) |
|
|
63
|
+
|
|
64
|
+
## Now for the boring part
|
|
65
|
+
**This library is created and maintained free of cost by a real human being /bla /bla /bla ...** You know the deal by now.
|
|
66
|
+
But seriously, monetary support a serious subject and without some income, I cannot continue to publish and maintain.
|
|
67
|
+
|
|
68
|
+
Not that anyone needs my gibberish anyways, but if you find it helpful, **please consider the below. Thanks :)**
|
|
69
|
+
--> [**buymeacoffee.com/core2000**](https://buymeacoffee.com/core2000)
|
|
70
|
+
|
|
71
|
+
## About
|
|
72
|
+
Created on 10.2026 and happily maintained since by **core2000** and it's owner, Benjamin Winter.
|
|
73
|
+
For more details, you can pay us a visit over on [**core2000.com**](https://core2000.com/).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
src/P/pyvarcheck.egg-info/PKG-INFO
|
|
5
|
+
src/P/pyvarcheck.egg-info/SOURCES.txt
|
|
6
|
+
src/P/pyvarcheck.egg-info/dependency_links.txt
|
|
7
|
+
src/P/pyvarcheck.egg-info/top_level.txt
|
|
8
|
+
src/P/pyvarcheck/__init__.py
|
|
9
|
+
src/P/pyvarcheck.egg-info/PKG-INFO
|
|
10
|
+
src/P/pyvarcheck.egg-info/SOURCES.txt
|
|
11
|
+
src/P/pyvarcheck.egg-info/dependency_links.txt
|
|
12
|
+
src/P/pyvarcheck.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyvarcheck
|