none-shall-parse 0.4.1__tar.gz → 0.4.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.
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/PKG-INFO +1 -1
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/pyproject.toml +1 -1
- none_shall_parse-0.4.2/src/none_shall_parse/__init__.py +133 -0
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/src/none_shall_parse/imeis.py +7 -8
- none_shall_parse-0.4.1/src/none_shall_parse/__init__.py +0 -15
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/README.md +0 -0
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/src/none_shall_parse/dates.py +0 -0
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/src/none_shall_parse/lists.py +0 -0
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/src/none_shall_parse/parse.py +0 -0
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/src/none_shall_parse/strings.py +0 -0
- {none_shall_parse-0.4.1 → none_shall_parse-0.4.2}/src/none_shall_parse/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: none-shall-parse
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
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>
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Trinity Shared Python utilities.
|
|
2
|
+
|
|
3
|
+
A collection of shared utilities for Trinity projects.
|
|
4
|
+
|
|
5
|
+
Originally intended to be parsing utilities, this grew to include
|
|
6
|
+
other useful functions.
|
|
7
|
+
|
|
8
|
+
Named for its author Andries Niemandt - whose surname loosely
|
|
9
|
+
translates to "none". Combined this with our parsing intentions
|
|
10
|
+
to create a name which nods to the Black Knight in Monty Python's Holy Grail.
|
|
11
|
+
https://www.youtube.com/watch?v=zKhEw7nD9C4
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
from .dates import (
|
|
15
|
+
DateUtilsError, assert_week_start_date_is_valid,
|
|
16
|
+
assert_month_start_date_is_valid,
|
|
17
|
+
get_datetime_now, za_now,
|
|
18
|
+
za_ordinal_year_day_now,
|
|
19
|
+
za_ordinal_year_day_tomorrow, utc_epoch_start,
|
|
20
|
+
now_offset_n_minutes, now_offset_n_hours,
|
|
21
|
+
now_offset_n_days, get_datetime_tomorrow,
|
|
22
|
+
get_datetime_yesterday,
|
|
23
|
+
get_utc_datetime_offset_n_days,
|
|
24
|
+
epoch_to_datetime, epoch_to_utc_datetime,
|
|
25
|
+
is_office_hours_in_timezone,
|
|
26
|
+
get_datetime_from_ordinal_and_sentinel,
|
|
27
|
+
day_span, week_span, month_span, arb_span,
|
|
28
|
+
calendar_month_start_end, unix_timestamp,
|
|
29
|
+
sentinel_date_and_ordinal_to_date,
|
|
30
|
+
seconds_to_end_of_month, standard_tz_timestring,
|
|
31
|
+
get_notice_end_date, dt_to_za_time_string,
|
|
32
|
+
months_ago_selection, is_aware, make_aware,
|
|
33
|
+
unaware_to_utc_aware, timer_decorator, ZA_TZ,
|
|
34
|
+
UTC_TZ, keys_for_span_func,
|
|
35
|
+
)
|
|
36
|
+
from .imeis import (
|
|
37
|
+
get_luhn_digit,
|
|
38
|
+
is_valid_luhn,
|
|
39
|
+
is_valid_imei,
|
|
40
|
+
normalize_imei,
|
|
41
|
+
get_tac_from_imei,
|
|
42
|
+
decrement_imei,
|
|
43
|
+
increment_imei,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
from .lists import (
|
|
47
|
+
flatten,
|
|
48
|
+
safe_list_get,
|
|
49
|
+
)
|
|
50
|
+
from .parse import (
|
|
51
|
+
str_to_bool,
|
|
52
|
+
is_true,
|
|
53
|
+
is_false,
|
|
54
|
+
str_to_strs_list,
|
|
55
|
+
int_to_bool,
|
|
56
|
+
int_or_none,
|
|
57
|
+
choices_code_to_string,
|
|
58
|
+
choices_string_to_code,
|
|
59
|
+
none_or_empty,
|
|
60
|
+
)
|
|
61
|
+
from .strings import (
|
|
62
|
+
slugify,
|
|
63
|
+
random_16,
|
|
64
|
+
to_human_string,
|
|
65
|
+
is_quoted_string,
|
|
66
|
+
is_numeric_string,
|
|
67
|
+
custom_slug,
|
|
68
|
+
b64_encode,
|
|
69
|
+
b64_decode,
|
|
70
|
+
calc_hash,
|
|
71
|
+
generate_random_password,
|
|
72
|
+
)
|
|
73
|
+
from .types import (
|
|
74
|
+
StringLike,
|
|
75
|
+
ChoicesType
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
__author__ = "Andries Niemandt, Jan Badenhorst"
|
|
79
|
+
__email__ = "andries.niemandt@trintel.co.za, jan@trintel.co.za"
|
|
80
|
+
__license__ = "MIT"
|
|
81
|
+
|
|
82
|
+
__all__ = (
|
|
83
|
+
"DateUtilsError", "assert_week_start_date_is_valid",
|
|
84
|
+
"assert_month_start_date_is_valid",
|
|
85
|
+
"get_datetime_now", "za_now",
|
|
86
|
+
"za_ordinal_year_day_now",
|
|
87
|
+
"za_ordinal_year_day_tomorrow", "utc_epoch_start",
|
|
88
|
+
"now_offset_n_minutes", "now_offset_n_hours",
|
|
89
|
+
"now_offset_n_days", "get_datetime_tomorrow",
|
|
90
|
+
"get_datetime_yesterday",
|
|
91
|
+
"get_utc_datetime_offset_n_days",
|
|
92
|
+
"epoch_to_datetime", "epoch_to_utc_datetime",
|
|
93
|
+
"is_office_hours_in_timezone",
|
|
94
|
+
"get_datetime_from_ordinal_and_sentinel",
|
|
95
|
+
"day_span", "week_span", "month_span", "arb_span",
|
|
96
|
+
"calendar_month_start_end", "unix_timestamp",
|
|
97
|
+
"sentinel_date_and_ordinal_to_date",
|
|
98
|
+
"seconds_to_end_of_month", "standard_tz_timestring",
|
|
99
|
+
"get_notice_end_date", "dt_to_za_time_string",
|
|
100
|
+
"months_ago_selection", "is_aware", "make_aware",
|
|
101
|
+
"unaware_to_utc_aware", "timer_decorator", "ZA_TZ",
|
|
102
|
+
"UTC_TZ", "keys_for_span_func",
|
|
103
|
+
"get_luhn_digit",
|
|
104
|
+
"is_valid_luhn",
|
|
105
|
+
"is_valid_imei",
|
|
106
|
+
"normalize_imei",
|
|
107
|
+
"get_tac_from_imei",
|
|
108
|
+
"decrement_imei",
|
|
109
|
+
"increment_imei",
|
|
110
|
+
"flatten",
|
|
111
|
+
"safe_list_get",
|
|
112
|
+
"str_to_bool",
|
|
113
|
+
"is_true",
|
|
114
|
+
"is_false",
|
|
115
|
+
"str_to_strs_list",
|
|
116
|
+
"int_to_bool",
|
|
117
|
+
"int_or_none",
|
|
118
|
+
"choices_code_to_string",
|
|
119
|
+
"choices_string_to_code",
|
|
120
|
+
"none_or_empty",
|
|
121
|
+
"slugify",
|
|
122
|
+
"random_16",
|
|
123
|
+
"to_human_string",
|
|
124
|
+
"is_quoted_string",
|
|
125
|
+
"is_numeric_string",
|
|
126
|
+
"custom_slug",
|
|
127
|
+
"b64_encode",
|
|
128
|
+
"b64_decode",
|
|
129
|
+
"calc_hash",
|
|
130
|
+
"generate_random_password",
|
|
131
|
+
"StringLike",
|
|
132
|
+
"ChoicesType"
|
|
133
|
+
)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
from typing import Union
|
|
2
1
|
|
|
3
2
|
LUHN_DOUBLES = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
|
|
4
3
|
|
|
5
4
|
|
|
6
|
-
def get_luhn_digit(n:
|
|
5
|
+
def get_luhn_digit(n: str | int) -> int:
|
|
7
6
|
"""
|
|
8
7
|
Calculates the Luhn checksum digit for a given number.
|
|
9
8
|
|
|
@@ -26,7 +25,7 @@ def get_luhn_digit(n: Union[str, int]) -> int:
|
|
|
26
25
|
return divmod(check, 10)[1]
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
def is_valid_luhn(n:
|
|
28
|
+
def is_valid_luhn(n: str | int) -> bool:
|
|
30
29
|
"""
|
|
31
30
|
Determines if a given number, represented as a string or integer, adheres
|
|
32
31
|
to the Luhn algorithm.
|
|
@@ -78,7 +77,7 @@ def is_valid_luhn(n: Union[str, int]) -> bool:
|
|
|
78
77
|
return divmod(final, 10)[1] == 0
|
|
79
78
|
|
|
80
79
|
|
|
81
|
-
def is_valid_imei(n:
|
|
80
|
+
def is_valid_imei(n: str | int) -> bool:
|
|
82
81
|
"""
|
|
83
82
|
Determines whether the given number is a valid IMEI (International Mobile
|
|
84
83
|
Equipment Identity) number.
|
|
@@ -98,7 +97,7 @@ def is_valid_imei(n: Union[str, int]) -> bool:
|
|
|
98
97
|
return len(str(n)) == 15 and is_valid_luhn(n)
|
|
99
98
|
|
|
100
99
|
|
|
101
|
-
def normalize_imei(c:
|
|
100
|
+
def normalize_imei(c: str | int) -> str:
|
|
102
101
|
"""
|
|
103
102
|
Normalizes the given IMEI number by extracting the first 14 digits and appending
|
|
104
103
|
the calculated Luhn check digit to make it a valid IMEI.
|
|
@@ -131,7 +130,7 @@ def normalize_imei(c: Union[str, int]) -> str:
|
|
|
131
130
|
return "%s%s" % (t, check_digit)
|
|
132
131
|
|
|
133
132
|
|
|
134
|
-
def get_tac_from_imei(n:
|
|
133
|
+
def get_tac_from_imei(n: str | int) -> tuple[bool, str]:
|
|
135
134
|
"""
|
|
136
135
|
Determines the validity of an IMEI number and extracts its TAC if valid.
|
|
137
136
|
|
|
@@ -156,7 +155,7 @@ def get_tac_from_imei(n: Union[str, int]) -> tuple[bool, str]:
|
|
|
156
155
|
return True, tac
|
|
157
156
|
|
|
158
157
|
|
|
159
|
-
def decrement_imei(n:
|
|
158
|
+
def decrement_imei(n: str | int) -> tuple[bool, str]:
|
|
160
159
|
"""
|
|
161
160
|
Decrements the given IMEI number by one and normalizes it.
|
|
162
161
|
|
|
@@ -184,7 +183,7 @@ def decrement_imei(n: Union[str, int]) -> tuple[bool, str]:
|
|
|
184
183
|
return True, result
|
|
185
184
|
|
|
186
185
|
|
|
187
|
-
def increment_imei(n:
|
|
186
|
+
def increment_imei(n: str | int) -> tuple[bool, str]:
|
|
188
187
|
"""
|
|
189
188
|
Determines if a given IMEI number is valid and increments it by 1 if valid.
|
|
190
189
|
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"""Trinity Shared Python utilities.
|
|
2
|
-
|
|
3
|
-
A collection of shared utilities for Trinity projects.
|
|
4
|
-
|
|
5
|
-
Originally intended to be parsing utilities, this grew to include
|
|
6
|
-
other useful functions.
|
|
7
|
-
|
|
8
|
-
Named for its author Andries Niemandt - whose surname loosely
|
|
9
|
-
translates to "none". Combined this with our parsing intentions
|
|
10
|
-
to create a name which nods to the Black Knight in Monty Python's Holy Grail.
|
|
11
|
-
https://www.youtube.com/watch?v=zKhEw7nD9C4
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
__author__ = "Andries Niemandt, Jan Badenhorst"
|
|
15
|
-
__email__ = "andries.niemandt@trintel.co.za, jan@trintel.co.za"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|