'Get an HDU from the `HDUList`, indexed by number or name.'

def __getitem__(self, key):

    if isinstance(key, slice):
        max_idx = key.stop
        if ((max_idx == sys.maxsize) or (max_idx is None)):
            max_idx = len(self)
        max_idx = self._positive_index_of(max_idx)
        number_loaded = super(HDUList, self).__len__()
        if (max_idx >= number_loaded):
            for i in range(number_loaded, max_idx):
                if (not self._read_next_hdu()):
                    break
        try:
            hdus = super(HDUList, self).__getitem__(key)
        except IndexError as e:
            if self._read_all:
                raise e
            else:
                raise IndexError('HDU    not    found,    possibly    because    the    index    is    out    of    range,    or    because    the    file    was    closed    before    all    HDUs    were    read')
        else:
            return HDUList(hdus)
    try:
        return self._try_while_unread_hdus(super(HDUList, self).__getitem__, self._positive_index_of(key))
    except IndexError as e:
        if self._read_all:
            raise e
        else:
            raise IndexError('HDU    not    found,    possibly    because    the    index    is    out    of    range,    or    because    the    file    was    closed    before    all    HDUs    were    read')
