mm-std 0.3.4__py3-none-any.whl → 0.3.6__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.
mm_std/__init__.py
CHANGED
@@ -13,7 +13,7 @@ from .date import parse_date as parse_date
|
|
13
13
|
from .date import utc_delta as utc_delta
|
14
14
|
from .date import utc_now as utc_now
|
15
15
|
from .date import utc_random as utc_random
|
16
|
-
from .dict import
|
16
|
+
from .dict import replace_empty_dict_values as replace_empty_dict_values
|
17
17
|
from .env import get_dotenv as get_dotenv
|
18
18
|
from .http_ import CHROME_USER_AGENT as CHROME_USER_AGENT
|
19
19
|
from .http_ import FIREFOX_USER_AGENT as FIREFOX_USER_AGENT
|
@@ -44,4 +44,6 @@ from .str import number_with_separator as number_with_separator
|
|
44
44
|
from .str import str_ends_with_any as str_ends_with_any
|
45
45
|
from .str import str_starts_with_any as str_starts_with_any
|
46
46
|
from .str import str_to_list as str_to_list
|
47
|
+
from .toml import toml_dumps as toml_dumps
|
48
|
+
from .toml import toml_loads as toml_loads
|
47
49
|
from .zip import read_text_from_zip_archive as read_text_from_zip_archive
|
mm_std/dict.py
CHANGED
@@ -1,4 +1,37 @@
|
|
1
|
-
def
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
def replace_empty_dict_values(
|
2
|
+
data: dict[object, object],
|
3
|
+
defaults: dict[object, object] | None = None,
|
4
|
+
zero_is_empty: bool = False,
|
5
|
+
) -> dict[object, object]:
|
6
|
+
"""
|
7
|
+
Replace empty values in a dictionary with provided default values, or remove them if no default exists.
|
8
|
+
|
9
|
+
An "empty" value is defined as one of the following:
|
10
|
+
- None
|
11
|
+
- An empty string ("")
|
12
|
+
|
13
|
+
If the flag `zero_is_empty` is True, the numeric value 0 is also considered empty.
|
14
|
+
|
15
|
+
For each key in the input dictionary `data`, if its value is empty, the function checks the
|
16
|
+
`defaults` dictionary for a replacement. If a default exists, it uses that value; otherwise, the
|
17
|
+
key is omitted from the resulting dictionary.
|
18
|
+
|
19
|
+
Parameters:
|
20
|
+
data (dict[object, object]): The input dictionary with key-value pairs to process.
|
21
|
+
defaults (dict[object, object] | None, optional): A dictionary of default values to use as
|
22
|
+
replacements for empty entries. If None, no default replacements are applied.
|
23
|
+
zero_is_empty (bool, optional): If True, treats the value 0 as empty. Defaults to False.
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
dict[object, object]: A new dictionary with empty values replaced by defaults or removed if no
|
27
|
+
default is provided.
|
28
|
+
"""
|
29
|
+
if defaults is None:
|
30
|
+
defaults = {}
|
31
|
+
result = {}
|
32
|
+
for key, value in data.items():
|
33
|
+
if value is None or value == "" or (zero_is_empty and value == 0):
|
34
|
+
value = defaults.get(key, None) # noqa: PLW2901
|
35
|
+
if value is not None:
|
36
|
+
result[key] = value
|
37
|
+
return result
|
mm_std/toml.py
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from decimal import Decimal
|
3
|
+
|
4
|
+
import tomlkit
|
5
|
+
from tomlkit.items import Float, Trivia
|
6
|
+
|
7
|
+
|
8
|
+
def encode_decimal(value: object) -> Float:
|
9
|
+
if isinstance(value, Decimal):
|
10
|
+
return Float(value=float(value), trivia=Trivia(), raw=str(value))
|
11
|
+
raise TypeError(f"Cannot convert {type(value)} to TOML item")
|
12
|
+
|
13
|
+
|
14
|
+
tomlkit.register_encoder(encode_decimal)
|
15
|
+
|
16
|
+
|
17
|
+
def toml_dumps(data: Mapping[str, object], sort_keys: bool = False) -> str:
|
18
|
+
return tomlkit.dumps(data, sort_keys=sort_keys)
|
19
|
+
|
20
|
+
|
21
|
+
def toml_loads(string: str | bytes) -> tomlkit.TOMLDocument:
|
22
|
+
return tomlkit.loads(string)
|
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mm-std
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.6
|
4
4
|
Requires-Python: >=3.12
|
5
5
|
Requires-Dist: cryptography~=44.0.2
|
6
6
|
Requires-Dist: httpx[http2,socks]~=0.28.1
|
7
7
|
Requires-Dist: pydantic~=2.10.6
|
8
8
|
Requires-Dist: pydash~=8.0.5
|
9
9
|
Requires-Dist: python-dotenv~=1.0.1
|
10
|
-
Requires-Dist: pyyaml~=6.0.2
|
11
10
|
Requires-Dist: rich~=13.9.4
|
11
|
+
Requires-Dist: tomlkit~=0.13.2
|
@@ -1,10 +1,10 @@
|
|
1
|
-
mm_std/__init__.py,sha256=
|
1
|
+
mm_std/__init__.py,sha256=caX2neVi9FNTqoxwzceesTP9y7iH0OrEi1SwL1qbKOY,2446
|
2
2
|
mm_std/command.py,sha256=ze286wjUjg0QSTgIu-2WZks53_Vclg69UaYYgPpQvCU,1283
|
3
3
|
mm_std/concurrency.py,sha256=4kKLhde6YQYsjJJjH6K5eMQj6FtegEz55Mo5TmhQMM0,5242
|
4
4
|
mm_std/config.py,sha256=4DGzjLO8TYno1xF8wj2hRaw2-gfNzt_W1_bt7w8ovno,1874
|
5
5
|
mm_std/crypto.py,sha256=jdk0_TCmeU0pPXMyz9xH6kQHSjjZ9GcGClBwQps5vBo,340
|
6
6
|
mm_std/date.py,sha256=976eEkSONuNqHQBgSRu8hrtH23tJqztbmHFHLdbP2TY,1879
|
7
|
-
mm_std/dict.py,sha256=
|
7
|
+
mm_std/dict.py,sha256=E8YxRCs-hdXt0yhZUzR_o892LYokHzcFxSaGh835yjI,1588
|
8
8
|
mm_std/env.py,sha256=5zaR9VeIfObN-4yfgxoFeU5IM1GDeZZj9SuYf7t9sOA,125
|
9
9
|
mm_std/fs.py,sha256=RwarNRJq3tIMG6LVX_g03hasfYpjYFh_O27oVDt5IPQ,291
|
10
10
|
mm_std/http_.py,sha256=QaPPXVb-rOS0BpoKdYQ0ABm_-mcR5dNa7Uqn-SeW_kE,4119
|
@@ -16,8 +16,9 @@ mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
mm_std/random_.py,sha256=OuUX4VJeSd13NZBya4qrGpR2TfN7_87tfebOY6DBUnI,1113
|
17
17
|
mm_std/result.py,sha256=KLnPWjICYFkP6CAhq7Ifs22XSD-PQ9RkG6n1-cZcXkM,7625
|
18
18
|
mm_std/str.py,sha256=jS7VAI7i_a3iqnfaW4Iw2LZRTv0Tml4kmMbP2S2IUF4,3067
|
19
|
+
mm_std/toml.py,sha256=CNznWKR0bpOxS6e3VB5LGS-Oa9lW-wterkcPUFtPcls,610
|
19
20
|
mm_std/types_.py,sha256=hvZlnvBWyB8CL_MeEWWD0Y0nN677plibYn3yD-5g7xs,99
|
20
21
|
mm_std/zip.py,sha256=axzF1BwcIygtfNNTefZH7hXKaQqwe-ZH3ChuRWr9dnk,396
|
21
|
-
mm_std-0.3.
|
22
|
-
mm_std-0.3.
|
23
|
-
mm_std-0.3.
|
22
|
+
mm_std-0.3.6.dist-info/METADATA,sha256=ehHTWxAnM1LynaVLjOw_WLOS-PLQ8qKYwqgaIjbQfCQ,308
|
23
|
+
mm_std-0.3.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
24
|
+
mm_std-0.3.6.dist-info/RECORD,,
|
File without changes
|