(doc, key)
| 78 | |
| 79 | |
| 80 | def get_value(doc, key): |
| 81 | if not key: |
| 82 | raise ValueError("key is None or empty: '{}'".format(key)) |
| 83 | |
| 84 | if not isinstance(doc, dict): |
| 85 | raise ValueError( |
| 86 | "doc is not an instance of dict: type={} value='{}'".format(type(doc), doc) |
| 87 | ) |
| 88 | # jsonpath_rw can be very slow when processing expressions. |
| 89 | # In the case of a simple expression we've created a "fast path" that avoids |
| 90 | # the complexity introduced by running jsonpath_rw code. |
| 91 | # For more complex expressions we fall back to using jsonpath_rw. |
| 92 | # This provides flexibility and increases performance in the base case. |
| 93 | match = SIMPLE_EXPRESSION_REGEX_CMPL.match(key) |
| 94 | if match: |
| 95 | return _get_value_simple(doc, key) |
| 96 | else: |
| 97 | return _get_value_complex(doc, key) |
| 98 | |
| 99 | |
| 100 | def get_kvps(doc, keys): |
no test coverage detected