'Get the index of an HDU from the `HDUList`.
Parameters
key : int, str or tuple of (string, int)
The key identifying the HDU.  If ``key`` is a tuple, it is of the
form ``(key, ver)`` where ``ver`` is an ``EXTVER`` value that must
match the HDU being searched for.
If the key is ambiguous (e.g. there are multiple \'SCI\' extensions)
the first match is returned.  For a more precise match use the
``(name, ver)`` pair.
If even the ``(name, ver)`` pair is ambiguous (it shouldn\'t be
but it\'s not impossible) the numeric index must be used to index
the duplicate HDU.
Returns
index : int
The index of the HDU in the `HDUList`.'

def index_of(self, key):

    if _is_int(key):
        return key
    elif isinstance(key, tuple):
        (_key, _ver) = key
    else:
        _key = key
        _ver = None
    if (not isinstance(_key, string_types)):
        raise KeyError('{}    indices    must    be    integers,    extension    names    as    strings,    or    (extname,    version)    tuples;    got    {}'.format(self.__class__.__name__, _key))
    _key = _key.strip().upper()
    found = None
    for (idx, hdu) in enumerate(self):
        name = hdu.name
        if isinstance(name, string_types):
            name = name.strip().upper()
        if (((name == _key) or ((_key == 'PRIMARY') and (idx == 0))) and ((_ver is None) or (_ver == hdu.ver))):
            found = idx
            break
    if (found is None):
        raise KeyError('Extension    {!r}    not    found.'.format(key))
    else:
        return found
