Return the item of an enumeration that corresponds to the specified
    string representation.

    @param value: string representation of an item of a Python
        enumeration.

    @param enumeration: a Python enumeration.

    @param strict: indicate whether the value must correspond to an
        item of the specified Python enumeration or if ``None`` value is
        accepted.

    @return: the item of the Python enumeration the specified string
        representation corresponds to.

    @raise ValueError: if the enumeration is not an instance of
        ``Enum``, or if the string representation doesn't correspond
        to any item of the given Python enumeration, or if the default
        value is not an item of the given Python enumeration.

def string_to_enum(value, enumeration, strict=True, default_value=None):
    """
    Return the item of an enumeration that corresponds to the specified
    string representation.

    @param value: string representation of an item of a Python
        enumeration.

    @param enumeration: a Python enumeration.

    @param strict: indicate whether the value must correspond to an
        item of the specified Python enumeration or if ``None`` value is
        accepted.

    @return: the item of the Python enumeration the specified string
        representation corresponds to.

    @raise ValueError: if the enumeration is not an instance of
        ``Enum``, or if the string representation doesn't correspond
        to any item of the given Python enumeration, or if the default
        value is not an item of the given Python enumeration.
    """
    if not isinstance(enumeration, Enum):
        raise ValueError('The specified enumeration is not an instance of Enum')

    if is_undefined(value):
        if strict:
            raise ValueError('The value cannot be null')

        if default_value is not None and not default_value in enumeration:
            raise ValueError('The default value must be an item of the specified enumeration')

        return default_value

    item = [ item for item in enumeration if str(item) == value]
    if len(item) == 0:
        raise ValueError('The specified string "%s" does not represent any item of the enumeration' % value)

    return item[0]