# Path: select_multiple_field/codecs.py
# def encode_list_to_csv(decoded):
#     """
#     Encodes a Python list to a delimiter separated string
# 
#     Note: This sorts the list lexicographically
#     """
#     delimiter = getattr(
#         settings, 'SELECTMULTIPLEFIELD_DELIMITER', DEFAULT_DELIMITER)
#     decoded = sorted(set(decoded))
#     return delimiter.join(decoded)


from django.core import validators
from django.utils.encoding import force_text
from django.utils.translation import ungettext_lazy
    from django.utils.deconstruct import deconstructible
from .codecs import encode_list_to_csv

@deconstructible
class MaxChoicesValidator(validators.BaseValidator):

    message = ungettext_lazy(
        'Ensure this value has at most %(limit_value)d choice (it has %(show_value)d).',  # NOQA
        'Ensure this value has at most %(limit_value)d choices (it has %(show_value)d).',  # NOQA
        'limit_value')
    code = 'max_choices'

    def compare(self, a, b):
        return a > b

    def clean(self, x):
        return len(x)


@deconstructible
class MaxLengthValidator(validators.BaseValidator):

    message = ungettext_lazy(
        'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).',  # NOQA
        'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).',  # NOQA
        'limit_value')
    code = 'max_length'

    def compare(self, a, b):
        return a > b

    def clean(self, value):

# Path: select_multiple_field/codecs.py
# def encode_list_to_csv(decoded):
#     """
#     Encodes a Python list to a delimiter separated string
# 
#     Note: This sorts the list lexicographically
#     """
#     delimiter = getattr(
#         settings, 'SELECTMULTIPLEFIELD_DELIMITER', DEFAULT_DELIMITER)
#     decoded = sorted(set(decoded))
#     return delimiter.join(decoded)


# Path: select_multiple_field/validators.py
from django.core import validators
from django.utils.encoding import force_text
from django.utils.translation import ungettext_lazy
    from django.utils.deconstruct import deconstructible
from .codecs import encode_list_to_csv


@deconstructible
class MaxChoicesValidator(validators.BaseValidator):

    message = ungettext_lazy(
        'Ensure this value has at most %(limit_value)d choice (it has %(show_value)d).',  # NOQA
        'Ensure this value has at most %(limit_value)d choices (it has %(show_value)d).',  # NOQA
        'limit_value')
    code = 'max_choices'

    def compare(self, a, b):
        return a > b

    def clean(self, x):
        return len(x)


@deconstructible
class MaxLengthValidator(validators.BaseValidator):

    message = ungettext_lazy(
        'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).',  # NOQA
        'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).',  # NOQA
        'limit_value')
    code = 'max_length'

    def compare(self, a, b):
        return a > b

    def clean(self, value):

        return len(force_text(encode_list_to_csv(value)))