mm-std 0.1.6__py3-none-any.whl → 0.1.8__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/concurrency.py +4 -4
- mm_std/config.py +1 -4
- mm_std/net.py +3 -5
- mm_std/random_.py +1 -4
- mm_std/result.py +22 -33
- mm_std-0.1.8.dist-info/METADATA +11 -0
- {mm_std-0.1.6.dist-info → mm_std-0.1.8.dist-info}/RECORD +8 -8
- mm_std-0.1.6.dist-info/METADATA +0 -11
- {mm_std-0.1.6.dist-info → mm_std-0.1.8.dist-info}/WHEEL +0 -0
mm_std/concurrency.py
CHANGED
@@ -8,13 +8,13 @@ from dataclasses import dataclass, field
|
|
8
8
|
from datetime import datetime
|
9
9
|
from logging import Logger
|
10
10
|
from threading import Lock, Thread
|
11
|
-
from typing import ParamSpec,
|
11
|
+
from typing import ParamSpec, TypeVar
|
12
12
|
|
13
13
|
from .date import is_too_old, utc_now
|
14
14
|
|
15
|
-
Func
|
16
|
-
Args
|
17
|
-
Kwargs
|
15
|
+
type Func = Callable[..., object]
|
16
|
+
type Args = tuple[object, ...]
|
17
|
+
type Kwargs = dict[str, object]
|
18
18
|
|
19
19
|
|
20
20
|
class ConcurrentTasks:
|
mm_std/config.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import io
|
2
2
|
from pathlib import Path
|
3
|
-
from typing import TypeVar
|
4
3
|
|
5
4
|
import yaml
|
6
5
|
from pydantic import BaseModel, ConfigDict, ValidationError
|
@@ -9,8 +8,6 @@ from .print_ import PrintFormat, print_console, print_json, print_plain, print_t
|
|
9
8
|
from .str import str_to_list
|
10
9
|
from .zip import read_text_from_zip_archive
|
11
10
|
|
12
|
-
T = TypeVar("T")
|
13
|
-
|
14
11
|
|
15
12
|
class BaseConfig(BaseModel):
|
16
13
|
model_config = ConfigDict(extra="forbid")
|
@@ -32,7 +29,7 @@ class BaseConfig(BaseModel):
|
|
32
29
|
return v
|
33
30
|
|
34
31
|
@classmethod
|
35
|
-
def read_config( # nosec
|
32
|
+
def read_config[T]( # nosec: B107
|
36
33
|
cls: type[T],
|
37
34
|
config_path: io.TextIOWrapper | str | Path,
|
38
35
|
error_print_type: PrintFormat = PrintFormat.PLAIN,
|
mm_std/net.py
CHANGED
@@ -3,7 +3,7 @@ import socket
|
|
3
3
|
import time
|
4
4
|
from dataclasses import asdict, dataclass, field
|
5
5
|
from json import JSONDecodeError
|
6
|
-
from typing import Any,
|
6
|
+
from typing import Any, cast
|
7
7
|
from urllib.parse import urlencode
|
8
8
|
|
9
9
|
import httpx
|
@@ -15,8 +15,6 @@ FIREFOX_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Ge
|
|
15
15
|
SAFARI_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15" # fmt: skip # noqa
|
16
16
|
CHROME_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" # fmt: skip # noqa
|
17
17
|
|
18
|
-
T = TypeVar("T")
|
19
|
-
|
20
18
|
|
21
19
|
@dataclass
|
22
20
|
class HResponse:
|
@@ -57,10 +55,10 @@ class HResponse:
|
|
57
55
|
return self.headers[key]
|
58
56
|
return None
|
59
57
|
|
60
|
-
def to_err_result(self, error: str | None = None) -> Err:
|
58
|
+
def to_err_result[T](self, error: str | None = None) -> Err:
|
61
59
|
return Err(error or self.error or "error", data=asdict(self))
|
62
60
|
|
63
|
-
def to_ok_result(self, result: T) -> Result[T]:
|
61
|
+
def to_ok_result[T](self, result: T) -> Result[T]:
|
64
62
|
return Ok(result, data=asdict(self))
|
65
63
|
|
66
64
|
def is_error(self) -> bool:
|
mm_std/random_.py
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
import random
|
2
2
|
from collections.abc import Sequence
|
3
3
|
from decimal import Decimal
|
4
|
-
from typing import TypeVar
|
5
4
|
|
6
|
-
T = TypeVar("T", contravariant=True)
|
7
5
|
|
8
|
-
|
9
|
-
def random_choice(source: Sequence[T] | T | None) -> T | None:
|
6
|
+
def random_choice[T](source: Sequence[T] | T | None) -> T | None:
|
10
7
|
"""Deprecated, don't use it"""
|
11
8
|
if source is None:
|
12
9
|
return None
|
mm_std/result.py
CHANGED
@@ -2,17 +2,12 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import time
|
4
4
|
from collections.abc import Callable
|
5
|
-
from typing import Any,
|
5
|
+
from typing import Any, Literal, NoReturn
|
6
6
|
|
7
7
|
from pydantic_core import core_schema
|
8
8
|
|
9
|
-
T = TypeVar("T", covariant=True) # Success type
|
10
|
-
U = TypeVar("U")
|
11
|
-
F = TypeVar("F")
|
12
|
-
TBE = TypeVar("TBE", bound=BaseException)
|
13
9
|
|
14
|
-
|
15
|
-
class Ok(Generic[T]):
|
10
|
+
class Ok[T]:
|
16
11
|
__match_args__ = ("ok",)
|
17
12
|
|
18
13
|
def __init__(self, ok: T, data: Any = None) -> None:
|
@@ -56,7 +51,7 @@ class Ok(Generic[T]):
|
|
56
51
|
def unwrap_err(self) -> NoReturn:
|
57
52
|
raise UnwrapError(self, "Called `Result.unwrap_err()` on an `Ok` value")
|
58
53
|
|
59
|
-
def unwrap_or(self, _default: U) -> T:
|
54
|
+
def unwrap_or[U](self, _default: U) -> T:
|
60
55
|
return self.ok
|
61
56
|
|
62
57
|
def unwrap_or_else(self, op: object) -> T:
|
@@ -65,13 +60,13 @@ class Ok(Generic[T]):
|
|
65
60
|
def unwrap_or_raise(self, e: object) -> T:
|
66
61
|
return self.ok
|
67
62
|
|
68
|
-
def map(self, op: Callable[[T], U]) -> Ok[U]:
|
63
|
+
def map[U](self, op: Callable[[T], U]) -> Ok[U]:
|
69
64
|
return Ok(op(self.ok), data=self.data)
|
70
65
|
|
71
|
-
def map_or(self, default: object, op: Callable[[T], U]) -> U:
|
66
|
+
def map_or[U](self, default: object, op: Callable[[T], U]) -> U:
|
72
67
|
return op(self.ok)
|
73
68
|
|
74
|
-
def map_or_else(self, err_op: object, ok_op: Callable[[T], U]) -> U:
|
69
|
+
def map_or_else[U](self, err_op: object, ok_op: Callable[[T], U]) -> U:
|
75
70
|
"""
|
76
71
|
The contained result is `Ok`, so return original value mapped to
|
77
72
|
a new value using the passed in `op` function.
|
@@ -84,7 +79,7 @@ class Ok(Generic[T]):
|
|
84
79
|
"""
|
85
80
|
return self
|
86
81
|
|
87
|
-
def and_then(self, op: Callable[[T], U | Result[U]]) -> Result[U]:
|
82
|
+
def and_then[U](self, op: Callable[[T], U | Result[U]]) -> Result[U]:
|
88
83
|
"""
|
89
84
|
The contained result is `Ok`, so return the result of `op` with the
|
90
85
|
original value passed in. If return of `op` function is not Result, it will be a Ok value.
|
@@ -115,7 +110,7 @@ class Ok(Generic[T]):
|
|
115
110
|
{
|
116
111
|
"ok": core_schema.model_field(core_schema.any_schema()),
|
117
112
|
"data": core_schema.model_field(core_schema.any_schema()),
|
118
|
-
}
|
113
|
+
},
|
119
114
|
),
|
120
115
|
)
|
121
116
|
|
@@ -159,10 +154,7 @@ class Err:
|
|
159
154
|
"""
|
160
155
|
Raises an `UnwrapError`.
|
161
156
|
"""
|
162
|
-
exc = UnwrapError(
|
163
|
-
self,
|
164
|
-
f"{message}: {self.err!r}",
|
165
|
-
)
|
157
|
+
exc = UnwrapError(self, f"{message}: {self.err!r}")
|
166
158
|
if isinstance(self.err, BaseException):
|
167
159
|
raise exc from self.err
|
168
160
|
raise exc
|
@@ -177,10 +169,7 @@ class Err:
|
|
177
169
|
"""
|
178
170
|
Raises an `UnwrapError`.
|
179
171
|
"""
|
180
|
-
exc = UnwrapError(
|
181
|
-
self,
|
182
|
-
f"Called `Result.unwrap()` on an `Err` value: {self.err!r}",
|
183
|
-
)
|
172
|
+
exc = UnwrapError(self, f"Called `Result.unwrap()` on an `Err` value: {self.err!r}")
|
184
173
|
if isinstance(self.err, BaseException):
|
185
174
|
raise exc from self.err
|
186
175
|
raise exc
|
@@ -191,20 +180,20 @@ class Err:
|
|
191
180
|
"""
|
192
181
|
return self.err
|
193
182
|
|
194
|
-
def unwrap_or(self, default: U) -> U:
|
183
|
+
def unwrap_or[U](self, default: U) -> U:
|
195
184
|
"""
|
196
185
|
Return `default`.
|
197
186
|
"""
|
198
187
|
return default
|
199
188
|
|
200
|
-
def unwrap_or_else(self, op: Callable[[str], T]) -> T:
|
189
|
+
def unwrap_or_else[T](self, op: Callable[[str], T]) -> T:
|
201
190
|
"""
|
202
191
|
The contained result is ``Err``, so return the result of applying
|
203
192
|
``op`` to the error value.
|
204
193
|
"""
|
205
194
|
return op(self.err)
|
206
195
|
|
207
|
-
def unwrap_or_raise(self, e: type[TBE]) -> NoReturn:
|
196
|
+
def unwrap_or_raise[TBE: BaseException](self, e: type[TBE]) -> NoReturn:
|
208
197
|
"""
|
209
198
|
The contained result is ``Err``, so raise the exception with the value.
|
210
199
|
"""
|
@@ -216,13 +205,13 @@ class Err:
|
|
216
205
|
"""
|
217
206
|
return self
|
218
207
|
|
219
|
-
def map_or(self, default: U, op: object) -> U:
|
208
|
+
def map_or[U](self, default: U, op: object) -> U:
|
220
209
|
"""
|
221
210
|
Return the default value
|
222
211
|
"""
|
223
212
|
return default
|
224
213
|
|
225
|
-
def map_or_else(self, err_op: Callable[[str], U], ok_op: object) -> U:
|
214
|
+
def map_or_else[U](self, err_op: Callable[[str], U], ok_op: object) -> U:
|
226
215
|
"""
|
227
216
|
Return the result of the default operation
|
228
217
|
"""
|
@@ -234,10 +223,10 @@ class Err:
|
|
234
223
|
"""
|
235
224
|
return self
|
236
225
|
|
237
|
-
def ok_or_err(self) -> T | str:
|
226
|
+
def ok_or_err[T](self) -> T | str:
|
238
227
|
return self.err
|
239
228
|
|
240
|
-
def ok_or_none(self) -> T | None:
|
229
|
+
def ok_or_none[T](self) -> T | None:
|
241
230
|
return None
|
242
231
|
|
243
232
|
@classmethod
|
@@ -248,18 +237,18 @@ class Err:
|
|
248
237
|
{
|
249
238
|
"err": core_schema.model_field(core_schema.any_schema()),
|
250
239
|
"data": core_schema.model_field(core_schema.any_schema()),
|
251
|
-
}
|
240
|
+
},
|
252
241
|
),
|
253
242
|
)
|
254
243
|
|
255
244
|
|
256
|
-
Result
|
245
|
+
type Result[T] = Ok[T] | Err
|
257
246
|
|
258
247
|
|
259
248
|
class UnwrapError(Exception):
|
260
|
-
_result: Result[
|
249
|
+
_result: Result[Any]
|
261
250
|
|
262
|
-
def __init__(self, result: Result[
|
251
|
+
def __init__(self, result: Result[Any], message: str) -> None:
|
263
252
|
self._result = result
|
264
253
|
super().__init__(message)
|
265
254
|
|
@@ -268,7 +257,7 @@ class UnwrapError(Exception):
|
|
268
257
|
return self._result
|
269
258
|
|
270
259
|
|
271
|
-
def try_ok(fn: Callable[..., Result[T]], *, args: tuple[object], attempts: int, delay: int | float = 0) -> Result[T]:
|
260
|
+
def try_ok[T](fn: Callable[..., Result[T]], *, args: tuple[object], attempts: int, delay: int | float = 0) -> Result[T]:
|
272
261
|
if attempts <= 0:
|
273
262
|
raise ValueError("attempts must be more than zero")
|
274
263
|
res: Result[T] = Err("not started")
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: mm-std
|
3
|
+
Version: 0.1.8
|
4
|
+
Requires-Python: >=3.12
|
5
|
+
Requires-Dist: cryptography~=44.0.0
|
6
|
+
Requires-Dist: httpx[http2,socks]~=0.28.0
|
7
|
+
Requires-Dist: pydantic~=2.10.2
|
8
|
+
Requires-Dist: pydash~=8.0.4
|
9
|
+
Requires-Dist: python-dotenv~=1.0.1
|
10
|
+
Requires-Dist: pyyaml~=6.0.1
|
11
|
+
Requires-Dist: rich~=13.0
|
@@ -1,7 +1,7 @@
|
|
1
1
|
mm_std/__init__.py,sha256=4pa6AjO-0mfrfBi6FS5sqOk1HFAKt2OMovA12ys7UvQ,2288
|
2
2
|
mm_std/command.py,sha256=r1n9ZHyMFhNkNOH9grRCm5J0hhX4_v0c2wdaal8iCZY,1270
|
3
|
-
mm_std/concurrency.py,sha256=
|
4
|
-
mm_std/config.py,sha256=
|
3
|
+
mm_std/concurrency.py,sha256=SZGSTlswpFRZwsI7ztFWYca1XOPToLe0oBNJBZlSlgo,5311
|
4
|
+
mm_std/config.py,sha256=Wo_VS6MO1vTZosOHv97mCo41YYGKZaRAeergaSVzUcs,3111
|
5
5
|
mm_std/crypto.py,sha256=jdk0_TCmeU0pPXMyz9xH6kQHSjjZ9GcGClBwQps5vBo,340
|
6
6
|
mm_std/date.py,sha256=dhlBE8dTzPe0Qhu5f6YMeR5ka5k2B0IoMe8VA7_-pII,1969
|
7
7
|
mm_std/dict.py,sha256=kJBPVG9vEqHiSgKKoji8gVGL1yEBbxAmFNn0zz17AUg,180
|
@@ -9,15 +9,15 @@ mm_std/env.py,sha256=5zaR9VeIfObN-4yfgxoFeU5IM1GDeZZj9SuYf7t9sOA,125
|
|
9
9
|
mm_std/fs.py,sha256=RwarNRJq3tIMG6LVX_g03hasfYpjYFh_O27oVDt5IPQ,291
|
10
10
|
mm_std/json_.py,sha256=12uGLwmnrRA63QI0nUx-UU33zXcyShbsKCoOQiIJ8io,1016
|
11
11
|
mm_std/log.py,sha256=6ux6njNKc_ZCQlvWn1FZR6vcSY2Cem-mQzmNXvsg5IE,913
|
12
|
-
mm_std/net.py,sha256=
|
12
|
+
mm_std/net.py,sha256=k3kl9OY23VoF2md6UyRBDQ9lhRzWlFCuhalDtv6Of90,4686
|
13
13
|
mm_std/print_.py,sha256=mMixwfdrLEYW15ez7_QxXdrV-d38q9XJP8tB8F7P2pI,1553
|
14
14
|
mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
-
mm_std/random_.py,sha256=
|
16
|
-
mm_std/result.py,sha256=
|
15
|
+
mm_std/random_.py,sha256=OuUX4VJeSd13NZBya4qrGpR2TfN7_87tfebOY6DBUnI,1113
|
16
|
+
mm_std/result.py,sha256=1uCb2YySZGHLVNrGRQYhs6BngB8aEW2MKY9Bx6j2wNQ,7407
|
17
17
|
mm_std/str.py,sha256=nG5XF5870xM2PAvU0LZrJDk-d54LYwRLGnSahIekOVw,3151
|
18
18
|
mm_std/telegram.py,sha256=QrHPnsy0LTeqpd-g3RaHhk7gWIfHZEgnMs-S5DLW-vU,1220
|
19
19
|
mm_std/types.py,sha256=KpFtJ-BTmDfmmFeOSlgq6cMbCfGGOQjh1oWvdcrW-kw,116
|
20
20
|
mm_std/zip.py,sha256=2EXcae4HO5U4kObj2Lj8jl5F2OUpT-WRlJybTyFzt6I,370
|
21
|
-
mm_std-0.1.
|
22
|
-
mm_std-0.1.
|
23
|
-
mm_std-0.1.
|
21
|
+
mm_std-0.1.8.dist-info/METADATA,sha256=qS2lfsHdWITmGzMWqikfNAAA-bZrWRfZHayi1_tF5bA,304
|
22
|
+
mm_std-0.1.8.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
23
|
+
mm_std-0.1.8.dist-info/RECORD,,
|
mm_std-0.1.6.dist-info/METADATA
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.3
|
2
|
-
Name: mm-std
|
3
|
-
Version: 0.1.6
|
4
|
-
Requires-Python: >=3.12
|
5
|
-
Requires-Dist: cryptography~=43.0.3
|
6
|
-
Requires-Dist: httpx[http2,socks]~=0.27.2
|
7
|
-
Requires-Dist: pydantic~=2.9.2
|
8
|
-
Requires-Dist: pydash~=8.0.0
|
9
|
-
Requires-Dist: python-dotenv~=1.0.1
|
10
|
-
Requires-Dist: pyyaml~=6.0.1
|
11
|
-
Requires-Dist: rich~=13.0
|
File without changes
|