def __new__(cls, index):
        """Acts as look-up routine after class is initialized.

        The purpose of overriding __new__ is to provide a way to treat
        Enum subclasses as casting types, similar to how the int type
        functions.  A program can pass a string or an integer and this
        method with "convert" that value in to an appropriate Enum instance.

        Args:
          index: Name or number to look up.  During initialization
            this is always the name of the new enum value.

        Raises:
          TypeError: When an inappropriate index value is passed provided.
        """
        # If is enum type of this class, return it.
        if isinstance(index, cls):
            return index

        # If number, look up by number.
        if isinstance(index, six.integer_types):
            try:
                return cls.lookup_by_number(index)
            except KeyError:
                pass

        # If name, look up by name.
        if isinstance(index, six.string_types):
            try:
                return cls.lookup_by_name(index)
            except KeyError:
                pass

        raise TypeError('No such value for %s in Enum %s' %
                        (index, cls.__name__))