'Update the Header with new keyword values, updating the values of
existing keywords and appending new keywords otherwise; similar to
`dict.update`.
`update` accepts either a dict-like object or an iterable.  In the
former case the keys must be header keywords and the values may be
either scalar values or (value, comment) tuples.  In the case of an
iterable the items must be (keyword, value) tuples or (keyword, value,
comment) tuples.
Arbitrary arguments are also accepted, in which case the update() is
called again with the kwargs dict as its only argument.  That is,
>>> header.update(NAXIS1=100, NAXIS2=100)
is equivalent to::
header.update({\'NAXIS1\': 100, \'NAXIS2\': 100})
.. warning::
As this method works similarly to `dict.update` it is very
different from the ``Header.update()`` method in PyFITS versions
prior to 3.1.0 (or Astropy v0.1). Use of the old API was
**deprecated** for a long time and is now removed. Most uses of the
old API can be replaced as follows:
* Replace ::
header.update(keyword, value)
with ::
header[keyword] = value
* Replace ::
header.update(keyword, value, comment=comment)
with ::
header[keyword] = (value, comment)
* Replace ::
header.update(keyword, value, before=before_keyword)
with ::
header.insert(before_keyword, (keyword, value))
* Replace ::
header.update(keyword, value, after=after_keyword)
with ::
header.insert(after_keyword, (keyword, value),
after=True)
See also :meth:`Header.set` which is a new method that provides an
interface similar to the old ``Header.update()`` and may help make
transition a little easier.'

def update(self, *args, **kwargs):

    if args:
        other = args[0]
    else:
        other = None
    def update_from_dict(k, v):
        if (not isinstance(v, tuple)):
            card = Card(k, v)
        elif (0 < len(v) <= 2):
            card = Card(*((k,) + v))
        else:
            raise ValueError(('Header    update    value    for    key    %r    is    invalid;    the    value    must    be    either    a    scalar,    a    1-tuple    containing    the    scalar    value,    or    a    2-tuple    containing    the    value    and    a    comment    string.' % k))
        self._update(card)
    if (other is None):
        pass
    elif hasattr(other, 'items'):
        for (k, v) in iteritems(other):
            update_from_dict(k, v)
    elif hasattr(other, 'keys'):
        for k in other.keys():
            update_from_dict(k, other[k])
    else:
        for (idx, card) in enumerate(other):
            if isinstance(card, Card):
                self._update(card)
            elif (isinstance(card, tuple) and (1 < len(card) <= 3)):
                self._update(Card(*card))
            else:
                raise ValueError('Header    update    sequence    item    #{}    is    invalid;    the    item    must    either    be    a    2-tuple    containing    a    keyword    and    value,    or    a    3-tuple    containing    a    keyword,    value,    and    comment    string.'.format(idx))
    if kwargs:
        self.update(kwargs)
