# 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 InvalidLength(ValidationError):
#     """Error raised by `Length` validator"""
# 
#     def __init__(self, length, min, max, path):
#         """
#         Args:
#             length (int): received length
#             min (int): minimum length
#             max (int): maximum length
#             path (list): path of the invalid data
#         """
#         message = "Got %s items, should have been between %s and %s" % (length, min, max)
#         super(InvalidLength, self).__init__(message, path)
#         self.max = max
#         self.min = min
#         self.length = length


from . import Validator
from ..errors import InvalidLength


class Length(Validator):
    """Validates the size of value"""

    def __init__(self, min=None, max=None):
        """
        Args:
            min (int): minimum length
            max (int): maximum length
        """
        self._min = min
        self._max = max

    def __call__(self, value, path):
        """Validate that value is contained in the expected ones

        Args:
            value (object): value to validate
            path (list): error path
        """
        try:
            length = len(value)
        except TypeError:

# 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 InvalidLength(ValidationError):
#     """Error raised by `Length` validator"""
# 
#     def __init__(self, length, min, max, path):
#         """
#         Args:
#             length (int): received length
#             min (int): minimum length
#             max (int): maximum length
#             path (list): path of the invalid data
#         """
#         message = "Got %s items, should have been between %s and %s" % (length, min, max)
#         super(InvalidLength, self).__init__(message, path)
#         self.max = max
#         self.min = min
#         self.length = length


# Path: src/lupin/validators/length.py
from . import Validator
from ..errors import InvalidLength



class Length(Validator):
    """Validates the size of value"""

    def __init__(self, min=None, max=None):
        """
        Args:
            min (int): minimum length
            max (int): maximum length
        """
        self._min = min
        self._max = max

    def __call__(self, value, path):
        """Validate that value is contained in the expected ones

        Args:
            value (object): value to validate
            path (list): error path
        """
        try:
            length = len(value)
        except TypeError:

            raise InvalidLength(None, self._min, self._max, path)