@classmethod
def coerce(cls, val):
    """
        Return the desired enum object or throw an error, the enum object will
        be searched based on its name or value.

        :param val: the value or name of the desired enum
        :return: the enum object
        """
    try:
        return cls[val]
    except KeyError:
        try:
            return cls(val)
        except ValueError:
            msg = (
                '"{0}" not a valid enum value or name of {1}, possible names are {2} and possible values are {3}.'
                )
            raise ValueError(msg.format(val, cls.__name__, ','.join(cls.
                get_names()), str(cls.get_values())))
