| 1395 | category=None, |
| 1396 | ) |
| 1397 | def parse_raw( # noqa: D102 |
| 1398 | cls, |
| 1399 | b: str | bytes, |
| 1400 | *, |
| 1401 | content_type: str | None = None, |
| 1402 | encoding: str = 'utf8', |
| 1403 | proto: DeprecatedParseProtocol | None = None, |
| 1404 | allow_pickle: bool = False, |
| 1405 | ) -> Self: # pragma: no cover |
| 1406 | warnings.warn( |
| 1407 | 'The `parse_raw` method is deprecated; if your data is JSON use `model_validate_json`, ' |
| 1408 | 'otherwise load the data then use `model_validate` instead.', |
| 1409 | category=PydanticDeprecatedSince20, |
| 1410 | stacklevel=2, |
| 1411 | ) |
| 1412 | from .deprecated import parse |
| 1413 | |
| 1414 | try: |
| 1415 | obj = parse.load_str_bytes( |
| 1416 | b, |
| 1417 | proto=proto, |
| 1418 | content_type=content_type, |
| 1419 | encoding=encoding, |
| 1420 | allow_pickle=allow_pickle, |
| 1421 | ) |
| 1422 | except (ValueError, TypeError) as exc: |
| 1423 | import json |
| 1424 | |
| 1425 | # try to match V1 |
| 1426 | if isinstance(exc, UnicodeDecodeError): |
| 1427 | type_str = 'value_error.unicodedecode' |
| 1428 | elif isinstance(exc, json.JSONDecodeError): |
| 1429 | type_str = 'value_error.jsondecode' |
| 1430 | elif isinstance(exc, ValueError): |
| 1431 | type_str = 'value_error' |
| 1432 | else: |
| 1433 | type_str = 'type_error' |
| 1434 | |
| 1435 | # ctx is missing here, but since we've added `input` to the error, we're not pretending it's the same |
| 1436 | error: pydantic_core.InitErrorDetails = { |
| 1437 | # The type: ignore on the next line is to ignore the requirement of LiteralString |
| 1438 | 'type': pydantic_core.PydanticCustomError(type_str, str(exc)), # type: ignore |
| 1439 | 'loc': ('__root__',), |
| 1440 | 'input': b, |
| 1441 | } |
| 1442 | raise pydantic_core.ValidationError.from_exception_data(cls.__name__, [error]) |
| 1443 | return cls.model_validate(obj) |
| 1444 | |
| 1445 | @classmethod |
| 1446 | @typing_extensions.deprecated( |