'Inserts a new keyword+value card into the Header at a given location,
similar to `list.insert`.
Parameters
key : int, str, or tuple
The index into the list of header keywords before which the
new keyword should be inserted, or the name of a keyword before
which the new keyword should be inserted.  Can also accept a
(keyword, index) tuple for inserting around duplicate keywords.
card : str, tuple
A keyword or a (keyword, value, [comment]) tuple; see
`Header.append`
useblanks : bool, optional
If there are blank cards at the end of the Header, replace the
first blank card so that the total number of cards in the Header
does not increase.  Otherwise preserve the number of blank cards.
after : bool, optional
If set to `True`, insert *after* the specified index or keyword,
rather than before it.  Defaults to `False`.'

def insert(self, key, card, useblanks=True, after=False):

    if (not isinstance(key, int)):
        idx = self._cardindex(key)
    else:
        idx = key
    if after:
        if (idx == (-1)):
            idx = len(self._cards)
        else:
            idx += 1
    if (idx >= len(self._cards)):
        self.append(card, end=True)
        return
    if isinstance(card, string_types):
        card = Card(card)
    elif isinstance(card, tuple):
        card = Card(*card)
    elif (not isinstance(card, Card)):
        raise ValueError('The    value    inserted    into    a    Header    must    be    either    a    keyword    or    (keyword,    value,    [comment])    tuple;    got:    {!r}'.format(card))
    self._cards.insert(idx, card)
    keyword = card.keyword
    if (idx < 0):
        idx += (len(self._cards) - 1)
        if (idx < 0):
            idx = 0
    self._updateindices(idx)
    keyword = Card.normalize_keyword(keyword)
    self._keyword_indices[keyword].append(idx)
    count = len(self._keyword_indices[keyword])
    if (count > 1):
        if (keyword not in Card._commentary_keywords):
            warnings.warn('A    {!r}    keyword    already    exists    in    this    header.        Inserting    duplicate    keyword.'.format(keyword), AstropyUserWarning)
        self._keyword_indices[keyword].sort()
    if (card.field_specifier is not None):
        rvkc_indices = self._rvkc_indices[card.rawkeyword]
        rvkc_indices.append(idx)
        rvkc_indices.sort()
    if useblanks:
        self._useblanks((len(str(card)) // Card.length))
    self._modified = True
