|
12 | 12 | from c8y_api._base_api import CumulocityRestApi |
13 | 13 | from c8y_api.model.matcher import JsonMatcher |
14 | 14 | from c8y_api.model._util import _DateUtil, _StringUtil, _QueryUtil |
| 15 | + |
| 16 | +# trying to import various matchers that need external libraries |
15 | 17 | try: |
16 | | - from c8y_api.model.matcher import PydfMatcher |
| 18 | + from c8y_api.model.matcher import PydfMatcher as DefaultMatcher |
17 | 19 | except ImportError: |
18 | | - pass |
| 20 | + try: |
| 21 | + from c8y_api.model.matcher import JmesPathMatcher as DefaultMatcher |
| 22 | + except ImportError: |
| 23 | + try: |
| 24 | + from c8y_api.model.matcher import JsonPathMatcher as DefaultMatcher |
| 25 | + except ImportError: |
| 26 | + DefaultMatcher = None |
19 | 27 |
|
20 | 28 |
|
21 | 29 | def get_by_path(dictionary: dict, path: str, default: Any = None) -> Any: |
@@ -52,7 +60,7 @@ def get_all_by_path(dictionary: dict, paths: list[str] | dict[str, Any]) -> tupl |
52 | 60 |
|
53 | 61 | Return: |
54 | 62 | The extracted values (or defaults it specified) as tuple. The |
55 | | - number of elements in the tuple matches the length of the paths |
| 63 | + number of elements in the tuple matches the length of the `paths` |
56 | 64 | argument. |
57 | 65 | """ |
58 | 66 | if isinstance(paths, dict): |
@@ -639,7 +647,7 @@ def __init__(self, c8y: CumulocityRestApi, resource: str): |
639 | 647 | # the last event for e.g. /event/events |
640 | 648 | self.object_name = self.resource.split('/')[-1] |
641 | 649 | # the default JSON matcher for client-side filtering |
642 | | - self.default_matcher = PydfMatcher |
| 650 | + self.default_matcher = DefaultMatcher |
643 | 651 |
|
644 | 652 | def build_object_path(self, object_id: int | str) -> str: |
645 | 653 | """Build the path to a specific object of this resource. |
@@ -801,8 +809,12 @@ def _iterate( |
801 | 809 | num_results = 0 |
802 | 810 | # compile/prepare filter if defined |
803 | 811 | if isinstance(include, str): |
| 812 | + if not self.default_matcher: |
| 813 | + raise ValueError("No default matcher defined (client-side filtering not supported?)") |
804 | 814 | include = self.default_matcher(include) |
805 | 815 | if isinstance(exclude, str): |
| 816 | + if not self.default_matcher: |
| 817 | + raise ValueError("No default matcher defined (client-side filtering not supported?)") |
806 | 818 | exclude = self.default_matcher(exclude) |
807 | 819 |
|
808 | 820 | while True: |
|
0 commit comments