winipedia-utils 0.1.59__py3-none-any.whl → 0.1.61__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.

Potentially problematic release.


This version of winipedia-utils might be problematic. Click here for more details.

winipedia_utils/os/os.py CHANGED
@@ -11,11 +11,12 @@ from pathlib import Path
11
11
  from typing import Any
12
12
 
13
13
 
14
- def which_with_raise(cmd: str) -> str:
14
+ def which_with_raise(cmd: str, *, raise_error: bool = True) -> str | None:
15
15
  """Give the path to the given command.
16
16
 
17
17
  Args:
18
18
  cmd: The command to find
19
+ raise_error: Whether to raise an error if the command is not found
19
20
 
20
21
  Returns:
21
22
  The path to the command
@@ -27,7 +28,8 @@ def which_with_raise(cmd: str) -> str:
27
28
  path = shutil.which(cmd)
28
29
  if path is None:
29
30
  msg = f"Command {cmd} not found"
30
- raise FileNotFoundError(msg)
31
+ if raise_error:
32
+ raise FileNotFoundError(msg)
31
33
  return path
32
34
 
33
35
 
@@ -11,7 +11,8 @@ from winipedia_utils.os.os import run_subprocess, which_with_raise
11
11
 
12
12
  logger = get_logger(__name__)
13
13
 
14
- POETRY_PATH = which_with_raise("poetry")
14
+
15
+ POETRY_PATH = which_with_raise("poetry", raise_error=False) or "poetry"
15
16
 
16
17
  POETRY_RUN_ARGS = [POETRY_PATH, "run"]
17
18
 
@@ -13,7 +13,7 @@ from cryptography.fernet import Fernet
13
13
  from cryptography.hazmat.primitives.ciphers.aead import AESGCM
14
14
 
15
15
 
16
- def get_or_create_fernet(service_name: str, username: str) -> Fernet:
16
+ def get_or_create_fernet(service_name: str, username: str) -> tuple[Fernet, bytes]:
17
17
  """Get the app secret using keyring.
18
18
 
19
19
  If it does not exist, create it with a Fernet.
@@ -23,7 +23,7 @@ def get_or_create_fernet(service_name: str, username: str) -> Fernet:
23
23
  )
24
24
 
25
25
 
26
- def get_or_create_aes_gcm(service_name: str, username: str) -> AESGCM:
26
+ def get_or_create_aes_gcm(service_name: str, username: str) -> tuple[AESGCM, bytes]:
27
27
  """Get the app secret using keyring.
28
28
 
29
29
  If it does not exist, create it with a AESGCM.
@@ -38,17 +38,33 @@ def get_or_create_key[T](
38
38
  username: str,
39
39
  key_class: Callable[[bytes], T],
40
40
  generate_key_func: Callable[..., bytes],
41
- ) -> T:
41
+ ) -> tuple[T, bytes]:
42
42
  """Get the app secret using keyring.
43
43
 
44
44
  If it does not exist, create it with the generate_func.
45
45
  """
46
- service_name = f"{service_name}_{key_class.__name__}"
47
- key = keyring.get_password(service_name, username)
46
+ key = get_key_as_str(service_name, username, key_class)
48
47
  if key is None:
49
48
  binary_key = generate_key_func()
50
49
  key = b64encode(binary_key).decode("ascii")
51
- keyring.set_password(service_name, username, key)
50
+ modified_service_name = make_service_name(service_name, key_class)
51
+ keyring.set_password(modified_service_name, username, key)
52
52
 
53
53
  binary_key = b64decode(key)
54
- return key_class(binary_key)
54
+ return key_class(binary_key), binary_key
55
+
56
+
57
+ def get_key_as_str[T](
58
+ service_name: str, username: str, key_class: Callable[[bytes], T]
59
+ ) -> str | None:
60
+ """Get the app secret using keyring.
61
+
62
+ If it does not exist, create it with the generate_func.
63
+ """
64
+ service_name = make_service_name(service_name, key_class)
65
+ return keyring.get_password(service_name, username)
66
+
67
+
68
+ def make_service_name[T](service_name: str, key_class: Callable[[bytes], T]) -> str:
69
+ """Make a service name from a service name and a key class."""
70
+ return f"{service_name}_{key_class.__name__}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: winipedia-utils
3
- Version: 0.1.59
3
+ Version: 0.1.61
4
4
  Summary: A package with many utility functions
5
5
  License: MIT
6
6
  Author: Winipedia
@@ -33,11 +33,11 @@ winipedia_utils/oop/mixins/__init__.py,sha256=PDK-cJcdRUfDUCz36qQ5pmMW07G133WtN4
33
33
  winipedia_utils/oop/mixins/meta.py,sha256=ajSlKTDqNYbPc3vAin84dWVG3R7ZaBEwga1e3Mzm-Gw,11309
34
34
  winipedia_utils/oop/mixins/mixin.py,sha256=sFImqDFX0TtdAAYHgepVT_UqJ50juvDdwGG9vMNa3PE,1438
35
35
  winipedia_utils/os/__init__.py,sha256=WSLt7tb6HqWRlCGGIEwRfVksF0sLJNeEW3iZeJhGWk0,47
36
- winipedia_utils/os/os.py,sha256=ITuiLLfjGBV2jH8tHQfwVzsICT-jY1zUxtwu3ASJBG4,1690
36
+ winipedia_utils/os/os.py,sha256=CXPVnagfj3dXlc8OIv1DirJpin8oaGXWetnmx2lULE4,1831
37
37
  winipedia_utils/projects/__init__.py,sha256=6oTiSlUMAwO5xnH4SGVnvspzKcxrxo9kn1L4xkjq1p8,53
38
38
  winipedia_utils/projects/poetry/__init__.py,sha256=0yNMuu9KmM19od4VBxBV3HLK-RdCsa0e2Zhg33J7RmQ,60
39
39
  winipedia_utils/projects/poetry/config.py,sha256=ghJzlNDVrSfG5Mg0JjnL9Xmz6fVD-rAHl41tjbFUBb8,2993
40
- winipedia_utils/projects/poetry/poetry.py,sha256=5jyUSMxhCZ7pz9bOaz5E9r7Da9qIrGOp6wcBzI1y7Cg,932
40
+ winipedia_utils/projects/poetry/poetry.py,sha256=QoQ-b8NgMiWaqq85gs2HZh_436VpNqKzGogrWPS5DrU,965
41
41
  winipedia_utils/projects/project.py,sha256=2nz1Hh51A-shjgdPCgiDw-ODrVtOtiHEHQnMPjAJZ-A,1587
42
42
  winipedia_utils/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
43
43
  winipedia_utils/pyside/__init__.py,sha256=knliQxknKWqxCEfxlI1K02OtbBfnTkYUZFqyYcLJNDI,52
@@ -72,7 +72,7 @@ winipedia_utils/resources/svgs/plus_icon.svg,sha256=CHjIzOUbDH4xHlwX5MbTsdL0Hnku
72
72
  winipedia_utils/resources/svgs/svg.py,sha256=-Dw6m7cm9CHT2076oZIMx7kTQw0v_ifJajXzWcpUtI0,430
73
73
  winipedia_utils/security/__init__.py,sha256=ZBa72J6MNtYumBFMoVc0ia4jsoS7oNgjaTCW0xDb6EI,53
74
74
  winipedia_utils/security/cryptography.py,sha256=zfxSDo7aE9ecmZNC6URMSEUYRpOuJ1iESg-WCSS5HP0,822
75
- winipedia_utils/security/keyring.py,sha256=35bCXBmsFWyd7Ja2w9zHElayABeRZEaNXoEDDRb8ItQ,1698
75
+ winipedia_utils/security/keyring.py,sha256=AKpIGRh7RAWzzdIjTLZRXndxgbsX5DJxdHaRk40zw7o,2343
76
76
  winipedia_utils/setup.py,sha256=F4NneO0wVTf7JCXLorWjTOdJl36N5fLSksoWMe4p86o,1650
77
77
  winipedia_utils/testing/__init__.py,sha256=kXhB5xw02ec5xpcW_KV--9CBKdyCjnuR-NZzAJ5tq0g,51
78
78
  winipedia_utils/testing/assertions.py,sha256=0JF4mqVTnLQ1qkAL_FuTwyN_idr00rvVlta7aDdnUXA,851
@@ -94,7 +94,7 @@ winipedia_utils/testing/tests/base/utils/utils.py,sha256=dUPDrgAxlfREQb33zz23Mfz
94
94
  winipedia_utils/testing/tests/conftest.py,sha256=8RounBlI8Jq1aLaLNpv84MW4ne8Qq0aavQextDOp5ng,920
95
95
  winipedia_utils/text/__init__.py,sha256=j2bwtK6kyeHI6SnoBjpRju0C1W2n2paXBDlNjNtaUxA,48
96
96
  winipedia_utils/text/string.py,sha256=pK_VQXxSZa8HqHY1a6oMKfmN-OKteFE32eZaweCI22E,3508
97
- winipedia_utils-0.1.59.dist-info/LICENSE,sha256=3PrKJ2CWNrnyyHaC_r0wPDSukVWgmjOxHr__eQVH7cw,1087
98
- winipedia_utils-0.1.59.dist-info/METADATA,sha256=4K38KbFyGfL0RsYd_HPKO2ze9bAITq-m7WKLYt2OGwM,12576
99
- winipedia_utils-0.1.59.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
100
- winipedia_utils-0.1.59.dist-info/RECORD,,
97
+ winipedia_utils-0.1.61.dist-info/LICENSE,sha256=3PrKJ2CWNrnyyHaC_r0wPDSukVWgmjOxHr__eQVH7cw,1087
98
+ winipedia_utils-0.1.61.dist-info/METADATA,sha256=i3pkb0PrD_YIkUnxzzeexIYtSQZ98BATj7GNLT_EFnk,12576
99
+ winipedia_utils-0.1.61.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
100
+ winipedia_utils-0.1.61.dist-info/RECORD,,