def _get_cards(self, hdukey, keywords, compressed):
        """Returns a list of `pyfits.card.Card` objects.

        This function will return the desired header cards, taking into
        account the user's preference to see the compressed or uncompressed
        version.

        Parameters
        ----------
        hdukey : int or str
            Key of a single HDU in the HDUList.

        keywords : list of str, optional
            Keywords for which the cards should be returned.

        compressed : boolean, optional
            If True, shows the header describing the compression.

        Raises
        ------
        ExtensionNotFoundException
            If the hdukey does not correspond to an extension.
        """
        # First we obtain the desired header
        try:
            if compressed:
                # In the case of a compressed image, return the header before
                # decompression (not the default behavior)
                header = self._hdulist[hdukey]._header
            else:
                header = self._hdulist[hdukey].header
        except (__HOLE__, KeyError):
            message = '{0}: Extension {1} not found.'.format(self.filename,
                                                             hdukey)
            log.warning(message)
            raise ExtensionNotFoundException(message)

        if not keywords:  # return all cards
            cards = header.cards
        else:  # specific keywords are requested
            cards = []
            for kw in keywords:
                try:
                    crd = header.cards[kw]
                    if isinstance(crd, pyfits.card.Card):  # Single card
                        cards.append(crd)
                    else:  # Allow for wildcard access
                        cards.extend(crd)
                except KeyError as e:  # Keyword does not exist
                    log.warning('{filename} (HDU {hdukey}): '
                                'Keyword {kw} not found.'.format(
                                    filename=self.filename,
                                    hdukey=hdukey,
                                    kw=kw))
        return cards
dataset/ETHPy150Open spacetelescope/PyFITS/pyfits/scripts/fitsheader.py/HeaderFormatter._get_cards