ae-base 0.3.68__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 CHANGED
@@ -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 a HTTP|FTP target is unavailable.
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.68'
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
- def url_failure(url: str, timeout: Optional[float] = None) -> str: # pylint: disable=too-many-return-statements
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 an target|page|file to check (not downloaded, fetching only the header).
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
- with urlopen(url, timeout=timeout) as response: # open connection and read header
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.68
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.96 -->
67
- <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_namespace_root V0.3.14 -->
68
- # base 0.3.68
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
  [![GitLab develop](https://img.shields.io/gitlab/pipeline/ae-group/ae_base/develop?logo=python)](
71
71
  https://gitlab.com/ae-group/ae_base)
72
72
  [![LatestPyPIrelease](
73
- https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.67?logo=python)](
74
- https://gitlab.com/ae-group/ae_base/-/tree/release0.3.67)
73
+ https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.70?logo=python)](
74
+ https://gitlab.com/ae-group/ae_base/-/tree/release0.3.70)
75
75
  [![PyPIVersions](https://img.shields.io/pypi/v/ae_base)](
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,,
@@ -1,4 +1,4 @@
1
- <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.project_tpls v0.3.55 -->
1
+ <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.project_tpls v0.3.56 -->
2
2
  ### GNU GENERAL PUBLIC LICENSE
3
3
 
4
4
  Version 3, 29 June 2007
@@ -1,7 +0,0 @@
1
- ae/base.py,sha256=B4qkfPNmuDeyFCLY7t2QbDtCv2uFpE8novuc8UTgh7M,77075
2
- ae_base-0.3.68.dist-info/licenses/LICENSE.md,sha256=K2nZMCD-VuxJiIVGUFsN_TSl68W3biSTBew0_9jOUXc,35003
3
- ae_base-0.3.68.dist-info/METADATA,sha256=kQkdHTEjrkMJJgBCyls3hAJL4w2OKOagFbZf3V7sK2A,5469
4
- ae_base-0.3.68.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- ae_base-0.3.68.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
6
- ae_base-0.3.68.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
- ae_base-0.3.68.dist-info/RECORD,,