|
10 | 10 | import demistomock as demisto # noqa: F401
|
11 | 11 | from CommonServerPython import * # noqa: F401
|
12 | 12 |
|
13 |
| -PATALG_BINARY = 0 |
| 13 | +PATALG_BINARY: int = 0 |
14 | 14 | PATALG_WILDCARD: int = 1
|
15 |
| -PATALG_REGEX = 2 |
| 15 | +PATALG_REGEX: int = 2 |
16 | 16 |
|
17 |
| -ITERATE_NODE = 0 |
18 |
| -ITERATE_VALUE = 1 |
19 |
| -ITERATE_KEY = 2 |
| 17 | +ITERATE_NODE: int = 0 |
| 18 | +ITERATE_VALUE: int = 1 |
| 19 | +ITERATE_KEY: int = 2 |
20 | 20 |
|
21 | 21 |
|
22 | 22 | class Value:
|
@@ -76,14 +76,15 @@ def set(node: Dict[str, Any], path: str, value: Any):
|
76 | 76 | @staticmethod
|
77 | 77 | def get_value(node: Dict[str, Any], path: str) -> Optional[Value]:
|
78 | 78 | val = None
|
| 79 | + key = None |
79 | 80 | comps = path.split('.')
|
80 | 81 | while comps:
|
81 | 82 | res = Ddict.__search(node if val is None else val, comps)
|
82 | 83 | if res is None:
|
83 | 84 | return None
|
84 |
| - _, val, comps = res |
| 85 | + key, val, comps = res |
85 | 86 |
|
86 |
| - return None if val is None else Value(val) |
| 87 | + return None if key is None else Value(val) |
87 | 88 |
|
88 | 89 | @staticmethod
|
89 | 90 | def get(node: Dict[str, Any], path: str) -> Any:
|
@@ -873,11 +874,17 @@ def filter_with_expressions(self,
|
873 | 874 |
|
874 | 875 | for x in self.__conds_items(conds, root):
|
875 | 876 | coptype, cconds = x
|
876 |
| - child = self.filter_value( |
877 |
| - child, coptype, cconds, None, inlist and parent is None) |
878 |
| - if not child: |
879 |
| - return None |
880 |
| - child = child.value |
| 877 | + |
| 878 | + if coptype in ("is", "isn't") and \ |
| 879 | + isinstance(cconds, str) and cconds == "existing key": |
| 880 | + if (coptype == "is") != bool(path and Ddict.get_value(root, path)): |
| 881 | + return None |
| 882 | + else: |
| 883 | + child = self.filter_value( |
| 884 | + child, coptype, cconds, None, inlist and parent is None) |
| 885 | + if not child: |
| 886 | + return None |
| 887 | + child = child.value |
881 | 888 |
|
882 | 889 | if parent:
|
883 | 890 | if isinstance(parent, dict):
|
@@ -1118,15 +1125,11 @@ def filter_value(
|
1118 | 1125 | if not inlist and isinstance(root, list):
|
1119 | 1126 | return self.filter_values(root, optype, conds, path)
|
1120 | 1127 |
|
1121 |
| - filstr = conds |
1122 |
| - if isinstance(filstr, str) and filstr == "existing key": |
1123 |
| - if optype == "is": |
1124 |
| - if path and Ddict.get_value(root, path): |
1125 |
| - return Value(root) |
1126 |
| - else: # isn't |
1127 |
| - if not path or not Ddict.get_value(root, path): |
1128 |
| - return Value(root) |
| 1128 | + if isinstance(conds, str) and conds == "existing key": |
| 1129 | + if (optype == "is") == bool(path and Ddict.get_value(root, path)): |
| 1130 | + return Value(root) |
1129 | 1131 | return None
|
| 1132 | + |
1130 | 1133 | if path:
|
1131 | 1134 | if not inlist and isinstance(root, list):
|
1132 | 1135 | return self.filter_values(root, optype, conds, path)
|
@@ -1718,7 +1721,11 @@ def parse_conds_json(
|
1718 | 1721 | """
|
1719 | 1722 | if only_parse_for_string and not isinstance(jstr, str):
|
1720 | 1723 | return jstr
|
1721 |
| - return json.loads(jstr) |
| 1724 | + |
| 1725 | + try: |
| 1726 | + return json.loads(jstr) |
| 1727 | + except json.JSONDecodeError: |
| 1728 | + return jstr |
1722 | 1729 |
|
1723 | 1730 | def parse_and_extract_conds_json(
|
1724 | 1731 | self,
|
|
0 commit comments