ae-base 0.3.68__tar.gz → 0.3.70__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.
- {ae_base-0.3.68 → ae_base-0.3.70}/LICENSE.md +1 -1
- {ae_base-0.3.68/ae_base.egg-info → ae_base-0.3.70}/PKG-INFO +6 -6
- {ae_base-0.3.68 → ae_base-0.3.70}/README.md +5 -5
- {ae_base-0.3.68 → ae_base-0.3.70}/ae/base.py +41 -14
- {ae_base-0.3.68 → ae_base-0.3.70/ae_base.egg-info}/PKG-INFO +6 -6
- {ae_base-0.3.68 → ae_base-0.3.70}/pyproject.toml +1 -1
- {ae_base-0.3.68 → ae_base-0.3.70}/setup.py +7 -7
- {ae_base-0.3.68 → ae_base-0.3.70}/tests/test_base.py +46 -16
- {ae_base-0.3.68 → ae_base-0.3.70}/ae_base.egg-info/SOURCES.txt +0 -0
- {ae_base-0.3.68 → ae_base-0.3.70}/ae_base.egg-info/dependency_links.txt +0 -0
- {ae_base-0.3.68 → ae_base-0.3.70}/ae_base.egg-info/requires.txt +0 -0
- {ae_base-0.3.68 → ae_base-0.3.70}/ae_base.egg-info/top_level.txt +0 -0
- {ae_base-0.3.68 → ae_base-0.3.70}/ae_base.egg-info/zip-safe +0 -0
- {ae_base-0.3.68 → ae_base-0.3.70}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ae_base
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.70
|
|
4
4
|
Summary: ae namespace module portion base: basic constants, helper functions and context managers
|
|
5
5
|
Home-page: https://gitlab.com/ae-group/ae_base
|
|
6
6
|
Author: AndiEcker
|
|
@@ -63,15 +63,15 @@ Dynamic: provides-extra
|
|
|
63
63
|
Dynamic: requires-python
|
|
64
64
|
Dynamic: summary
|
|
65
65
|
|
|
66
|
-
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.
|
|
67
|
-
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.
|
|
68
|
-
# base 0.3.
|
|
66
|
+
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.97 -->
|
|
67
|
+
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.namespace_root_tpls v0.3.19 -->
|
|
68
|
+
# base 0.3.70
|
|
69
69
|
|
|
70
70
|
[](
|
|
71
71
|
https://gitlab.com/ae-group/ae_base)
|
|
72
72
|
[](
|
|
74
|
+
https://gitlab.com/ae-group/ae_base/-/tree/release0.3.70)
|
|
75
75
|
[](
|
|
76
76
|
https://pypi.org/project/ae-base/#history)
|
|
77
77
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.
|
|
2
|
-
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.
|
|
3
|
-
# base 0.3.
|
|
1
|
+
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.97 -->
|
|
2
|
+
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.namespace_root_tpls v0.3.19 -->
|
|
3
|
+
# base 0.3.70
|
|
4
4
|
|
|
5
5
|
[](
|
|
6
6
|
https://gitlab.com/ae-group/ae_base)
|
|
7
7
|
[](
|
|
9
|
+
https://gitlab.com/ae-group/ae_base/-/tree/release0.3.70)
|
|
10
10
|
[](
|
|
11
11
|
https://pypi.org/project/ae-base/#history)
|
|
12
12
|
|
|
@@ -42,7 +42,7 @@ inspect the operating system and manage environment variables.
|
|
|
42
42
|
:func:`~ae.core.start_app_service` and :func:`~ae.core.request_app_permissions`.
|
|
43
43
|
|
|
44
44
|
OS information
|
|
45
|
-
|
|
45
|
+
^^^^^^^^^^^^^^
|
|
46
46
|
|
|
47
47
|
* :data:`os_platform`: a string identifying the operating system (e.g., 'linux', 'win32', 'android', 'ios').
|
|
48
48
|
* :data:`os_device_id`: a string with the ID/name of the device.
|
|
@@ -53,7 +53,7 @@ OS information
|
|
|
53
53
|
* :func:`sys_env_text`: compiles a formatted text block with system environment information, useful for logging.
|
|
54
54
|
|
|
55
55
|
environment variables & `.env` files
|
|
56
|
-
|
|
56
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
57
57
|
|
|
58
58
|
* :func:`env_str`: retrieves the string value of an OS environment variable, with an option to automatically convert the
|
|
59
59
|
variable name to the conventional format.
|
|
@@ -114,7 +114,7 @@ dynamically inspect modules, execution frames, and variables on the call stack.
|
|
|
114
114
|
networking utilities
|
|
115
115
|
--------------------
|
|
116
116
|
|
|
117
|
-
* :func:`url_failure`: determines if and why
|
|
117
|
+
* :func:`url_failure`: determines if and why an HTTP|FTP target is unavailable.
|
|
118
118
|
* :func:`mask_url`: hides or replaces the password/token portion of a URL for safe logging.
|
|
119
119
|
|
|
120
120
|
|
|
@@ -124,18 +124,18 @@ general utilities & helpers
|
|
|
124
124
|
a collection of miscellaneous mathematical, date/time, and other standalone helper functions.
|
|
125
125
|
|
|
126
126
|
mathematical
|
|
127
|
-
|
|
127
|
+
^^^^^^^^^^^^
|
|
128
128
|
|
|
129
129
|
* :func:`sign`: returns the sign of a number (-1 for negative, 0 for zero, 1 for positive).
|
|
130
130
|
* :func:`round_traditional`: rounds a float value using traditional rounding rules (e.g., `0.5` rounds up).
|
|
131
131
|
|
|
132
132
|
date & time
|
|
133
|
-
|
|
133
|
+
^^^^^^^^^^^
|
|
134
134
|
* :func:`utc_datetime`: Returns the current date and time as a timezone-naive `datetime` object in UTC.
|
|
135
135
|
* :func:`now_str`: creates a compact, sortable timestamp string from the current UTC time.
|
|
136
136
|
|
|
137
137
|
miscellaneous
|
|
138
|
-
|
|
138
|
+
^^^^^^^^^^^^^
|
|
139
139
|
* :func:`dummy_function`: a null function that accepts any arguments and returns `None`.
|
|
140
140
|
|
|
141
141
|
|
|
@@ -158,7 +158,7 @@ base constants
|
|
|
158
158
|
predefined constants for project structure, file conventions, and default settings.
|
|
159
159
|
|
|
160
160
|
project & file structure
|
|
161
|
-
|
|
161
|
+
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
162
162
|
|
|
163
163
|
* :data:`DOCS_FOLDER`: default name for a project's documentation folder ('docs').
|
|
164
164
|
* :data:`TESTS_FOLDER`: default name for a project's tests folder ('tests').
|
|
@@ -176,7 +176,7 @@ project & file structure
|
|
|
176
176
|
:mod:`ae.updater` and :mod:`aedev.project_manager`)
|
|
177
177
|
|
|
178
178
|
formats & default settings
|
|
179
|
-
|
|
179
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
180
180
|
|
|
181
181
|
* :data:`DATE_ISO`: ISO format string for dates ("%Y-%m-%d").
|
|
182
182
|
* :data:`DATE_TIME_ISO`: ISO format string for :mod:`datetime.datetime` dates ("%Y-%m-%d %H:%M:%S.%f").
|
|
@@ -200,7 +200,7 @@ simplify file system interactions with wrappers and context managers.
|
|
|
200
200
|
* :func:`in_wd`: a context manager that temporarily switches the current working directory.
|
|
201
201
|
|
|
202
202
|
os.path shortcuts
|
|
203
|
-
|
|
203
|
+
^^^^^^^^^^^^^^^^^
|
|
204
204
|
|
|
205
205
|
the following are direct references to functions in the :mod:`os.path` module for convenient and quicker access:
|
|
206
206
|
|
|
@@ -218,6 +218,7 @@ the following are direct references to functions in the :mod:`os.path` module fo
|
|
|
218
218
|
* :data:`os_path_splitext`: :func:`os.path.splitext`
|
|
219
219
|
"""
|
|
220
220
|
# pylint: disable=too-many-lines
|
|
221
|
+
import base64
|
|
221
222
|
import datetime
|
|
222
223
|
import getpass
|
|
223
224
|
import importlib.abc
|
|
@@ -240,12 +241,12 @@ from importlib.machinery import ModuleSpec
|
|
|
240
241
|
from inspect import getinnerframes, getouterframes, getsourcefile
|
|
241
242
|
from urllib.error import HTTPError, URLError
|
|
242
243
|
from urllib.parse import urlparse, urlunparse
|
|
243
|
-
from urllib.request import urlopen
|
|
244
|
+
from urllib.request import Request, urlopen
|
|
244
245
|
from types import ModuleType
|
|
245
246
|
from typing import Any, Callable, Generator, Iterable, MutableMapping, Optional, Union, cast
|
|
246
247
|
|
|
247
248
|
|
|
248
|
-
__version__ = '0.3.
|
|
249
|
+
__version__ = '0.3.70'
|
|
249
250
|
|
|
250
251
|
|
|
251
252
|
os_path_abspath = os.path.abspath
|
|
@@ -1316,18 +1317,44 @@ def to_ascii(unicode_str: str) -> str:
|
|
|
1316
1317
|
return "".join([c for c in nfkd_form if not unicodedata.combining(c)]).replace('ß', "ss").replace('€', "Euro")
|
|
1317
1318
|
|
|
1318
1319
|
|
|
1319
|
-
|
|
1320
|
+
# pylint: disable-next=too-many-arguments,too-many-positional-arguments,too-many-return-statements
|
|
1321
|
+
def url_failure(url: str, token: str = "", username: str = "", password: str = "", git_repo: bool = False,
|
|
1322
|
+
timeout: Optional[float] = None) -> str:
|
|
1320
1323
|
""" determine if and why an FTP or HTTP[S] target is not available via a GET request.
|
|
1321
1324
|
|
|
1322
|
-
:param url: URL of
|
|
1325
|
+
:param url: URL of a target|page|file to check (not downloaded, fetching only the header).
|
|
1326
|
+
:param token: optional bearer token to authenticate (only for HTTPS protocol).
|
|
1327
|
+
:param username: optional username to authenticate (for HTTPS, together with the password argument).
|
|
1328
|
+
:param password: optional password to authenticate (for HTTPS, together with the username argument).
|
|
1329
|
+
:param git_repo: optimized check for Git repository HTTP servers/sites (like GitHub, GitLab, Bitbucket,
|
|
1330
|
+
Gitea, SourceHut, Mercury, etc. as long as they implement Smart HTTP).
|
|
1323
1331
|
:param timeout: connection timeout in seconds (see :func:`urllib.request.urlopen`).
|
|
1324
1332
|
:return: empty string if target header is available, else an error description. if an
|
|
1325
1333
|
FTP|HTTP response error occurred then the error/status code
|
|
1326
1334
|
will be returned in the first 3 characters.
|
|
1335
|
+
|
|
1336
|
+
.. note::
|
|
1337
|
+
credentials for server authentication can be specified either (1) embedded into the specified url argument,
|
|
1338
|
+
(2) as bearer token in the token argument or (3) via the username/password arguments. in all cases the
|
|
1339
|
+
functino will remove these secrets from the returned error description string.
|
|
1327
1340
|
"""
|
|
1341
|
+
if git_repo:
|
|
1342
|
+
if not url.endswith(".git"):
|
|
1343
|
+
url += ".git"
|
|
1344
|
+
url += "/info/refs?service=git-upload-pack"
|
|
1345
|
+
|
|
1346
|
+
headers = {}
|
|
1347
|
+
if token:
|
|
1348
|
+
assert not username and not password, "url_failure accepts either a token or username/password, not both"
|
|
1349
|
+
headers['Authorization'] = "Bearer " + token
|
|
1350
|
+
elif username or password:
|
|
1351
|
+
creds = f"{username}:{password}".encode('utf-8')
|
|
1352
|
+
headers['Authorization'] = "Basic " + base64.b64encode(creds).decode('utf-8')
|
|
1353
|
+
|
|
1328
1354
|
# noinspection PyBroadException
|
|
1329
1355
|
try:
|
|
1330
|
-
|
|
1356
|
+
request = Request(url, method='GET', headers=headers)
|
|
1357
|
+
with urlopen(request, timeout=timeout) as response: # open connection and only read the header
|
|
1331
1358
|
status = response.getcode() # no need to call response.read()
|
|
1332
1359
|
return "" if 200 <= status < 300 else f"{status} {mask_url(url)} {response.reason=}"
|
|
1333
1360
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ae_base
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.70
|
|
4
4
|
Summary: ae namespace module portion base: basic constants, helper functions and context managers
|
|
5
5
|
Home-page: https://gitlab.com/ae-group/ae_base
|
|
6
6
|
Author: AndiEcker
|
|
@@ -63,15 +63,15 @@ Dynamic: provides-extra
|
|
|
63
63
|
Dynamic: requires-python
|
|
64
64
|
Dynamic: summary
|
|
65
65
|
|
|
66
|
-
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.
|
|
67
|
-
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.
|
|
68
|
-
# base 0.3.
|
|
66
|
+
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.97 -->
|
|
67
|
+
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.namespace_root_tpls v0.3.19 -->
|
|
68
|
+
# base 0.3.70
|
|
69
69
|
|
|
70
70
|
[](
|
|
71
71
|
https://gitlab.com/ae-group/ae_base)
|
|
72
72
|
[](
|
|
74
|
+
https://gitlab.com/ae-group/ae_base/-/tree/release0.3.70)
|
|
75
75
|
[](
|
|
76
76
|
https://pypi.org/project/ae-base/#history)
|
|
77
77
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.project_tpls v0.3.
|
|
1
|
+
# THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.project_tpls v0.3.56
|
|
2
2
|
""" setup of ae namespace module portion base: basic constants, helper functions and context managers. """
|
|
3
3
|
# noinspection PyUnresolvedReferences
|
|
4
4
|
import sys
|
|
@@ -23,15 +23,15 @@ setup_kwargs = {
|
|
|
23
23
|
'install_requires': [],
|
|
24
24
|
'keywords': ['configuration', 'development', 'environment', 'productivity'],
|
|
25
25
|
'license': 'GPL-3.0-or-later',
|
|
26
|
-
'long_description': ('<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.
|
|
27
|
-
'<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.
|
|
28
|
-
'# base 0.3.
|
|
26
|
+
'long_description': ('<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.97 -->\n'
|
|
27
|
+
'<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.namespace_root_tpls v0.3.19 -->\n'
|
|
28
|
+
'# base 0.3.70\n'
|
|
29
29
|
'\n'
|
|
30
30
|
'[](\n'
|
|
31
31
|
' https://gitlab.com/ae-group/ae_base)\n'
|
|
32
32
|
'[](\n'
|
|
34
|
+
' https://gitlab.com/ae-group/ae_base/-/tree/release0.3.70)\n'
|
|
35
35
|
'[](\n'
|
|
36
36
|
' https://pypi.org/project/ae-base/#history)\n'
|
|
37
37
|
'\n'
|
|
@@ -108,7 +108,7 @@ setup_kwargs = {
|
|
|
108
108
|
'Source': 'https://ae.readthedocs.io/en/latest/_modules/ae/base.html'},
|
|
109
109
|
'python_requires': '>=3.9',
|
|
110
110
|
'url': 'https://gitlab.com/ae-group/ae_base',
|
|
111
|
-
'version': '0.3.
|
|
111
|
+
'version': '0.3.70',
|
|
112
112
|
'zip_safe': True,
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
""" ae.base unit tests """
|
|
2
2
|
import datetime
|
|
3
3
|
import os
|
|
4
|
+
import time
|
|
5
|
+
|
|
4
6
|
import pytest
|
|
5
7
|
import shutil
|
|
6
8
|
import socket
|
|
@@ -1072,18 +1074,25 @@ class TestBaseHelpers:
|
|
|
1072
1074
|
|
|
1073
1075
|
assert not url_failure("https://gitlab.com/ae-group/ae_base.git")
|
|
1074
1076
|
|
|
1075
|
-
assert not url_failure("https://
|
|
1077
|
+
assert not url_failure("https://gitlab.com/ae-group/ae_base", git_repo=True)
|
|
1076
1078
|
|
|
1077
|
-
assert not url_failure(
|
|
1079
|
+
assert not url_failure("https://www.google.com")
|
|
1078
1080
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
+
retries = 9
|
|
1082
|
+
while True:
|
|
1083
|
+
err_msg = url_failure(f"https://httpbin.org/status/200")
|
|
1084
|
+
if not err_msg or retries == 0:
|
|
1085
|
+
break
|
|
1086
|
+
time.sleep(3)
|
|
1087
|
+
retries -= 1
|
|
1088
|
+
assert not err_msg, f"httpbin is sometimes unavailable with error 503 - retry later; {err_msg=}"
|
|
1081
1089
|
|
|
1090
|
+
def test_url_failure_authentication_errors(self):
|
|
1082
1091
|
password, domain, path = "toBeMaskedPassword", "any-not_existing-host_domain.zzz", "any/not/existing/url/path"
|
|
1083
1092
|
url = f"https://username:{password}@{domain}/{path}"
|
|
1084
1093
|
err_msg = "raised exception error message"
|
|
1085
1094
|
|
|
1086
|
-
ret = url_failure(url)
|
|
1095
|
+
ret = url_failure(url, token=password)
|
|
1087
1096
|
|
|
1088
1097
|
assert ret
|
|
1089
1098
|
assert int(ret[:3]) > 0
|
|
@@ -1091,24 +1100,21 @@ class TestBaseHelpers:
|
|
|
1091
1100
|
assert domain in ret
|
|
1092
1101
|
assert path in ret
|
|
1093
1102
|
|
|
1094
|
-
ret = url_failure(
|
|
1095
|
-
|
|
1096
|
-
assert ret
|
|
1097
|
-
assert int(ret[:3]) == 504
|
|
1098
|
-
assert ret[4:].startswith(mask_url(url2))
|
|
1099
|
-
|
|
1100
|
-
ret = url_failure(f"https://httpbin.org/delay/3", timeout=0.9)
|
|
1103
|
+
ret = url_failure(url, username="any user name", password=password)
|
|
1101
1104
|
|
|
1102
1105
|
assert ret
|
|
1103
1106
|
assert int(ret[:3]) > 0
|
|
1107
|
+
assert password not in ret
|
|
1108
|
+
assert domain in ret
|
|
1109
|
+
assert path in ret
|
|
1104
1110
|
|
|
1105
|
-
ret = url_failure(
|
|
1111
|
+
ret = url_failure(url)
|
|
1106
1112
|
|
|
1107
1113
|
assert ret
|
|
1108
1114
|
assert int(ret[:3]) > 0
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1115
|
+
assert password not in ret
|
|
1116
|
+
assert domain in ret
|
|
1117
|
+
assert path in ret
|
|
1112
1118
|
|
|
1113
1119
|
mocked_headers = cast(HTTPMessage, {})
|
|
1114
1120
|
|
|
@@ -1202,6 +1208,30 @@ class TestBaseHelpers:
|
|
|
1202
1208
|
assert domain in ret
|
|
1203
1209
|
assert path in ret
|
|
1204
1210
|
|
|
1211
|
+
def test_url_failure_ssl_errors(self):
|
|
1212
|
+
ret = url_failure(f"https://expired.badssl.com")
|
|
1213
|
+
|
|
1214
|
+
assert ret
|
|
1215
|
+
assert int(ret[:3]) > 0
|
|
1216
|
+
|
|
1217
|
+
def test_url_failure_timeout_errors(self):
|
|
1218
|
+
ret = url_failure(f"https://httpbin.org/delay/3", timeout=0.9)
|
|
1219
|
+
|
|
1220
|
+
assert ret
|
|
1221
|
+
assert int(ret[:3]) > 0
|
|
1222
|
+
|
|
1223
|
+
def test_url_failure_url_errors(self):
|
|
1224
|
+
assert url_failure("")
|
|
1225
|
+
|
|
1226
|
+
ret = url_failure(url2 := f"https://httpbin.org/status/504")
|
|
1227
|
+
|
|
1228
|
+
assert ret
|
|
1229
|
+
assert int(ret[:3]) == 504
|
|
1230
|
+
assert ret[4:].startswith(mask_url(url2))
|
|
1231
|
+
|
|
1232
|
+
with pytest.raises(AttributeError):
|
|
1233
|
+
url_failure(cast(str, 123456))
|
|
1234
|
+
|
|
1205
1235
|
def test_utc_datetime(self):
|
|
1206
1236
|
dt1 = utc_datetime()
|
|
1207
1237
|
dt2 = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|