File: match.py

package info (click to toggle)
python-jsonpath 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,028 kB
  • sloc: python: 9,473; makefile: 6
file content (19 lines) | stat: -rw-r--r-- 573 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""The standard `match` function extension."""

from ._pattern import AbstractRegexFilterFunction


class Match(AbstractRegexFilterFunction):
    """The standard `match` function."""

    def __call__(self, value: object, pattern: object) -> bool:
        """Return `True` if _value_ matches _pattern_, or `False` otherwise."""
        if not isinstance(value, str) or not isinstance(pattern, str):
            return False

        _pattern = self.check_cache(pattern)

        if _pattern is None:
            return False

        return bool(_pattern.fullmatch(value))