ae-base 0.3.48__tar.gz → 0.3.49__tar.gz
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-0.3.48/ae_base.egg-info → ae_base-0.3.49}/PKG-INFO +5 -5
- {ae_base-0.3.48 → ae_base-0.3.49}/README.md +4 -4
- {ae_base-0.3.48 → ae_base-0.3.49}/ae/base.py +49 -1
- {ae_base-0.3.48 → ae_base-0.3.49/ae_base.egg-info}/PKG-INFO +5 -5
- {ae_base-0.3.48 → ae_base-0.3.49}/tests/test_base.py +22 -1
- {ae_base-0.3.48 → ae_base-0.3.49}/LICENSE.md +0 -0
- {ae_base-0.3.48 → ae_base-0.3.49}/ae_base.egg-info/SOURCES.txt +0 -0
- {ae_base-0.3.48 → ae_base-0.3.49}/ae_base.egg-info/dependency_links.txt +0 -0
- {ae_base-0.3.48 → ae_base-0.3.49}/ae_base.egg-info/requires.txt +0 -0
- {ae_base-0.3.48 → ae_base-0.3.49}/ae_base.egg-info/top_level.txt +0 -0
- {ae_base-0.3.48 → ae_base-0.3.49}/ae_base.egg-info/zip-safe +0 -0
- {ae_base-0.3.48 → ae_base-0.3.49}/setup.cfg +0 -0
- {ae_base-0.3.48 → ae_base-0.3.49}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: ae_base
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.49
|
|
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
|
|
@@ -68,17 +68,17 @@ Dynamic: summary
|
|
|
68
68
|
|
|
69
69
|
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae V0.3.95 -->
|
|
70
70
|
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_namespace_root V0.3.14 -->
|
|
71
|
-
# base 0.3.
|
|
71
|
+
# base 0.3.49
|
|
72
72
|
|
|
73
73
|
[](
|
|
74
74
|
https://gitlab.com/ae-group/ae_base)
|
|
75
75
|
[](
|
|
77
|
+
https://gitlab.com/ae-group/ae_base/-/tree/release0.3.48)
|
|
78
78
|
[](
|
|
79
79
|
https://pypi.org/project/ae-base/#history)
|
|
80
80
|
|
|
81
|
-
>ae_base module 0.3.
|
|
81
|
+
>ae_base module 0.3.49.
|
|
82
82
|
|
|
83
83
|
[](
|
|
84
84
|
https://ae-group.gitlab.io/ae_base/coverage/index.html)
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae V0.3.95 -->
|
|
2
2
|
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_namespace_root V0.3.14 -->
|
|
3
|
-
# base 0.3.
|
|
3
|
+
# base 0.3.49
|
|
4
4
|
|
|
5
5
|
[](
|
|
6
6
|
https://gitlab.com/ae-group/ae_base)
|
|
7
7
|
[](
|
|
9
|
+
https://gitlab.com/ae-group/ae_base/-/tree/release0.3.48)
|
|
10
10
|
[](
|
|
11
11
|
https://pypi.org/project/ae-base/#history)
|
|
12
12
|
|
|
13
|
-
>ae_base module 0.3.
|
|
13
|
+
>ae_base module 0.3.49.
|
|
14
14
|
|
|
15
15
|
[](
|
|
16
16
|
https://ae-group.gitlab.io/ae_base/coverage/index.html)
|
|
@@ -100,6 +100,9 @@ allowing also ``None`` is an accepted argument value.
|
|
|
100
100
|
|
|
101
101
|
to extend any class with an intelligent error message handling, add the mixin :class:`ErrorMsgMixin` to it.
|
|
102
102
|
|
|
103
|
+
the classes :class:`UnformattedValue` and :class:`GivenFormatter` can be used to format strings with placeholders
|
|
104
|
+
enclosed in curly brackets. the function :func:`format_given` is using them to format templates with placeholders.
|
|
105
|
+
|
|
103
106
|
|
|
104
107
|
generic context manager
|
|
105
108
|
-----------------------
|
|
@@ -144,6 +147,7 @@ import platform
|
|
|
144
147
|
import re
|
|
145
148
|
import shutil
|
|
146
149
|
import socket
|
|
150
|
+
import string
|
|
147
151
|
import sys
|
|
148
152
|
import unicodedata
|
|
149
153
|
import warnings
|
|
@@ -156,7 +160,7 @@ from types import ModuleType
|
|
|
156
160
|
from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union, cast
|
|
157
161
|
|
|
158
162
|
|
|
159
|
-
__version__ = '0.3.
|
|
163
|
+
__version__ = '0.3.49'
|
|
160
164
|
|
|
161
165
|
|
|
162
166
|
os_path_abspath = os.path.abspath
|
|
@@ -469,6 +473,50 @@ def force_encoding(text: Union[str, bytes], encoding: str = DEF_ENCODING, errors
|
|
|
469
473
|
return enc_str.decode(encoding=encoding)
|
|
470
474
|
|
|
471
475
|
|
|
476
|
+
class UnformattedValue:
|
|
477
|
+
""" helper class for :func:`~ae.base.format_given` to keep placeholder with format unchanged if not found. """
|
|
478
|
+
def __init__(self, key: str):
|
|
479
|
+
self.key = key
|
|
480
|
+
|
|
481
|
+
def __format__(self, format_spec: str):
|
|
482
|
+
""" overriding Python object class method to return placeholder unchanged including the curly brackets. """
|
|
483
|
+
return "{{{}{}}}".format(self.key, ":" + format_spec if format_spec else "")
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
class GivenFormatter(string.Formatter):
|
|
487
|
+
""" helper class for :func:`~ae.base.format_given` to keep placeholder with format unchanged if not found. """
|
|
488
|
+
def get_value(self, key, args, kwargs):
|
|
489
|
+
""" overriding to keep placeholder unchanged if not found """
|
|
490
|
+
try:
|
|
491
|
+
return super().get_value(key, args, kwargs)
|
|
492
|
+
except KeyError:
|
|
493
|
+
return UnformattedValue(key)
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def format_given(text: str, placeholder_map: dict[str, Any], strict: bool = False):
|
|
497
|
+
""" replacement for Python's str.format_map(), keeping intact placeholders that are not in the specified mapping.
|
|
498
|
+
|
|
499
|
+
:param text: text/template in which the given/specified placeholders will get replaced. in contrary
|
|
500
|
+
to str.format_map() no KeyError will be raised for placeholders not specified in
|
|
501
|
+
:paramref:`~format_given.placeholder_map`.
|
|
502
|
+
:param placeholder_map: dict with placeholder keys to be replaced in :paramref:`~format_given.text` argument.
|
|
503
|
+
:param strict: pass True to raise error for text templates containing unpaired curly brackets.
|
|
504
|
+
:return: the specified :paramref:`~format_given.text` with only the placeholders specified in
|
|
505
|
+
:paramref:`~format_given.placeholder_map` replaced with their respective map value.
|
|
506
|
+
additionally any ValueError that would be thrown by str.format_map(), e.g. if the
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
inspired by the answer of CodeManX in `https://stackoverflow.com/questions/3536303`__
|
|
510
|
+
"""
|
|
511
|
+
formatter = GivenFormatter()
|
|
512
|
+
try:
|
|
513
|
+
return formatter.vformat(text, (), placeholder_map)
|
|
514
|
+
except (ValueError, Exception) as ex:
|
|
515
|
+
if strict:
|
|
516
|
+
raise ex
|
|
517
|
+
return text
|
|
518
|
+
|
|
519
|
+
|
|
472
520
|
def full_stack_trace(ex: Exception) -> str:
|
|
473
521
|
""" get full stack trace from an exception.
|
|
474
522
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: ae_base
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.49
|
|
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
|
|
@@ -68,17 +68,17 @@ Dynamic: summary
|
|
|
68
68
|
|
|
69
69
|
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae V0.3.95 -->
|
|
70
70
|
<!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_namespace_root V0.3.14 -->
|
|
71
|
-
# base 0.3.
|
|
71
|
+
# base 0.3.49
|
|
72
72
|
|
|
73
73
|
[](
|
|
74
74
|
https://gitlab.com/ae-group/ae_base)
|
|
75
75
|
[](
|
|
77
|
+
https://gitlab.com/ae-group/ae_base/-/tree/release0.3.48)
|
|
78
78
|
[](
|
|
79
79
|
https://pypi.org/project/ae-base/#history)
|
|
80
80
|
|
|
81
|
-
>ae_base module 0.3.
|
|
81
|
+
>ae_base module 0.3.49.
|
|
82
82
|
|
|
83
83
|
[](
|
|
84
84
|
https://ae-group.gitlab.io/ae_base/coverage/index.html)
|
|
@@ -21,7 +21,7 @@ from ae.base import (
|
|
|
21
21
|
UNSET,
|
|
22
22
|
URI_SEP_CHAR, app_name_guess, build_config_variable_values, camel_to_snake, deep_dict_update, dummy_function,
|
|
23
23
|
duplicates, env_str,
|
|
24
|
-
dedefuse, force_encoding, full_stack_trace, import_module, instantiate_config_parser, in_wd,
|
|
24
|
+
dedefuse, force_encoding, format_given, full_stack_trace, import_module, instantiate_config_parser, in_wd,
|
|
25
25
|
load_env_var_defaults, load_dotenvs, main_file_paths_parts, module_attr, module_file_path, module_name,
|
|
26
26
|
norm_line_sep, norm_name, norm_path, now_str, os_host_name, os_local_ip, _os_platform, os_user_name,
|
|
27
27
|
parse_dotenv, project_main_file, read_file, round_traditional, snake_to_camel, stack_frames, stack_var, stack_vars,
|
|
@@ -326,6 +326,27 @@ class TestBaseHelpers:
|
|
|
326
326
|
with pytest.raises(TypeError):
|
|
327
327
|
assert force_encoding(s, encoding=cast(str, None)) == '\\xe4\\xf6\\xfc'
|
|
328
328
|
|
|
329
|
+
def test_format_given(self):
|
|
330
|
+
assert format_given("test text with {placeholder}", {}) == "test text with {placeholder}"
|
|
331
|
+
assert format_given("test text with {placeholder:.2e}", {}) == "test text with {placeholder:.2e}"
|
|
332
|
+
assert format_given("a {placeholder} {{test}}", {}) == "a {placeholder} {test}"
|
|
333
|
+
|
|
334
|
+
assert format_given("test text with {placeholder}", {'placeholder': "replaced"}) == "test text with replaced"
|
|
335
|
+
assert format_given("test text with {placeholder:.2e}", {'placeholder': 3.14159}) == "test text with 3.14e+00"
|
|
336
|
+
|
|
337
|
+
assert format_given("a {ph} {{test}}", {'ph': "rep"}) == "a rep {test}"
|
|
338
|
+
assert format_given("a {{ph}} {test}", {'ph': "rep"}) == "a {ph} {test}"
|
|
339
|
+
assert format_given("a {{ph} {test}}", {'ph': "rep"}) == "a {{ph} {test}}"
|
|
340
|
+
|
|
341
|
+
assert format_given("a non-ph}", {'ph': "rep"}) == "a non-ph}"
|
|
342
|
+
assert format_given("a non-{ph", {'ph': "rep"}) == "a non-{ph"
|
|
343
|
+
|
|
344
|
+
def test_format_given_err(self):
|
|
345
|
+
with pytest.raises(ValueError):
|
|
346
|
+
format_given("test text with {placeholder", {}, strict=True) # expected '}' before end of string
|
|
347
|
+
with pytest.raises(ValueError):
|
|
348
|
+
format_given("test text with placeholder}", {}, strict=True) # Single '}' encountered in format string
|
|
349
|
+
|
|
329
350
|
def test_import_module_ae_base(self):
|
|
330
351
|
mod_ref = import_module('ae.base')
|
|
331
352
|
assert isinstance(mod_ref, ModuleType)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|