|
6 | 6 | from abc import ABC |
7 | 7 | from abc import abstractmethod |
8 | 8 | from io import IOBase |
9 | | -from typing import Any |
10 | 9 | from typing import Dict |
11 | 10 | from typing import Iterable |
12 | 11 | from typing import List |
13 | 12 | from typing import Mapping |
14 | 13 | from typing import MutableMapping |
15 | 14 | from typing import MutableSequence |
16 | | -from typing import Sequence |
17 | 15 | from typing import TypeVar |
18 | 16 | from typing import Union |
19 | 17 |
|
20 | | -from .exceptions import JSONPatchError |
21 | | -from .exceptions import JSONPatchTestFailure |
22 | | -from .exceptions import JSONPointerError |
23 | | -from .exceptions import JSONPointerIndexError |
24 | | -from .exceptions import JSONPointerKeyError |
25 | | -from .exceptions import JSONPointerTypeError |
26 | | -from .pointer import UNDEFINED |
27 | | -from .pointer import JSONPointer |
| 18 | +from jsonpath._data import load_data |
| 19 | +from jsonpath.exceptions import JSONPatchError |
| 20 | +from jsonpath.exceptions import JSONPatchTestFailure |
| 21 | +from jsonpath.exceptions import JSONPointerError |
| 22 | +from jsonpath.exceptions import JSONPointerIndexError |
| 23 | +from jsonpath.exceptions import JSONPointerKeyError |
| 24 | +from jsonpath.exceptions import JSONPointerTypeError |
| 25 | +from jsonpath.pointer import UNDEFINED |
| 26 | +from jsonpath.pointer import JSONPointer |
28 | 27 |
|
29 | 28 |
|
30 | 29 | class Op(ABC): |
@@ -537,7 +536,7 @@ def apply( |
537 | 536 | JSONPatchTestFailure: When a _test_ operation does not pass. |
538 | 537 | `JSONPatchTestFailure` is a subclass of `JSONPatchError`. |
539 | 538 | """ |
540 | | - _data = _load_data(data) |
| 539 | + _data = load_data(data) |
541 | 540 |
|
542 | 541 | for i, op in enumerate(self.ops): |
543 | 542 | try: |
@@ -598,18 +597,3 @@ def apply( |
598 | 597 | unicode_escape=unicode_escape, |
599 | 598 | uri_decode=uri_decode, |
600 | 599 | ).apply(data) |
601 | | - |
602 | | - |
603 | | -def _load_data( |
604 | | - data: Union[int, str, IOBase, Sequence[Any], MutableMapping[str, Any]] |
605 | | -) -> Any: |
606 | | - if isinstance(data, str): |
607 | | - try: |
608 | | - return json.loads(data) |
609 | | - except json.JSONDecodeError: |
610 | | - data = data.strip() |
611 | | - if data.startswith('"') and data.endswith('"'): |
612 | | - return data |
613 | | - if isinstance(data, IOBase): |
614 | | - return json.loads(data.read()) |
615 | | - return data |
0 commit comments