ae-base 0.3.51__py3-none-any.whl → 0.3.53__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
@@ -32,6 +32,9 @@ sortable and compact string from a timestamp.
32
32
  base helper functions
33
33
  ---------------------
34
34
 
35
+ in order to convert and transfer Unicode character outside the 7-bit ASCII range via internet transport protocols,
36
+ like http, use the helper functions :func:`ascii_str` and :func:`str_ascii`.
37
+
35
38
  :func:`now_str` creates a timestamp string with the actual UTC date and time. the :func:`utc_datetime` provides the
36
39
  actual UTC date and time as datetime object.
37
40
 
@@ -155,6 +158,7 @@ import sys
155
158
  import unicodedata
156
159
  import warnings
157
160
 
161
+ from ast import literal_eval
158
162
  from configparser import ConfigParser, ExtendedInterpolation
159
163
  from contextlib import contextmanager
160
164
  from importlib.machinery import ModuleSpec
@@ -163,7 +167,7 @@ from types import ModuleType
163
167
  from typing import Any, Callable, Generator, Iterable, Optional, Union, cast
164
168
 
165
169
 
166
- __version__ = '0.3.51'
170
+ __version__ = '0.3.53'
167
171
 
168
172
 
169
173
  os_path_abspath = os.path.abspath
@@ -176,7 +180,7 @@ os_path_join = os.path.join
176
180
  os_path_normpath = os.path.normpath
177
181
  os_path_realpath = os.path.realpath
178
182
  os_path_relpath = os.path.relpath
179
- os_path_sep = os.path.sep
183
+ os_path_sep = os.path.sep # pylint: disable=invalid-name
180
184
  os_path_splitext = os.path.splitext
181
185
 
182
186
 
@@ -275,6 +279,24 @@ def app_name_guess() -> str:
275
279
  return defuse(app_name)
276
280
 
277
281
 
282
+ def ascii_str(unicode_str: str) -> str:
283
+ """ convert non-ASCII chars in str object to a revertible 7-bit/ASCII representation, e.g. to put in a http header.
284
+
285
+ :param unicode_str: string to encode/convert.
286
+ :return: revertible representation of the specified string, using only ASCII characters.
287
+ """
288
+ return repr(unicode_str.encode())
289
+
290
+
291
+ def str_ascii(encoded_str: str) -> str:
292
+ """ convert non-ASCII chars in str object encoded with :func:`ascii_str` back to their corresponding Unicode chars.
293
+
294
+ :param encoded_str: string to decode (covert contained ASCII-encoded characters back Unicode chars).
295
+ :return: decoded string.
296
+ """
297
+ return literal_eval(encoded_str).decode()
298
+
299
+
278
300
  def build_config_variable_values(*names_defaults: tuple[str, Any], section: str = 'app') -> tuple[Any, ...]:
279
301
  """ determine build config variable values from the ``buildozer.spec`` file in the current directory.
280
302
 
@@ -476,13 +498,14 @@ def force_encoding(text: Union[str, bytes], encoding: str = DEF_ENCODING, errors
476
498
  return enc_str.decode(encoding=encoding)
477
499
 
478
500
 
479
- class UnformattedValue:
501
+ class UnformattedValue: # pylint: disable=too-few-public-methods
480
502
  """ helper class for :func:`~ae.base.format_given` to keep placeholder with format unchanged if not found. """
481
503
  def __init__(self, key: str):
482
504
  self.key = key
483
505
 
484
506
  def __format__(self, format_spec: str):
485
507
  """ overriding Python object class method to return placeholder unchanged including the curly brackets. """
508
+ # pylint: disable=consider-using-f-string
486
509
  return "{{{}{}}}".format(self.key, ":" + format_spec if format_spec else "")
487
510
 
488
511
 
@@ -514,7 +537,7 @@ def format_given(text: str, placeholder_map: dict[str, Any], strict: bool = Fals
514
537
  formatter = GivenFormatter()
515
538
  try:
516
539
  return formatter.vformat(text, (), placeholder_map)
517
- except (ValueError, Exception) as ex:
540
+ except (ValueError, Exception) as ex: # pylint: disable=broad-except
518
541
  if strict:
519
542
  raise ex
520
543
  return text
@@ -669,8 +692,8 @@ def mask_secrets(data: Union[dict, Iterable], fragments: Iterable[str] = ('passw
669
692
  if not val_is_str and isinstance(val, Iterable):
670
693
  mask_secrets(val, fragments=fragments)
671
694
  elif is_dict and val_is_str and isinstance(idx, str):
672
- idx = idx.lower()
673
- if any(_frag in idx for _frag in fragments):
695
+ idx_lower = idx.lower()
696
+ if any(_frag in idx_lower for _frag in fragments):
674
697
  data[idx] = val[:3] + "*" * 9 # type: ignore # silly mypy not sees is_dict
675
698
 
676
699
  return data
@@ -817,6 +840,7 @@ def os_host_name() -> str:
817
840
  return defuse(platform.node()) or "indeterminableHostName"
818
841
 
819
842
 
843
+ # noinspection PyTypeChecker
820
844
  def os_local_ip() -> str:
821
845
  """ determine ip address of this system/machine in the local network (LAN or WLAN).
822
846
 
@@ -827,16 +851,16 @@ def os_local_ip() -> str:
827
851
  """
828
852
  socket1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
829
853
  try:
830
- socket1.connect(('10.255.255.255', 1)) # doesn't even have to be reachable
854
+ socket1.connect(('10.255.255.255', 1)) # doesn't even have to be reachable
831
855
  ip_address = socket1.getsockname()[0]
832
- except (OSError, IOError): # pragma: no cover
856
+ except (OSError, IOError, Exception): # pylint: disable=broad-except # pragma: no cover
833
857
  # ConnectionAbortedError, ConnectionError, ConnectionRefusedError, ConnectionResetError inherit from OSError
834
858
  socket2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
835
859
  try:
836
860
  socket2.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
837
861
  socket2.connect(('<broadcast>', 0))
838
862
  ip_address = socket2.getsockname()[0]
839
- except (OSError, IOError):
863
+ except (OSError, IOError, Exception): # pylint: disable=broad-except
840
864
  ip_address = ""
841
865
  finally:
842
866
  socket2.close()
@@ -1198,7 +1222,7 @@ def write_file(file_path: str, content: Union[str, bytes],
1198
1222
  file_handle.write(content)
1199
1223
 
1200
1224
 
1201
- class ErrorMsgMixin:
1225
+ class ErrorMsgMixin: # pylint: disable=too-few-public-methods
1202
1226
  """ mixin class providing sophisticated error message handling. """
1203
1227
  _err_msg: str = ""
1204
1228
 
@@ -1209,7 +1233,7 @@ class ErrorMsgMixin:
1209
1233
 
1210
1234
  def __init__(self):
1211
1235
  try:
1212
- from ae.core import main_app_instance # type: ignore
1236
+ from ae.core import main_app_instance # type: ignore # pylint: disable=import-outside-toplevel
1213
1237
 
1214
1238
  self.cae = cae = main_app_instance()
1215
1239
  assert cae is not None, f"{self.__class__.__name__}.__init__() called too early; main app instance not"
@@ -1218,7 +1242,7 @@ class ErrorMsgMixin:
1218
1242
  self.dpo = cae.dpo
1219
1243
  self.vpo = cae.vpo
1220
1244
 
1221
- except (ImportError, AssertionError, Exception) as exc:
1245
+ except (ImportError, AssertionError, Exception) as exc: # pylint: disable=broad-except
1222
1246
  print(f"{self.__class__.__name__}.__init__() raised {exc}; using print() instead of main app error loggers")
1223
1247
 
1224
1248
  # self.cae = None
@@ -1278,7 +1302,7 @@ if os_platform == 'android': # pragma: no
1278
1302
  if _dev_id := Settings.getString(context.getContentResolver(), 'device_name'):
1279
1303
  os_device_id = defuse(_dev_id)
1280
1304
 
1281
- except Exception:
1305
+ except Exception: # pylint: disable=broad-except
1282
1306
  pass
1283
1307
 
1284
1308
  # monkey patch the :func:`shutil.copystat` and :func:`shutil.copymode` helper functions, which are crashing on
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ae_base
3
- Version: 0.3.51
3
+ Version: 0.3.53
4
4
  Summary: ae namespace module portion base: basic constants, helper functions and context manager
5
5
  Home-page: https://gitlab.com/ae-group/ae_base
6
6
  Author: AndiEcker
@@ -69,17 +69,17 @@ Dynamic: summary
69
69
 
70
70
  <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae V0.3.95 -->
71
71
  <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_namespace_root V0.3.14 -->
72
- # base 0.3.51
72
+ # base 0.3.53
73
73
 
74
74
  [![GitLab develop](https://img.shields.io/gitlab/pipeline/ae-group/ae_base/develop?logo=python)](
75
75
  https://gitlab.com/ae-group/ae_base)
76
76
  [![LatestPyPIrelease](
77
- https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.50?logo=python)](
78
- https://gitlab.com/ae-group/ae_base/-/tree/release0.3.50)
77
+ https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.52?logo=python)](
78
+ https://gitlab.com/ae-group/ae_base/-/tree/release0.3.52)
79
79
  [![PyPIVersions](https://img.shields.io/pypi/v/ae_base)](
80
80
  https://pypi.org/project/ae-base/#history)
81
81
 
82
- >ae_base module 0.3.51.
82
+ >ae_base module 0.3.53.
83
83
 
84
84
  [![Coverage](https://ae-group.gitlab.io/ae_base/coverage.svg)](
85
85
  https://ae-group.gitlab.io/ae_base/coverage/index.html)
@@ -0,0 +1,7 @@
1
+ ae/base.py,sha256=_4JBeu42qcu1sQVzghHSZC-KWcQSTvr8BcQHjFl6ZPM,66221
2
+ ae_base-0.3.53.dist-info/licenses/LICENSE.md,sha256=uoIIfORuk4V8ZeNh6SN0EUhiU79RC-indIMFqePKVhY,35002
3
+ ae_base-0.3.53.dist-info/METADATA,sha256=ySY1EoA5JUeZh8Ri8pDc5hg5VpOjjV5mgY1KJsWc5pA,5658
4
+ ae_base-0.3.53.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
5
+ ae_base-0.3.53.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
6
+ ae_base-0.3.53.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
+ ae_base-0.3.53.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- ae/base.py,sha256=SeQfFkj2ODRqwpp2yUSLlkf0YC1dfaJQ9ZnBtZ760jo,64599
2
- ae_base-0.3.51.dist-info/licenses/LICENSE.md,sha256=uoIIfORuk4V8ZeNh6SN0EUhiU79RC-indIMFqePKVhY,35002
3
- ae_base-0.3.51.dist-info/METADATA,sha256=maz0cd02j373QhmJA1ZJ1VhKQJrFjTSxwO3f7M8N0tA,5658
4
- ae_base-0.3.51.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
5
- ae_base-0.3.51.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
6
- ae_base-0.3.51.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
- ae_base-0.3.51.dist-info/RECORD,,