ae-base 0.3.40__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 +25 -10
- {ae_base-0.3.40.dist-info → ae_base-0.3.41.dist-info}/LICENSE.md +1 -1
- {ae_base-0.3.40.dist-info → ae_base-0.3.41.dist-info}/METADATA +7 -5
- ae_base-0.3.41.dist-info/RECORD +7 -0
- {ae_base-0.3.40.dist-info → ae_base-0.3.41.dist-info}/WHEEL +1 -1
- ae_base-0.3.40.dist-info/RECORD +0 -7
- {ae_base-0.3.40.dist-info → ae_base-0.3.41.dist-info}/top_level.txt +0 -0
- {ae_base-0.3.40.dist-info → ae_base-0.3.41.dist-info}/zip-safe +0 -0
ae/base.py
CHANGED
|
@@ -31,6 +31,9 @@ sortable and compact string from a timestamp.
|
|
|
31
31
|
base helper functions
|
|
32
32
|
---------------------
|
|
33
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
|
+
|
|
34
37
|
to write more compact and readable code for the most common file I/O operations, the helper functions :func:`read_file`
|
|
35
38
|
and :func:`write_file` are wrapping Python's built-in :func:`open` function and its context manager.
|
|
36
39
|
|
|
@@ -43,6 +46,9 @@ the function :func:`duplicates` returns the duplicates of an iterable type.
|
|
|
43
46
|
to normalize a file path, in order to remove `.`, `..` placeholders, to resolve symbolic links or to make it relative or
|
|
44
47
|
absolute, call the function :func:`norm_path`.
|
|
45
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
|
+
|
|
46
52
|
:func:`camel_to_snake` and :func:`snake_to_camel` providing name conversions of class and method names.
|
|
47
53
|
|
|
48
54
|
to encode Unicode strings to other codecs the functions :func:`force_encoding` and :func:`to_ascii` can be used.
|
|
@@ -160,7 +166,7 @@ from types import ModuleType
|
|
|
160
166
|
from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union, cast
|
|
161
167
|
|
|
162
168
|
|
|
163
|
-
__version__ = '0.3.
|
|
169
|
+
__version__ = '0.3.41'
|
|
164
170
|
|
|
165
171
|
|
|
166
172
|
DOCS_FOLDER = 'docs' #: project documentation root folder name
|
|
@@ -352,6 +358,17 @@ def env_str(name: str, convert_name: bool = False) -> Optional[str]:
|
|
|
352
358
|
return os.environ.get(name)
|
|
353
359
|
|
|
354
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
|
+
|
|
355
372
|
def force_encoding(text: Union[str, bytes], encoding: str = DEF_ENCODING, errors: str = DEF_ENCODE_ERRORS) -> str:
|
|
356
373
|
""" force/ensure the encoding of text (str or bytes) without any UnicodeDecodeError/UnicodeEncodeError.
|
|
357
374
|
|
|
@@ -628,10 +645,7 @@ def now_str(sep: str = "") -> str:
|
|
|
628
645
|
the seconds from the microseconds).
|
|
629
646
|
:return: naive UTC timestamp (without timezone info) as string (length=20 + 3 * len(sep)).
|
|
630
647
|
"""
|
|
631
|
-
|
|
632
|
-
return datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None).strftime(NOW_STR_FORMAT.format(sep=sep))
|
|
633
|
-
# else:
|
|
634
|
-
# return datetime.datetime.utcnow().strftime(NOW_STR_FORMAT.format(sep=sep))
|
|
648
|
+
return utc_datetime().strftime(NOW_STR_FORMAT.format(sep=sep))
|
|
635
649
|
|
|
636
650
|
|
|
637
651
|
def os_host_name() -> str:
|
|
@@ -986,19 +1000,20 @@ def uri2filename(uri: str) -> str:
|
|
|
986
1000
|
|
|
987
1001
|
more on allowed characters in file names in the answers of RedGrittyBrick on https://superuser.com/questions/358855
|
|
988
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
|
|
989
1005
|
"""
|
|
990
1006
|
# using urllib.parse.quote(uri, safe="") instead would convert also any non-ascii (e.g. umlaut) characters into hex
|
|
991
1007
|
# added [] to str.join() argument because List comprehensions are faster than generator expressions
|
|
992
1008
|
return "".join([f"%{hex(ord(_))[2:].upper()}" if _ in '/|\\:*?"<>%' else _ for _ in uri])
|
|
993
1009
|
|
|
994
1010
|
|
|
995
|
-
def
|
|
996
|
-
"""
|
|
1011
|
+
def utc_datetime() -> datetime.datetime:
|
|
1012
|
+
""" return the current UTC timestamp as string (to use as suffix for file and variable/attribute names).
|
|
997
1013
|
|
|
998
|
-
:
|
|
999
|
-
:return: URI string.
|
|
1014
|
+
:return: timestamp string of the actual UTC date and time.
|
|
1000
1015
|
"""
|
|
1001
|
-
return
|
|
1016
|
+
return datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
|
|
1002
1017
|
|
|
1003
1018
|
|
|
1004
1019
|
def write_file(file_path: str, content: Union[str, bytes], extra_mode: str = "", encoding: Optional[str] = None):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ae_base
|
|
3
|
-
Version: 0.3.
|
|
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.
|
|
58
|
+
# base 0.3.41
|
|
57
59
|
|
|
58
60
|
[](
|
|
59
61
|
https://gitlab.com/ae-group/ae_base)
|
|
60
62
|
[](
|
|
64
|
+
https://gitlab.com/ae-group/ae_base/-/tree/release0.3.40)
|
|
63
65
|
[](
|
|
64
66
|
https://pypi.org/project/ae-base/#history)
|
|
65
67
|
|
|
66
|
-
>ae_base module 0.3.
|
|
68
|
+
>ae_base module 0.3.41.
|
|
67
69
|
|
|
68
70
|
[](
|
|
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,,
|
ae_base-0.3.40.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
ae/base.py,sha256=-_eBIIgBgO1opcu_GlqDB1qQOU0qzuUvKUd1YM0hT5c,55971
|
|
2
|
-
ae_base-0.3.40.dist-info/LICENSE.md,sha256=3X7IwvwQFt4PqRHb7mV8qoJjQ1E-HmcGioyT4Y6-6c8,35002
|
|
3
|
-
ae_base-0.3.40.dist-info/METADATA,sha256=Mvak-VG2CUOXlP0lNF5wi2UuQSSkdPm8WdS5FsUwL5g,5219
|
|
4
|
-
ae_base-0.3.40.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
5
|
-
ae_base-0.3.40.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
|
|
6
|
-
ae_base-0.3.40.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
7
|
-
ae_base-0.3.40.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|