winipedia-utils 0.1.36__py3-none-any.whl → 0.1.38__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.
@@ -236,7 +236,6 @@ class MediaPlayer(QMediaPlayer):
236
236
  ):
237
237
  self.setPosition(position)
238
238
  self.last_slider_moved_update = current_time
239
- self.setPosition(position)
240
239
 
241
240
  def on_slider_released(self) -> None:
242
241
  """Handle slider release event."""
@@ -268,12 +267,8 @@ class MediaPlayer(QMediaPlayer):
268
267
  source_url=QUrl.fromLocalFile(path),
269
268
  )
270
269
 
271
- def set_source_device(
272
- self, io_device: PyQIODevice, source_url: QUrl | None = None
273
- ) -> None:
270
+ def set_source_device(self, io_device: PyQIODevice, source_url: QUrl) -> None:
274
271
  """Play the video."""
275
- if source_url is None:
276
- source_url = QUrl()
277
272
  self.source_url = source_url
278
273
  self.io_device = io_device
279
274
  self.setSourceDevice(self.io_device, self.source_url)
@@ -5,6 +5,8 @@ including getting and creating secrets and fernets.
5
5
  These utilities help with secure storage and retrieval of secrets.
6
6
  """
7
7
 
8
+ from collections.abc import Callable
9
+
8
10
  import keyring
9
11
  from cryptography.fernet import Fernet
10
12
  from cryptography.hazmat.primitives.ciphers.aead import AESGCM
@@ -15,11 +17,9 @@ def get_or_create_fernet(service_name: str, username: str) -> Fernet:
15
17
 
16
18
  If it does not exist, create it with a Fernet.
17
19
  """
18
- secret = keyring.get_password(service_name, username)
19
- if secret is None:
20
- secret = Fernet.generate_key().decode()
21
- keyring.set_password(service_name, username, secret)
22
- return Fernet(secret.encode())
20
+ return get_or_create_key(
21
+ service_name, username, Fernet, lambda: Fernet.generate_key()
22
+ )
23
23
 
24
24
 
25
25
  def get_or_create_aes_gcm(service_name: str, username: str) -> AESGCM:
@@ -27,8 +27,25 @@ def get_or_create_aes_gcm(service_name: str, username: str) -> AESGCM:
27
27
 
28
28
  If it does not exist, create it with a AESGCM.
29
29
  """
30
+ return get_or_create_key(
31
+ service_name, username, AESGCM, lambda: AESGCM.generate_key(bit_length=256)
32
+ )
33
+
34
+
35
+ def get_or_create_key[T](
36
+ service_name: str,
37
+ username: str,
38
+ key_class: Callable[[bytes], T],
39
+ generate_key_func: Callable[..., bytes],
40
+ ) -> T:
41
+ """Get the app secret using keyring.
42
+
43
+ If it does not exist, create it with the generate_func.
44
+ """
45
+ service_name = f"{service_name}_{key_class.__name__}"
30
46
  secret = keyring.get_password(service_name, username)
31
47
  if secret is None:
32
- secret = AESGCM.generate_key(bit_length=256).decode()
48
+ secret = generate_key_func().decode()
33
49
  keyring.set_password(service_name, username, secret)
34
- return AESGCM(secret.encode())
50
+
51
+ return key_class(secret.encode())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: winipedia-utils
3
- Version: 0.1.36
3
+ Version: 0.1.38
4
4
  Summary: A package with many utility functions
5
5
  License: MIT
6
6
  Author: Winipedia
@@ -54,7 +54,7 @@ winipedia_utils/pyside/ui/pages/player.py,sha256=PPmUNejMibKeNUm-a-1VA6i14G743YF
54
54
  winipedia_utils/pyside/ui/widgets/__init__.py,sha256=p-maJQh7gYbXwhkqKU4wL6UNGzRAy988JP8_qLoTZDk,24
55
55
  winipedia_utils/pyside/ui/widgets/browser.py,sha256=5oUyQKYOYu9Zzx6adbewTtAIfnn_RVs8CLoX3rU2g28,6160
56
56
  winipedia_utils/pyside/ui/widgets/clickable_widget.py,sha256=nUZ7ngPFQ7utJuq9A-72TeT1wqCt_xubAxBg3xQSL64,856
57
- winipedia_utils/pyside/ui/widgets/media_player.py,sha256=uTHmdJyiUQBOlZsAVse2CAZG-m6RcMODMX45SbryQYs,11040
57
+ winipedia_utils/pyside/ui/widgets/media_player.py,sha256=jcAGeZo3ey177K2jAmqg1LOyARzn_5z26krZGKVj99c,10909
58
58
  winipedia_utils/pyside/ui/widgets/notification.py,sha256=_zBq9Q6SDFu3fV2AkbvyCNQmOEOy1l9mKOFAAdyteg4,1941
59
59
  winipedia_utils/pyside/ui/windows/__init__.py,sha256=p-maJQh7gYbXwhkqKU4wL6UNGzRAy988JP8_qLoTZDk,24
60
60
  winipedia_utils/pyside/ui/windows/base/__init__.py,sha256=p-maJQh7gYbXwhkqKU4wL6UNGzRAy988JP8_qLoTZDk,24
@@ -69,7 +69,7 @@ winipedia_utils/resources/svgs/play_icon.svg,sha256=U0RQ-S_WbcyyjeWC55BkcOtG64Gf
69
69
  winipedia_utils/resources/svgs/svg.py,sha256=-Dw6m7cm9CHT2076oZIMx7kTQw0v_ifJajXzWcpUtI0,430
70
70
  winipedia_utils/security/__init__.py,sha256=ZBa72J6MNtYumBFMoVc0ia4jsoS7oNgjaTCW0xDb6EI,53
71
71
  winipedia_utils/security/cryptography.py,sha256=zfxSDo7aE9ecmZNC6URMSEUYRpOuJ1iESg-WCSS5HP0,822
72
- winipedia_utils/security/keyring.py,sha256=eJifLGKnlOF_9tB3y6fvHXxr02a-TWOXljb1JI6ztkU,1218
72
+ winipedia_utils/security/keyring.py,sha256=6aQQAn1YH2cC33JCiTIAeeZ83ISj90ijE590eyPM1tU,1590
73
73
  winipedia_utils/setup.py,sha256=F4NneO0wVTf7JCXLorWjTOdJl36N5fLSksoWMe4p86o,1650
74
74
  winipedia_utils/testing/__init__.py,sha256=kXhB5xw02ec5xpcW_KV--9CBKdyCjnuR-NZzAJ5tq0g,51
75
75
  winipedia_utils/testing/assertions.py,sha256=0JF4mqVTnLQ1qkAL_FuTwyN_idr00rvVlta7aDdnUXA,851
@@ -91,7 +91,7 @@ winipedia_utils/testing/tests/base/utils/utils.py,sha256=dUPDrgAxlfREQb33zz23Mfz
91
91
  winipedia_utils/testing/tests/conftest.py,sha256=8RounBlI8Jq1aLaLNpv84MW4ne8Qq0aavQextDOp5ng,920
92
92
  winipedia_utils/text/__init__.py,sha256=j2bwtK6kyeHI6SnoBjpRju0C1W2n2paXBDlNjNtaUxA,48
93
93
  winipedia_utils/text/string.py,sha256=1jbBftlgxffGgSlPnQh3aRPIr8XekEwpSenjFCW6JyM,3478
94
- winipedia_utils-0.1.36.dist-info/LICENSE,sha256=3PrKJ2CWNrnyyHaC_r0wPDSukVWgmjOxHr__eQVH7cw,1087
95
- winipedia_utils-0.1.36.dist-info/METADATA,sha256=dombJeW2JBlMRgVubedOvgrWclo7vxbJ4MWIJeh-fMw,12576
96
- winipedia_utils-0.1.36.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
97
- winipedia_utils-0.1.36.dist-info/RECORD,,
94
+ winipedia_utils-0.1.38.dist-info/LICENSE,sha256=3PrKJ2CWNrnyyHaC_r0wPDSukVWgmjOxHr__eQVH7cw,1087
95
+ winipedia_utils-0.1.38.dist-info/METADATA,sha256=HT7wvz4rMXg3aJcumnZQpV5j681ZAp2PzmA6cXG9jlM,12576
96
+ winipedia_utils-0.1.38.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
97
+ winipedia_utils-0.1.38.dist-info/RECORD,,