ae-base 0.3.69__py3-none-any.whl → 0.3.70__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.
- ae/base.py +33 -6
- {ae_base-0.3.69.dist-info → ae_base-0.3.70.dist-info}/METADATA +6 -6
- ae_base-0.3.70.dist-info/RECORD +7 -0
- ae_base-0.3.69.dist-info/RECORD +0 -7
- {ae_base-0.3.69.dist-info → ae_base-0.3.70.dist-info}/WHEEL +0 -0
- {ae_base-0.3.69.dist-info → ae_base-0.3.70.dist-info}/licenses/LICENSE.md +0 -0
- {ae_base-0.3.69.dist-info → ae_base-0.3.70.dist-info}/top_level.txt +0 -0
- {ae_base-0.3.69.dist-info → ae_base-0.3.70.dist-info}/zip-safe +0 -0
ae/base.py
CHANGED
|
@@ -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
|
|
|
@@ -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
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ae/base.py,sha256=hIgo28nJJr6rMV-KLvnfiAREF0wZx5EhQgnGhOANAJs,78705
|
|
2
|
+
ae_base-0.3.70.dist-info/licenses/LICENSE.md,sha256=0g3tHWG2bfmLGyuM0e0YzSXT8As8eN1b0VQIqXMWTMg,35003
|
|
3
|
+
ae_base-0.3.70.dist-info/METADATA,sha256=HjSggbiVRRnU89mVsTmMUlizZtKTNkxfYz6mo7qVspM,5470
|
|
4
|
+
ae_base-0.3.70.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
ae_base-0.3.70.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
|
|
6
|
+
ae_base-0.3.70.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
7
|
+
ae_base-0.3.70.dist-info/RECORD,,
|
ae_base-0.3.69.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
ae/base.py,sha256=6OPSCEjga6s7iOAklyen7q1WKFc3T6YhHFyW1O5F4zc,77075
|
|
2
|
-
ae_base-0.3.69.dist-info/licenses/LICENSE.md,sha256=0g3tHWG2bfmLGyuM0e0YzSXT8As8eN1b0VQIqXMWTMg,35003
|
|
3
|
-
ae_base-0.3.69.dist-info/METADATA,sha256=mlFlGyFQbldQgCNL33UOqoveoNvfYBSkh3OHFKy3miA,5469
|
|
4
|
-
ae_base-0.3.69.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
-
ae_base-0.3.69.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
|
|
6
|
-
ae_base-0.3.69.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
7
|
-
ae_base-0.3.69.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|