mm-std 0.4.0__py3-none-any.whl → 0.4.2__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/config.py
CHANGED
@@ -45,6 +45,6 @@ class BaseConfig(BaseModel):
|
|
45
45
|
data = tomllib.load(f)
|
46
46
|
return Result.success(cls(**data))
|
47
47
|
except ValidationError as e:
|
48
|
-
return Result.
|
48
|
+
return Result.failure(("validator_error", e), extra={"errors": e.errors()})
|
49
49
|
except Exception as e:
|
50
|
-
return Result.
|
50
|
+
return Result.failure(e)
|
mm_std/http/response.py
CHANGED
@@ -57,7 +57,7 @@ class HttpResponse:
|
|
57
57
|
def is_error(self) -> bool:
|
58
58
|
return self.error is not None or (self.status_code is not None and self.status_code >= 400)
|
59
59
|
|
60
|
-
def to_result_err[T](self, error: str | None = None) -> Result[T]:
|
60
|
+
def to_result_err[T](self, error: str | Exception | tuple[str, Exception] | None = None) -> Result[T]:
|
61
61
|
return Result.failure(error or self.error or "error", extra=self.to_dict())
|
62
62
|
|
63
63
|
def to_result_ok[T](self, result: T) -> Result[T]:
|
@@ -72,6 +72,15 @@ class HttpResponse:
|
|
72
72
|
"headers": self.headers,
|
73
73
|
}
|
74
74
|
|
75
|
+
@property
|
76
|
+
def content_type(self) -> str | None:
|
77
|
+
if self.headers is None:
|
78
|
+
return None
|
79
|
+
for key in self.headers:
|
80
|
+
if key.lower() == "content-type":
|
81
|
+
return self.headers[key]
|
82
|
+
return None
|
83
|
+
|
75
84
|
def __repr__(self) -> str:
|
76
85
|
parts: list[str] = []
|
77
86
|
if self.status_code is not None:
|
mm_std/result.py
CHANGED
@@ -97,7 +97,7 @@ class Result[T]:
|
|
97
97
|
new_value = fn(cast(T, self.ok))
|
98
98
|
return Result.success(new_value, extra=self.extra)
|
99
99
|
except Exception as e:
|
100
|
-
return Result.
|
100
|
+
return Result.failure(("map_exception", e), extra=self.extra)
|
101
101
|
return cast(Result[U], self)
|
102
102
|
|
103
103
|
async def map_async(self, fn: Callable[[T], Awaitable[U]]) -> Result[U]:
|
@@ -106,7 +106,7 @@ class Result[T]:
|
|
106
106
|
new_value = await fn(cast(T, self.ok))
|
107
107
|
return Result.success(new_value, extra=self.extra)
|
108
108
|
except Exception as e:
|
109
|
-
return Result.
|
109
|
+
return Result.failure(("map_exception", e), extra=self.extra)
|
110
110
|
return cast(Result[U], self)
|
111
111
|
|
112
112
|
def and_then(self, fn: Callable[[T], Result[U]]) -> Result[U]:
|
@@ -114,7 +114,7 @@ class Result[T]:
|
|
114
114
|
try:
|
115
115
|
return fn(cast(T, self.ok))
|
116
116
|
except Exception as e:
|
117
|
-
return Result.
|
117
|
+
return Result.failure(("and_then_exception", e), extra=self.extra)
|
118
118
|
return cast(Result[U], self)
|
119
119
|
|
120
120
|
async def and_then_async(self, fn: Callable[[T], Awaitable[Result[U]]]) -> Result[U]:
|
@@ -122,7 +122,7 @@ class Result[T]:
|
|
122
122
|
try:
|
123
123
|
return await fn(cast(T, self.ok))
|
124
124
|
except Exception as e:
|
125
|
-
return Result.
|
125
|
+
return Result.failure(("and_then_exception", e), extra=self.extra)
|
126
126
|
return cast(Result[U], self)
|
127
127
|
|
128
128
|
def __repr__(self) -> str:
|
@@ -165,15 +165,43 @@ class Result[T]:
|
|
165
165
|
|
166
166
|
@staticmethod
|
167
167
|
def success(ok: T, extra: Extra = None) -> Result[T]:
|
168
|
-
|
168
|
+
"""
|
169
|
+
Creates a successful Result instance.
|
169
170
|
|
170
|
-
|
171
|
-
|
172
|
-
|
171
|
+
Args:
|
172
|
+
ok: The success value to store in the Result.
|
173
|
+
extra: Optional extra metadata to associate with the Result.
|
174
|
+
|
175
|
+
Returns:
|
176
|
+
A Result instance representing success with the provided value.
|
177
|
+
"""
|
178
|
+
return Result._create(ok=ok, error=None, exception=None, extra=extra)
|
173
179
|
|
174
180
|
@staticmethod
|
175
|
-
def
|
176
|
-
|
181
|
+
def failure(error: str | Exception | tuple[str, Exception], extra: Extra = None) -> Result[T]:
|
182
|
+
"""
|
183
|
+
Creates a Result instance representing a failure.
|
184
|
+
|
185
|
+
Args:
|
186
|
+
error: The error information, which can be:
|
187
|
+
- A string error message
|
188
|
+
- An Exception object
|
189
|
+
- A tuple containing (error_message, exception)
|
190
|
+
extra: Optional extra metadata to associate with the Result.
|
191
|
+
|
192
|
+
Returns:
|
193
|
+
A Result instance representing failure with the provided error information.
|
194
|
+
"""
|
195
|
+
if isinstance(error, tuple):
|
196
|
+
error_, exception = error
|
197
|
+
elif isinstance(error, Exception):
|
198
|
+
error_ = "exception"
|
199
|
+
exception = error
|
200
|
+
else:
|
201
|
+
error_ = error
|
202
|
+
exception = None
|
203
|
+
|
204
|
+
return Result._create(ok=None, error=error_, exception=exception, extra=extra)
|
177
205
|
|
178
206
|
@classmethod
|
179
207
|
def __get_pydantic_core_schema__(cls, _source_type: type[Any], _handler: GetCoreSchemaHandler) -> CoreSchema:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
mm_std/__init__.py,sha256=Kl-7TT_hd-xmwDJJ0E5AO2Qjpj5H8H7A93DgDwv_r-0,2804
|
2
2
|
mm_std/command.py,sha256=ze286wjUjg0QSTgIu-2WZks53_Vclg69UaYYgPpQvCU,1283
|
3
|
-
mm_std/config.py,sha256=
|
3
|
+
mm_std/config.py,sha256=QtF-SCzaHZf511miTDjmIWR2dFfVPsnw2x6B5rmhMMk,1884
|
4
4
|
mm_std/crypto.py,sha256=jdk0_TCmeU0pPXMyz9xH6kQHSjjZ9GcGClBwQps5vBo,340
|
5
5
|
mm_std/date.py,sha256=976eEkSONuNqHQBgSRu8hrtH23tJqztbmHFHLdbP2TY,1879
|
6
6
|
mm_std/dict.py,sha256=6GkhJPXD0LiJDxPcYe6jPdEDw-MN7P7mKu6U5XxwYDk,675
|
@@ -12,7 +12,7 @@ mm_std/net.py,sha256=qdRCBIDneip6FaPNe5mx31UtYVmzqam_AoUF7ydEyjA,590
|
|
12
12
|
mm_std/print_.py,sha256=zB7sVbSSF8RffMxvnOdbKCXjCKtKzKV3R68pBri4NkQ,1638
|
13
13
|
mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
mm_std/random_.py,sha256=OuUX4VJeSd13NZBya4qrGpR2TfN7_87tfebOY6DBUnI,1113
|
15
|
-
mm_std/result.py,sha256=
|
15
|
+
mm_std/result.py,sha256=VrEIJvFaVFus-b5s75I8PATvfoIRQw084zuOhbnbRSA,7655
|
16
16
|
mm_std/str.py,sha256=BEjJ1p5O4-uSYK0h-enasSSDdwzkBbiwdQ4_dsrlEE8,3257
|
17
17
|
mm_std/toml.py,sha256=CNznWKR0bpOxS6e3VB5LGS-Oa9lW-wterkcPUFtPcls,610
|
18
18
|
mm_std/types_.py,sha256=9FGd2q47a8M9QQgsWJR1Kq34jLxBAkYSoJuwih4PPqg,257
|
@@ -27,7 +27,7 @@ mm_std/concurrency/sync_task_runner.py,sha256=s5JPlLYLGQGHIxy4oDS-PN7O9gcy-yPZFo
|
|
27
27
|
mm_std/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
28
|
mm_std/http/http_request.py,sha256=h74_ZjACwdbeINjzhuEwNUpvnaHZvyGl7TExjlBwMGg,3704
|
29
29
|
mm_std/http/http_request_sync.py,sha256=aawVZfopzMI0alS3lkJQmVOVxH51rmtvsOK_inUlJOs,1537
|
30
|
-
mm_std/http/response.py,sha256=
|
31
|
-
mm_std-0.4.
|
32
|
-
mm_std-0.4.
|
33
|
-
mm_std-0.4.
|
30
|
+
mm_std/http/response.py,sha256=Y6voWD3y_iK-tYBuXPborjcD7Y6-piupD6kcGXmAqmY,3911
|
31
|
+
mm_std-0.4.2.dist-info/METADATA,sha256=j2djNKVv_DiXYat3p3hbpBaKzaSj5m-CExfViW5qVHU,446
|
32
|
+
mm_std-0.4.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
33
|
+
mm_std-0.4.2.dist-info/RECORD,,
|
File without changes
|