-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstarts_with.py
More file actions
21 lines (15 loc) · 676 Bytes
/
starts_with.py
File metadata and controls
21 lines (15 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""The `startswith` function extension."""
from jsonpath.function_extensions import ExpressionType
from jsonpath.function_extensions import FilterFunction
class StartsWith(FilterFunction):
"""The `startswith` function extension."""
arg_types = [ExpressionType.VALUE, ExpressionType.VALUE]
return_type = ExpressionType.LOGICAL
def __call__(self, value: object, prefix: object) -> bool:
"""Return `True` if `value` starts with `prefix`."""
if not isinstance(value, str) or not isinstance(prefix, str):
return False
try:
return value.startswith(prefix)
except AttributeError:
return False