none-shall-parse 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl
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.
- none_shall_parse/__init__.py +1 -1
- none_shall_parse/imeis.py +30 -30
- none_shall_parse/lists.py +2 -1
- none_shall_parse/parse.py +8 -8
- none_shall_parse/strings.py +14 -13
- none_shall_parse/types.py +2 -1
- {none_shall_parse-0.3.0.dist-info → none_shall_parse-0.3.1.dist-info}/METADATA +2 -2
- none_shall_parse-0.3.1.dist-info/RECORD +9 -0
- {none_shall_parse-0.3.0.dist-info → none_shall_parse-0.3.1.dist-info}/WHEEL +1 -1
- none_shall_parse-0.3.0.dist-info/RECORD +0 -9
none_shall_parse/__init__.py
CHANGED
none_shall_parse/imeis.py
CHANGED
|
@@ -47,28 +47,28 @@ def is_valid_luhn(n: Union[str, int]) -> bool:
|
|
|
47
47
|
e
|
|
48
48
|
for e in n
|
|
49
49
|
if e
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
in [
|
|
51
|
+
0,
|
|
52
|
+
1,
|
|
53
|
+
2,
|
|
54
|
+
3,
|
|
55
|
+
4,
|
|
56
|
+
5,
|
|
57
|
+
6,
|
|
58
|
+
7,
|
|
59
|
+
8,
|
|
60
|
+
9,
|
|
61
|
+
"0",
|
|
62
|
+
"1",
|
|
63
|
+
"2",
|
|
64
|
+
"3",
|
|
65
|
+
"4",
|
|
66
|
+
"5",
|
|
67
|
+
"6",
|
|
68
|
+
"7",
|
|
69
|
+
"8",
|
|
70
|
+
"9",
|
|
71
|
+
]
|
|
72
72
|
]
|
|
73
73
|
)
|
|
74
74
|
chars = [int(ch) for ch in str(n)][::-1] # Reversed Digits
|
|
@@ -135,16 +135,16 @@ def get_tac_from_imei(n: Union[str, int]) -> tuple[bool, str]:
|
|
|
135
135
|
"""
|
|
136
136
|
Determines the validity of an IMEI number and extracts its TAC if valid.
|
|
137
137
|
|
|
138
|
-
This function checks whether a provided IMEI (International Mobile Equipment
|
|
139
|
-
Identity) number is valid based on IMEI validation rules. If the given IMEI
|
|
140
|
-
is valid, the function also extracts and returns the TAC (Type Allocation
|
|
138
|
+
This function checks whether a provided IMEI (International Mobile Equipment
|
|
139
|
+
Identity) number is valid based on IMEI validation rules. If the given IMEI
|
|
140
|
+
is valid, the function also extracts and returns the TAC (Type Allocation
|
|
141
141
|
Code), which corresponds to the first 8 digits of the IMEI.
|
|
142
142
|
|
|
143
143
|
Parameters:
|
|
144
144
|
n (str): The IMEI number to be validated and processed.
|
|
145
145
|
|
|
146
146
|
Returns:
|
|
147
|
-
tuple: A tuple containing a boolean indicating whether the IMEI is valid
|
|
147
|
+
tuple: A tuple containing a boolean indicating whether the IMEI is valid
|
|
148
148
|
and a string representing the TAC if valid or a placeholder if invalid.
|
|
149
149
|
"""
|
|
150
150
|
tac = "Not a Valid IMEI"
|
|
@@ -188,9 +188,9 @@ def increment_imei(n: Union[str, int]) -> tuple[bool, str]:
|
|
|
188
188
|
"""
|
|
189
189
|
Determines if a given IMEI number is valid and increments it by 1 if valid.
|
|
190
190
|
|
|
191
|
-
This function first checks if the provided IMEI number is valid using the
|
|
191
|
+
This function first checks if the provided IMEI number is valid using the
|
|
192
192
|
is_valid_imei function. If the input is a valid IMEI, it increments the IMEI
|
|
193
|
-
value by 1 while retaining only the first 14 digits. If the input is not valid,
|
|
193
|
+
value by 1 while retaining only the first 14 digits. If the input is not valid,
|
|
194
194
|
it returns a predefined invalid result.
|
|
195
195
|
|
|
196
196
|
Parameters:
|
|
@@ -199,8 +199,8 @@ def increment_imei(n: Union[str, int]) -> tuple[bool, str]:
|
|
|
199
199
|
|
|
200
200
|
Returns:
|
|
201
201
|
tuple[bool, str]
|
|
202
|
-
A tuple where the first element is a boolean indicating whether the operation
|
|
203
|
-
was successful, and the second element is a string containing the incremented
|
|
202
|
+
A tuple where the first element is a boolean indicating whether the operation
|
|
203
|
+
was successful, and the second element is a string containing the incremented
|
|
204
204
|
IMEI number if valid or an error message if not valid.
|
|
205
205
|
"""
|
|
206
206
|
result = "Not a Valid IMEI"
|
none_shall_parse/lists.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import collections
|
|
2
2
|
from typing import Iterable, Generator, Any, List
|
|
3
|
+
|
|
3
4
|
from .types import T
|
|
4
5
|
|
|
6
|
+
|
|
5
7
|
def flatten(some_list: Iterable) -> Generator[Any, None, None]:
|
|
6
8
|
"""
|
|
7
9
|
Flattens a nested iterable into a one-dimensional generator.
|
|
@@ -44,4 +46,3 @@ def safe_list_get(lst: List[T], idx: int, default: T) -> T:
|
|
|
44
46
|
return lst[idx]
|
|
45
47
|
except IndexError:
|
|
46
48
|
return default
|
|
47
|
-
|
none_shall_parse/parse.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from typing import Callable, Any
|
|
2
2
|
from typing import Union
|
|
3
3
|
|
|
4
|
-
from
|
|
5
|
-
from
|
|
4
|
+
from .strings import slugify
|
|
5
|
+
from .types import ChoicesType, StringLike
|
|
6
6
|
|
|
7
|
-
_true_set = {
|
|
8
|
-
_false_set = {
|
|
7
|
+
_true_set = {"yes", "true", "t", "y", "1"}
|
|
8
|
+
_false_set = {"no", "false", "f", "n", "0"}
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def str_to_bool(v: Any, raise_exc: bool = False) -> bool | None:
|
|
@@ -123,8 +123,8 @@ def int_or_none(s: int | float | str | None) -> int | None:
|
|
|
123
123
|
|
|
124
124
|
|
|
125
125
|
def choices_code_to_string(
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
choices: ChoicesType, default: str | None = None, to_slug: bool = False
|
|
127
|
+
) -> Callable[[Union[int, StringLike]], StringLike | None]:
|
|
128
128
|
"""
|
|
129
129
|
Converts a code to a corresponding string representation based on provided choices.
|
|
130
130
|
The function allows optional fallback to a default value and can slugify the resulting string
|
|
@@ -157,8 +157,8 @@ def choices_code_to_string(
|
|
|
157
157
|
|
|
158
158
|
|
|
159
159
|
def choices_string_to_code(
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
choices: ChoicesType, default: Any = None, to_lower: bool = False
|
|
161
|
+
) -> Callable[[str], Union[int, str, None]]:
|
|
162
162
|
"""
|
|
163
163
|
Converts a dictionary of choices into a callable function that maps input strings
|
|
164
164
|
to their corresponding codes. This helper function is particularly useful for handling
|
none_shall_parse/strings.py
CHANGED
|
@@ -9,7 +9,8 @@ import unicodedata
|
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
11
|
_control_chars = "".join(
|
|
12
|
-
map(chr, itertools.chain(range(0x00, 0x20), range(0x7F, 0xA0)))
|
|
12
|
+
map(chr, itertools.chain(range(0x00, 0x20), range(0x7F, 0xA0)))
|
|
13
|
+
)
|
|
13
14
|
_re_control_char = re.compile("[%s]" % re.escape(_control_chars))
|
|
14
15
|
_re_combine_whitespace = re.compile(r"\s+")
|
|
15
16
|
|
|
@@ -74,8 +75,8 @@ def is_quoted_string(s: str, strip: bool = False) -> tuple[bool, str]:
|
|
|
74
75
|
"""
|
|
75
76
|
Checks if a given string is enclosed in quotes and optionally strips the quotes.
|
|
76
77
|
|
|
77
|
-
The function determines whether a given string starts and ends with matching quotes,
|
|
78
|
-
either single quotes (') or double quotes ("). If the string is quoted and
|
|
78
|
+
The function determines whether a given string starts and ends with matching quotes,
|
|
79
|
+
either single quotes (') or double quotes ("). If the string is quoted and
|
|
79
80
|
the `strip` parameter is set to True, it removes the enclosing quotes and returns
|
|
80
81
|
the unquoted string.
|
|
81
82
|
|
|
@@ -88,8 +89,8 @@ def is_quoted_string(s: str, strip: bool = False) -> tuple[bool, str]:
|
|
|
88
89
|
|
|
89
90
|
Returns:
|
|
90
91
|
tuple[bool, str]
|
|
91
|
-
A tuple where the first element is a boolean indicating whether the string
|
|
92
|
-
is quoted, and the second element is the original string or the stripped
|
|
92
|
+
A tuple where the first element is a boolean indicating whether the string
|
|
93
|
+
is quoted, and the second element is the original string or the stripped
|
|
93
94
|
version if `strip` is True.
|
|
94
95
|
"""
|
|
95
96
|
is_quoted = False
|
|
@@ -131,7 +132,7 @@ def is_numeric_string(s: str, convert: bool = False) -> tuple[bool, str | int |
|
|
|
131
132
|
tuple
|
|
132
133
|
A tuple containing a boolean and the result:
|
|
133
134
|
- A boolean indicating whether the input string is numeric or not.
|
|
134
|
-
- The numeric value if `convert` is True and the string is numeric;
|
|
135
|
+
- The numeric value if `convert` is True and the string is numeric;
|
|
135
136
|
otherwise, the original string.
|
|
136
137
|
"""
|
|
137
138
|
is_numeric = False
|
|
@@ -218,15 +219,15 @@ def calc_hash(*args: Any) -> str:
|
|
|
218
219
|
Returns:
|
|
219
220
|
str: The computed SHA-1 hash as a hexadecimal string.
|
|
220
221
|
"""
|
|
221
|
-
s =
|
|
222
|
+
s = "_".join(map(str, args))
|
|
222
223
|
return hashlib.sha1(s.encode("utf-16")).hexdigest()
|
|
223
224
|
|
|
224
225
|
|
|
225
226
|
def generate_random_password(n: int = 10) -> str:
|
|
226
227
|
"""
|
|
227
|
-
Generates a random password meeting specific criteria for complexity. The
|
|
228
|
-
function ensures the password contains at least one lowercase letter, one
|
|
229
|
-
uppercase letter, and at least three numeric digits. The length of the
|
|
228
|
+
Generates a random password meeting specific criteria for complexity. The
|
|
229
|
+
function ensures the password contains at least one lowercase letter, one
|
|
230
|
+
uppercase letter, and at least three numeric digits. The length of the
|
|
230
231
|
password can be customized using the 'n' parameter.
|
|
231
232
|
|
|
232
233
|
Parameters:
|
|
@@ -239,9 +240,9 @@ def generate_random_password(n: int = 10) -> str:
|
|
|
239
240
|
while True:
|
|
240
241
|
password = "".join(secrets.choice(alphabet) for i in range(n))
|
|
241
242
|
if (
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
any(c.islower() for c in password)
|
|
244
|
+
and any(c.isupper() for c in password)
|
|
245
|
+
and sum(c.isdigit() for c in password) >= 3
|
|
245
246
|
):
|
|
246
247
|
break
|
|
247
248
|
return password
|
none_shall_parse/types.py
CHANGED
|
@@ -12,6 +12,7 @@ class StringLike(Protocol):
|
|
|
12
12
|
commonly used string manipulation methods. Objects adhering to
|
|
13
13
|
this protocol can mimic the behavior of standard Python strings.
|
|
14
14
|
"""
|
|
15
|
+
|
|
15
16
|
def __str__(self) -> str: ...
|
|
16
17
|
def __len__(self) -> int: ...
|
|
17
18
|
def __add__(self, other: str) -> str: ...
|
|
@@ -28,4 +29,4 @@ class StringLike(Protocol):
|
|
|
28
29
|
|
|
29
30
|
ChoicesType = Sequence[Tuple[Union[int, str], StringLike]]
|
|
30
31
|
|
|
31
|
-
T = TypeVar(
|
|
32
|
+
T = TypeVar("T")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: none-shall-parse
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Trinity Shared Python utilities.
|
|
5
5
|
Author: Andries Niemandt, Jan Badenhorst
|
|
6
6
|
Author-email: Andries Niemandt <andries.niemandt@trintel.co.za>, Jan Badenhorst <jan@trintel.co.za>
|
|
@@ -53,7 +53,7 @@ pip install none-shall-parse
|
|
|
53
53
|
|
|
54
54
|
## Development Quick Start
|
|
55
55
|
|
|
56
|
-
#### To build
|
|
56
|
+
#### To build and publish to pypi:
|
|
57
57
|
|
|
58
58
|
Update the version in the `pyproject.toml` file, then:
|
|
59
59
|
```bash
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
none_shall_parse/__init__.py,sha256=3uhWV40LVbfVnCtRGCDLdTKyBBcoH56zgIApAQWWN0Q,549
|
|
2
|
+
none_shall_parse/imeis.py,sha256=o-TgbWDU4tmv1MHnAxfLCeZUpCZ8lt7VKOHrIeBmUFE,6837
|
|
3
|
+
none_shall_parse/lists.py,sha256=buAahex2iOYXZIcGOFfE9y9BYgBgvo3RilIiv1BALJ8,1706
|
|
4
|
+
none_shall_parse/parse.py,sha256=77bXZAtwFksRwuZ9Ax0lPxEjFpyjkQBqRa5mBc1WkF4,6843
|
|
5
|
+
none_shall_parse/strings.py,sha256=Eqrl8Sb-wOzjTu1_bbO-ALljlDKVa-1LcpcACqOmZuE,7931
|
|
6
|
+
none_shall_parse/types.py,sha256=PsljcR1UyyZZizm50wgyZPRNaeYvInSQoPS3i0RLgKo,1123
|
|
7
|
+
none_shall_parse-0.3.1.dist-info/WHEEL,sha256=Jb20R3Ili4n9P1fcwuLup21eQ5r9WXhs4_qy7VTrgPI,79
|
|
8
|
+
none_shall_parse-0.3.1.dist-info/METADATA,sha256=3ISK09CuJPT5ZdlRboWS2wH0s_u6RBt1WeeFTBCvdfQ,1677
|
|
9
|
+
none_shall_parse-0.3.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
none_shall_parse/__init__.py,sha256=ElNUb98vffLm3_IvHJWLklIPWvr0p84SdpVLHof2n1o,548
|
|
2
|
-
none_shall_parse/imeis.py,sha256=sNLGeeGU0K4SvTb4xp-yuV0P3c-JjYDanble9f09uBc,6911
|
|
3
|
-
none_shall_parse/lists.py,sha256=3s9Oi0-aUVcfzhIdW6N9-z7ZI56VxTa3WRDj1zAiJQI,1705
|
|
4
|
-
none_shall_parse/parse.py,sha256=U4FUuQqtqgEKEC-3blUd78EFYyQHbBgbWW194VXdcYw,6905
|
|
5
|
-
none_shall_parse/strings.py,sha256=HAcaDOHkrUZ_pDfNjfh89GQ5EJeBo6WjH5of1B11vos,7950
|
|
6
|
-
none_shall_parse/types.py,sha256=SGHhzzIxC9_89STRa9eAQt18_cZVuklpj2cUnyrW8l0,1121
|
|
7
|
-
none_shall_parse-0.3.0.dist-info/WHEEL,sha256=4n27za1eEkOnA7dNjN6C5-O2rUiw6iapszm14Uj-Qmk,79
|
|
8
|
-
none_shall_parse-0.3.0.dist-info/METADATA,sha256=d-W1OJJiftIMIVXi3EzRYfgAWLu_74FYrchoBHmROOs,1676
|
|
9
|
-
none_shall_parse-0.3.0.dist-info/RECORD,,
|