# Path: src/lupin/validators/validator.py
# class Validator(object):
#     """Validators base class"""
# 
#     def __and__(self, other):
#         """Combine current validator with another one using the & operator
# 
#         Returns:
#             ValidatorsAndCombination
#         """
#         return lupin.ValidatorsAndCombination([self, other])
# 
#     def __or__(self, other):
#         """Combine current validator with another one using the | operator
# 
#         Returns:
#             ValidatorsOrCombination
#         """
#         return lupin.ValidatorsOrCombination([self, other])
# 
# Path: src/lupin/errors.py
# class InvalidMatch(ValidationError):
#     """Error raised by `Match` validator"""
# 
#     def __init__(self, invalid, regexp, path):
#         """
#         Args:
#             invalid (str): invalid value
#             regexp (regexp): a regexp
#             path (list): path of the invalid data
#         """
#         message = "Value \"%s\" does not match pattern \"%s\"" % (invalid, regexp.pattern)
#         super(InvalidMatch, self).__init__(message, path)
#         self.invalid = invalid
#         self.regexp = regexp


from . import Validator
from ..errors import InvalidMatch


class Match(Validator):
    """Validate that a string matches a pattern"""

    def __init__(self, regex):
        """
        Args:
            regex (regex): a regexp object
        """
        self._regex = regex

    def __call__(self, value, path):
        """Validate that value matches the regex

        Args:
            value (str): string to validate
            path (list): error path
        """
        try:
            if not self._regex.match(value):

# Path: src/lupin/validators/validator.py
# class Validator(object):
#     """Validators base class"""
# 
#     def __and__(self, other):
#         """Combine current validator with another one using the & operator
# 
#         Returns:
#             ValidatorsAndCombination
#         """
#         return lupin.ValidatorsAndCombination([self, other])
# 
#     def __or__(self, other):
#         """Combine current validator with another one using the | operator
# 
#         Returns:
#             ValidatorsOrCombination
#         """
#         return lupin.ValidatorsOrCombination([self, other])
# 
# Path: src/lupin/errors.py
# class InvalidMatch(ValidationError):
#     """Error raised by `Match` validator"""
# 
#     def __init__(self, invalid, regexp, path):
#         """
#         Args:
#             invalid (str): invalid value
#             regexp (regexp): a regexp
#             path (list): path of the invalid data
#         """
#         message = "Value \"%s\" does not match pattern \"%s\"" % (invalid, regexp.pattern)
#         super(InvalidMatch, self).__init__(message, path)
#         self.invalid = invalid
#         self.regexp = regexp


# Path: src/lupin/validators/match.py
from . import Validator
from ..errors import InvalidMatch



class Match(Validator):
    """Validate that a string matches a pattern"""

    def __init__(self, regex):
        """
        Args:
            regex (regex): a regexp object
        """
        self._regex = regex

    def __call__(self, value, path):
        """Validate that value matches the regex

        Args:
            value (str): string to validate
            path (list): error path
        """
        try:
            if not self._regex.match(value):

                raise InvalidMatch(value, self._regex, path)