Spaces:
Sleeping
Sleeping
Upload backend/venv/lib/python3.10/site-packages/marshmallow/exceptions.py with huggingface_hub
Browse files
backend/venv/lib/python3.10/site-packages/marshmallow/exceptions.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Exception classes for marshmallow-related errors."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import typing
|
| 6 |
+
|
| 7 |
+
# Key used for schema-level validation errors
|
| 8 |
+
SCHEMA = "_schema"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class MarshmallowError(Exception):
|
| 12 |
+
"""Base class for all marshmallow-related errors."""
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class ValidationError(MarshmallowError):
|
| 16 |
+
"""Raised when validation fails on a field or schema.
|
| 17 |
+
|
| 18 |
+
Validators and custom fields should raise this exception.
|
| 19 |
+
|
| 20 |
+
:param message: An error message, list of error messages, or dict of
|
| 21 |
+
error messages. If a dict, the keys are subitems and the values are error messages.
|
| 22 |
+
:param field_name: Field name to store the error on.
|
| 23 |
+
If `None`, the error is stored as schema-level error.
|
| 24 |
+
:param data: Raw input data.
|
| 25 |
+
:param valid_data: Valid (de)serialized data.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def __init__(
|
| 29 |
+
self,
|
| 30 |
+
message: str | list | dict,
|
| 31 |
+
field_name: str = SCHEMA,
|
| 32 |
+
data: typing.Mapping[str, typing.Any]
|
| 33 |
+
| typing.Iterable[typing.Mapping[str, typing.Any]]
|
| 34 |
+
| None = None,
|
| 35 |
+
valid_data: list[dict[str, typing.Any]] | dict[str, typing.Any] | None = None,
|
| 36 |
+
**kwargs,
|
| 37 |
+
):
|
| 38 |
+
self.messages = [message] if isinstance(message, (str, bytes)) else message
|
| 39 |
+
self.field_name = field_name
|
| 40 |
+
self.data = data
|
| 41 |
+
self.valid_data = valid_data
|
| 42 |
+
self.kwargs = kwargs
|
| 43 |
+
super().__init__(message)
|
| 44 |
+
|
| 45 |
+
def normalized_messages(self):
|
| 46 |
+
if self.field_name == SCHEMA and isinstance(self.messages, dict):
|
| 47 |
+
return self.messages
|
| 48 |
+
return {self.field_name: self.messages}
|
| 49 |
+
|
| 50 |
+
@property
|
| 51 |
+
def messages_dict(self) -> dict[str, typing.Any]:
|
| 52 |
+
if not isinstance(self.messages, dict):
|
| 53 |
+
raise TypeError(
|
| 54 |
+
"cannot access 'messages_dict' when 'messages' is of type "
|
| 55 |
+
+ type(self.messages).__name__
|
| 56 |
+
)
|
| 57 |
+
return self.messages
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class RegistryError(NameError):
|
| 61 |
+
"""Raised when an invalid operation is performed on the serializer
|
| 62 |
+
class registry.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class StringNotCollectionError(MarshmallowError, TypeError):
|
| 67 |
+
"""Raised when a string is passed when a list of strings is expected."""
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class FieldInstanceResolutionError(MarshmallowError, TypeError):
|
| 71 |
+
"""Raised when schema to instantiate is neither a Schema class nor an instance."""
|