ae-base 0.3.39__py3-none-any.whl → 0.3.41__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
@@ -3,7 +3,7 @@ basic constants, helper functions and context manager
3
3
  =====================================================
4
4
 
5
5
  this module is pure python, has no external dependencies, and is providing base constants, common helper
6
- functions and context managers.
6
+ functions, useful classes and context managers.
7
7
 
8
8
 
9
9
  base constants
@@ -24,10 +24,16 @@ the constants :data:`PACKAGE_NAME`, :data:`PACKAGE_DOMAIN` and :data:`PERMISSION
24
24
  on mobile devices. to avoid redundancies, these values get loaded from the
25
25
  :data:`build config file <BUILD_CONFIG_FILE>` - if it exists in the current working directory.
26
26
 
27
+ with the help of the format string constant :data:`NOW_STR_FORMAT` and the function :func:`now_str` you can create a
28
+ sortable and compact string from a timestamp.
29
+
27
30
 
28
31
  base helper functions
29
32
  ---------------------
30
33
 
34
+ :func:`now_str` creates a timestamp string with the actual UTC date and time. the :func:`utc_datetime` provides the
35
+ actual UTC date and time as datetime object.
36
+
31
37
  to write more compact and readable code for the most common file I/O operations, the helper functions :func:`read_file`
32
38
  and :func:`write_file` are wrapping Python's built-in :func:`open` function and its context manager.
33
39
 
@@ -40,6 +46,9 @@ the function :func:`duplicates` returns the duplicates of an iterable type.
40
46
  to normalize a file path, in order to remove `.`, `..` placeholders, to resolve symbolic links or to make it relative or
41
47
  absolute, call the function :func:`norm_path`.
42
48
 
49
+ :func:`uri2filename` converts special characters of a URI/URL resulting in a string that can be used as a file name.
50
+ use the function :func:`filename2uri` to convert this string back to the corresponding URL/URI.
51
+
43
52
  :func:`camel_to_snake` and :func:`snake_to_camel` providing name conversions of class and method names.
44
53
 
45
54
  to encode Unicode strings to other codecs the functions :func:`force_encoding` and :func:`to_ascii` can be used.
@@ -99,6 +108,15 @@ code and build Kivy apps for the Android OS, and to `Gabriel Pettier <https://gi
99
108
  osc example.
100
109
 
101
110
 
111
+ types, classes and mixins
112
+ -------------------------
113
+
114
+ the :class:`UnsetType` class can be used e.g. for the declaration of optional function and method parameters,
115
+ allowing also `None` is an accepted argument value.
116
+
117
+ to extend any class with an intelligent error message property, add the mixin :class:`ErrorMsgMixin` to it.
118
+
119
+
102
120
  generic context manager
103
121
  -----------------------
104
122
 
@@ -148,7 +166,7 @@ from types import ModuleType
148
166
  from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union, cast
149
167
 
150
168
 
151
- __version__ = '0.3.39'
169
+ __version__ = '0.3.41'
152
170
 
153
171
 
154
172
  DOCS_FOLDER = 'docs' #: project documentation root folder name
@@ -202,7 +220,9 @@ _env_variable = re.compile(r"""
202
220
  """, re.IGNORECASE | re.VERBOSE)
203
221
 
204
222
 
205
- NAME_PARTS_SEP = '_' #: name parts separator character, e.g. for :func:`norm_name`
223
+ NAME_PARTS_SEP = '_' #: name parts separator character, e.g. for :func:`norm_name`
224
+
225
+ NOW_STR_FORMAT = "{sep}%Y%m%d{sep}%H%M%S{sep}%f" #: timestamp format of :func:`now_str`
206
226
 
207
227
  SKIPPED_MODULES = ('ae.base', 'ae.paths', 'ae.dynamicod', 'ae.core', 'ae.console', 'ae.gui_app', 'ae.gui_help',
208
228
  'ae.kivy', 'ae.kivy.apps', 'ae.kivy.behaviors', 'ae.kivy.i18n', 'ae.kivy.tours', 'ae.kivy.widgets',
@@ -338,6 +358,17 @@ def env_str(name: str, convert_name: bool = False) -> Optional[str]:
338
358
  return os.environ.get(name)
339
359
 
340
360
 
361
+ def filename2uri(file_name: str) -> str:
362
+ """ convert a file name converted by :func:`uri2filename` back to its representation as a URI
363
+
364
+ :param file_name: name of the file/folder to convert back to its URI representation.
365
+ :return: URI string.
366
+
367
+ .. hint:: to ensure proper conversion the specified file name has to be created by :func:`uri2filename`.
368
+ """
369
+ return urllib.parse.unquote(file_name)
370
+
371
+
341
372
  def force_encoding(text: Union[str, bytes], encoding: str = DEF_ENCODING, errors: str = DEF_ENCODE_ERRORS) -> str:
342
373
  """ force/ensure the encoding of text (str or bytes) without any UnicodeDecodeError/UnicodeEncodeError.
343
374
 
@@ -612,9 +643,9 @@ def now_str(sep: str = "") -> str:
612
643
 
613
644
  :param sep: optional prefix and separator character (separating date from time and in time part
614
645
  the seconds from the microseconds).
615
- :return: UTC timestamp as string (length=20 + 3 * len(sep)).
646
+ :return: naive UTC timestamp (without timezone info) as string (length=20 + 3 * len(sep)).
616
647
  """
617
- return datetime.datetime.utcnow().strftime("{sep}%Y%m%d{sep}%H%M%S{sep}%f".format(sep=sep))
648
+ return utc_datetime().strftime(NOW_STR_FORMAT.format(sep=sep))
618
649
 
619
650
 
620
651
  def os_host_name() -> str:
@@ -969,19 +1000,20 @@ def uri2filename(uri: str) -> str:
969
1000
 
970
1001
  more on allowed characters in file names in the answers of RedGrittyBrick on https://superuser.com/questions/358855
971
1002
  and of Christopher Oezbek on https://stackoverflow.com/questions/1976007.
1003
+
1004
+ .. hint:: use :func:`filename2uri` to convert the resulting file name back to the corresponding URO
972
1005
  """
973
1006
  # using urllib.parse.quote(uri, safe="") instead would convert also any non-ascii (e.g. umlaut) characters into hex
974
1007
  # added [] to str.join() argument because List comprehensions are faster than generator expressions
975
1008
  return "".join([f"%{hex(ord(_))[2:].upper()}" if _ in '/|\\:*?"<>%' else _ for _ in uri])
976
1009
 
977
1010
 
978
- def filename2uri(file_name: str) -> str:
979
- """ convert a file name converted by :func:`uri2filename` back to its representation as a URI
1011
+ def utc_datetime() -> datetime.datetime:
1012
+ """ return the current UTC timestamp as string (to use as suffix for file and variable/attribute names).
980
1013
 
981
- :param file_name: name of the file/folder to convert back to its URI representation.
982
- :return: URI string.
1014
+ :return: timestamp string of the actual UTC date and time.
983
1015
  """
984
- return urllib.parse.unquote(file_name)
1016
+ return datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
985
1017
 
986
1018
 
987
1019
  def write_file(file_path: str, content: Union[str, bytes], extra_mode: str = "", encoding: Optional[str] = None):
@@ -1,4 +1,4 @@
1
- <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_project V0.3.30 -->
1
+ <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_project V0.3.31 -->
2
2
  ### GNU GENERAL PUBLIC LICENSE
3
3
 
4
4
  Version 3, 29 June 2007
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ae_base
3
- Version: 0.3.39
3
+ Version: 0.3.41
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
@@ -32,6 +32,7 @@ Requires-Dist: mypy; extra == "dev"
32
32
  Requires-Dist: pylint; extra == "dev"
33
33
  Requires-Dist: pytest; extra == "dev"
34
34
  Requires-Dist: pytest-cov; extra == "dev"
35
+ Requires-Dist: pytest-django; extra == "dev"
35
36
  Requires-Dist: typing; extra == "dev"
36
37
  Requires-Dist: types-setuptools; extra == "dev"
37
38
  Requires-Dist: wheel; extra == "dev"
@@ -46,6 +47,7 @@ Requires-Dist: mypy; extra == "tests"
46
47
  Requires-Dist: pylint; extra == "tests"
47
48
  Requires-Dist: pytest; extra == "tests"
48
49
  Requires-Dist: pytest-cov; extra == "tests"
50
+ Requires-Dist: pytest-django; extra == "tests"
49
51
  Requires-Dist: typing; extra == "tests"
50
52
  Requires-Dist: types-setuptools; extra == "tests"
51
53
  Requires-Dist: wheel; extra == "tests"
@@ -53,17 +55,17 @@ Requires-Dist: twine; extra == "tests"
53
55
 
54
56
  <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae V0.3.94 -->
55
57
  <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_namespace_root V0.3.14 -->
56
- # base 0.3.39
58
+ # base 0.3.41
57
59
 
58
60
  [![GitLab develop](https://img.shields.io/gitlab/pipeline/ae-group/ae_base/develop?logo=python)](
59
61
  https://gitlab.com/ae-group/ae_base)
60
62
  [![LatestPyPIrelease](
61
- https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.38?logo=python)](
62
- https://gitlab.com/ae-group/ae_base/-/tree/release0.3.38)
63
+ https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.40?logo=python)](
64
+ https://gitlab.com/ae-group/ae_base/-/tree/release0.3.40)
63
65
  [![PyPIVersions](https://img.shields.io/pypi/v/ae_base)](
64
66
  https://pypi.org/project/ae-base/#history)
65
67
 
66
- >ae_base module 0.3.39.
68
+ >ae_base module 0.3.41.
67
69
 
68
70
  [![Coverage](https://ae-group.gitlab.io/ae_base/coverage.svg)](
69
71
  https://ae-group.gitlab.io/ae_base/coverage/index.html)
@@ -0,0 +1,7 @@
1
+ ae/base.py,sha256=9qixFzNhWVcGztz9Y7zv7vsQL485LEXH-IsfF61yo_M,56696
2
+ ae_base-0.3.41.dist-info/LICENSE.md,sha256=eHVr16LWo8bsm2NbdFOBcQp-F_3MUXo9I922sABpsMQ,35002
3
+ ae_base-0.3.41.dist-info/METADATA,sha256=pr0WsX0BOV067Vj5cxyfuWPNtr0rTHURIlRoacPaZe0,5311
4
+ ae_base-0.3.41.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
5
+ ae_base-0.3.41.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
6
+ ae_base-0.3.41.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
+ ae_base-0.3.41.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- ae/base.py,sha256=aA_qa4s-17EzXKjN9wwfya688eGnFNJP0EglSLeYJjw,55182
2
- ae_base-0.3.39.dist-info/LICENSE.md,sha256=3X7IwvwQFt4PqRHb7mV8qoJjQ1E-HmcGioyT4Y6-6c8,35002
3
- ae_base-0.3.39.dist-info/METADATA,sha256=YPZbM4qKqfaO-3WvDLvV77O9WNWOfxg6uxhkO7nu0vA,5219
4
- ae_base-0.3.39.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
5
- ae_base-0.3.39.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
6
- ae_base-0.3.39.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
- ae_base-0.3.39.dist-info/RECORD,,