# 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 InvalidDateTimeFormat(ValidationError):
#     """Error raised by `DateTimeFormat` validator"""
# 
#     def __init__(self, value, format, path):
#         """
#         Args:
#             value (str): invalid datetime string
#             format (str): format used to parse datetime
#             path (list): path of the invalid data
#         """
#         message = "Date value \"%s\" can't be parsed with format \"%s\"" % (value, format)
#         super(InvalidDateTimeFormat, self).__init__(message, path)
#         self.value = value
#         self.format = format


from datetime import datetime
from . import Validator
from ..errors import InvalidDateTimeFormat



class DateTimeFormat(Validator):
    """Validates date and datetimes format"""

    def __init__(self, format):
        """
        Args:
            format (str): datetime format
        """
        self._format = format

    def __call__(self, value, path):
        """Validate that value can be parsed as a date

        Args:
            value (str): datetime string to validate
            path (list): error path
        """
        try:
            datetime.strptime(value, self._format)
        except ValueError:

# 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 InvalidDateTimeFormat(ValidationError):
#     """Error raised by `DateTimeFormat` validator"""
# 
#     def __init__(self, value, format, path):
#         """
#         Args:
#             value (str): invalid datetime string
#             format (str): format used to parse datetime
#             path (list): path of the invalid data
#         """
#         message = "Date value \"%s\" can't be parsed with format \"%s\"" % (value, format)
#         super(InvalidDateTimeFormat, self).__init__(message, path)
#         self.value = value
#         self.format = format


# Path: src/lupin/validators/datetime_format.py
from datetime import datetime
from . import Validator
from ..errors import InvalidDateTimeFormat




class DateTimeFormat(Validator):
    """Validates date and datetimes format"""

    def __init__(self, format):
        """
        Args:
            format (str): datetime format
        """
        self._format = format

    def __call__(self, value, path):
        """Validate that value can be parsed as a date

        Args:
            value (str): datetime string to validate
            path (list): error path
        """
        try:
            datetime.strptime(value, self._format)
        except ValueError:

            raise InvalidDateTimeFormat(value, self._format, path)