dycw-utilities 0.174.9__py3-none-any.whl → 0.174.10__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dycw-utilities
3
- Version: 0.174.9
3
+ Version: 0.174.10
4
4
  Author: Derek Wan
5
5
  Author-email: Derek Wan <d.wan@icloud.com>
6
6
  Requires-Dist: atomicwrites>=1.4.1,<1.5
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=s0yfL-qs6UI6ltNUkBKltAzsUuIudzaPhHhfNI2ILBI,60
1
+ utilities/__init__.py,sha256=0CWy0Ep-3LcvfPyRs5NDWEzJToyo7mozx2oLa1j9OoA,61
2
2
  utilities/aeventkit.py,sha256=OmDBhYGgbsKrB7cdC5FFpJHUatX9O76eTeKVVTksp2Y,12673
3
3
  utilities/altair.py,sha256=rUK99g9x6CYDDfiZrf-aTx5fSRbL1Q8ctgKORowzXHg,9060
4
4
  utilities/asyncio.py,sha256=aJySVxBY0gqsIYnoNmH7-1r8djKuf4vSsU69VCD08t8,16772
@@ -47,7 +47,7 @@ utilities/orjson.py,sha256=T_0SlK811ysg46d3orvIPY3JpBa4FRMpP2wlPQo7-gU,41854
47
47
  utilities/os.py,sha256=kjKKSQfnRqFTTZ315iavaaGd3gGuYNoSWlxVLCJjyQs,4852
48
48
  utilities/parse.py,sha256=g7Qm9eBOIeDId2tGA021CIaeF6jp1TI8rx4srdvlyoo,17937
49
49
  utilities/pathlib.py,sha256=EKZn-wWxH7MEWFrQGqHIoB-GJzyXeiEj8iDIgvkr8Wk,9325
50
- utilities/permissions.py,sha256=PlY95KIon6onivvZt8H1dKlzPXatLdZ5cUPdfwZDfs4,9408
50
+ utilities/permissions.py,sha256=HSVpLef4lfG6GsbeDgYbKRe_92Kk6dNPrB0kw7GsXMY,8093
51
51
  utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
52
52
  utilities/platform.py,sha256=0pYO5v7L2sU5UN87zHhEEhTKsZ9NIEM8N6UCr0F7bLY,2778
53
53
  utilities/polars.py,sha256=cNFBLWgOMUAp_Sz4xtlto17uZswZRrcfQYC95QKyaY4,87483
@@ -98,7 +98,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
98
98
  utilities/whenever.py,sha256=F4ek0-OBWxHYrZdmoZt76N2RnNyKY5KrEHt7rqO4AQE,60183
99
99
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
100
100
  utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
101
- dycw_utilities-0.174.9.dist-info/WHEEL,sha256=ZyFSCYkV2BrxH6-HRVRg3R9Fo7MALzer9KiPYqNxSbo,79
102
- dycw_utilities-0.174.9.dist-info/entry_points.txt,sha256=ykGI1ArwOPHqm2g5Cqh3ENdMxEej_a_FcOUov5EM5Oc,155
103
- dycw_utilities-0.174.9.dist-info/METADATA,sha256=LpxiNDUuPoCbqx1Jb4H4UsVRdjGHNrGyeslCZqKy2AE,1709
104
- dycw_utilities-0.174.9.dist-info/RECORD,,
101
+ dycw_utilities-0.174.10.dist-info/WHEEL,sha256=ZyFSCYkV2BrxH6-HRVRg3R9Fo7MALzer9KiPYqNxSbo,79
102
+ dycw_utilities-0.174.10.dist-info/entry_points.txt,sha256=ykGI1ArwOPHqm2g5Cqh3ENdMxEej_a_FcOUov5EM5Oc,155
103
+ dycw_utilities-0.174.10.dist-info/METADATA,sha256=xJJPzLScczDipOwF6AP4Tqr8p__BH8NV6WcuwhqZIq0,1710
104
+ dycw_utilities-0.174.10.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.174.9"
3
+ __version__ = "0.174.10"
utilities/permissions.py CHANGED
@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- from contextlib import suppress
4
3
  from dataclasses import dataclass
5
4
  from functools import reduce
6
5
  from operator import or_
@@ -18,20 +17,8 @@ from stat import (
18
17
  from typing import Literal, Self, override
19
18
 
20
19
  from utilities.dataclasses import replace_non_sentinel
21
- from utilities.functions import ensure_member
22
- from utilities.re import (
23
- ExtractGroupError,
24
- ExtractGroupsError,
25
- extract_group,
26
- extract_groups,
27
- )
20
+ from utilities.re import ExtractGroupsError, extract_groups
28
21
  from utilities.sentinel import Sentinel, sentinel
29
- from utilities.typing import get_args
30
-
31
- _MIN_INT = 0o0
32
- _MAX_INT = 0o777
33
- type _ZeroToSeven = Literal[0, 1, 2, 3, 4, 5, 6, 7]
34
- _ZERO_TO_SEVEN: list[_ZeroToSeven] = list(get_args(_ZeroToSeven.__value__))
35
22
 
36
23
 
37
24
  @dataclass(order=True, unsafe_hash=True, kw_only=True, slots=True)
@@ -65,7 +52,7 @@ class Permissions:
65
52
 
66
53
  def _int(
67
54
  self, *, read: bool = False, write: bool = False, execute: bool = False
68
- ) -> _ZeroToSeven:
55
+ ) -> int:
69
56
  return (4 if read else 0) + (2 if write else 0) + (1 if execute else 0)
70
57
 
71
58
  @override
@@ -115,65 +102,32 @@ class Permissions:
115
102
 
116
103
  @classmethod
117
104
  def from_int(cls, n: int, /) -> Self:
118
- with suppress(ExtractGroupsError):
119
- user, group, others = extract_groups(r"^([0-7])([0-7])([0-7])$", str(n))
120
- user_read, user_write, user_execute = cls._from_int(
121
- ensure_member(int(user), _ZERO_TO_SEVEN)
122
- )
123
- group_read, group_write, group_execute = cls._from_int(
124
- ensure_member(int(group), _ZERO_TO_SEVEN)
125
- )
126
- others_read, others_write, others_execute = cls._from_int(
127
- ensure_member(int(others), _ZERO_TO_SEVEN)
128
- )
129
- return cls(
130
- user_read=user_read,
131
- user_write=user_write,
132
- user_execute=user_execute,
133
- group_read=group_read,
134
- group_write=group_write,
135
- group_execute=group_execute,
136
- others_read=others_read,
137
- others_write=others_write,
138
- others_execute=others_execute,
139
- )
140
- with suppress(ExtractGroupsError):
141
- group, others = extract_groups(r"^([0-7])([0-7])$", str(n))
142
- group_read, group_write, group_execute = cls._from_int(
143
- ensure_member(int(group), _ZERO_TO_SEVEN)
144
- )
145
- others_read, others_write, others_execute = cls._from_int(
146
- ensure_member(int(others), _ZERO_TO_SEVEN)
147
- )
148
- return cls(
149
- group_read=group_read,
150
- group_write=group_write,
151
- group_execute=group_execute,
152
- others_read=others_read,
153
- others_write=others_write,
154
- others_execute=others_execute,
155
- )
156
- with suppress(ExtractGroupError):
157
- others = extract_group(r"^([0-7])$", str(n))
158
- others_read, others_write, others_execute = cls._from_int(
159
- ensure_member(int(others), _ZERO_TO_SEVEN)
160
- )
161
- return cls(
162
- others_read=others_read,
163
- others_write=others_write,
164
- others_execute=others_execute,
165
- )
166
- if n == 0:
167
- return cls()
168
- raise PermissionsFromIntError(n=n)
105
+ if not (0 <= n <= 777):
106
+ raise PermissionsFromIntRangeError(n=n)
107
+ user_read, user_write, user_execute = cls._from_int(n, (n // 100) % 10)
108
+ group_read, group_write, group_execute = cls._from_int(n, (n // 10) % 10)
109
+ others_read, others_write, others_execute = cls._from_int(n, n % 10)
110
+ return cls(
111
+ user_read=user_read,
112
+ user_write=user_write,
113
+ user_execute=user_execute,
114
+ group_read=group_read,
115
+ group_write=group_write,
116
+ group_execute=group_execute,
117
+ others_read=others_read,
118
+ others_write=others_write,
119
+ others_execute=others_execute,
120
+ )
169
121
 
170
122
  @classmethod
171
- def _from_int(cls, n: _ZeroToSeven, /) -> tuple[bool, bool, bool]:
172
- return bool(4 & n), bool(2 & n), bool(1 & n)
123
+ def _from_int(cls, n: int, digit: int, /) -> tuple[bool, bool, bool]:
124
+ if not (0 <= digit <= 7):
125
+ raise PermissionsFromIntDigitError(n=n, digit=digit)
126
+ return bool(4 & digit), bool(2 & digit), bool(1 & digit)
173
127
 
174
128
  @classmethod
175
129
  def from_octal(cls, n: int, /) -> Self:
176
- if _MIN_INT <= n <= _MAX_INT:
130
+ if 0o0 <= n <= 0o777:
177
131
  return cls(
178
132
  user_read=bool(n & S_IRUSR),
179
133
  user_write=bool(n & S_IWUSR),
@@ -265,11 +219,23 @@ class PermissionsError(Exception): ...
265
219
  class PermissionsFromIntError(PermissionsError):
266
220
  n: int
267
221
 
222
+
223
+ @dataclass(kw_only=True, slots=True)
224
+ class PermissionsFromIntRangeError(PermissionsFromIntError):
268
225
  @override
269
226
  def __str__(self) -> str:
270
227
  return f"Invalid integer for permissions; got {self.n}"
271
228
 
272
229
 
230
+ @dataclass(kw_only=True, slots=True)
231
+ class PermissionsFromIntDigitError(PermissionsFromIntError):
232
+ digit: int
233
+
234
+ @override
235
+ def __str__(self) -> str:
236
+ return f"Invalid integer for permissions; got digit {self.digit} in {self.n}"
237
+
238
+
273
239
  @dataclass(kw_only=True, slots=True)
274
240
  class PermissionsFromOctalError(PermissionsError):
275
241
  n: int
@@ -291,6 +257,7 @@ class PermissionsFromTextError(PermissionsError):
291
257
  __all__ = [
292
258
  "Permissions",
293
259
  "PermissionsError",
260
+ "PermissionsFromIntDigitError",
294
261
  "PermissionsFromIntError",
295
262
  "PermissionsFromOctalError",
296
263
  "PermissionsFromTextError",