Overlay one configuration over another.

    This overlays `overlay` on top of `base` as follows:

    * If either isn't a dictionary, returns `overlay`.
    * Any key in `base` not present in `overlay` is present in the
      result with its original value.
    * Any key in `overlay` with value :const:`None` is not present in
      the result, unless it also is :const:`None` in `base`.
    * Any key in `overlay` not present in `base` and not :const:`None`
      is present in the result with its new value.
    * Any key in both `overlay` and `base` with a non-:const:`None` value
      is recursively overlaid.

    >>> overlay_config({'a': 'b'}, {'a': 'c'})
    {'a': 'c'}
    >>> overlay_config({'a': 'b'}, {'c': 'd'})
    {'a': 'b', 'c': 'd'}
    >>> overlay_config({'a': {'b': 'c'}},
    ...                {'a': {'b': 'd', 'e': 'f'}})
    {'a': {'b': 'd', 'e': 'f'}}
    >>> overlay_config({'a': 'b', 'c': 'd'}, {'a': None})
    {'c': 'd'}

    :param dict base: original configuration
    :param dict overlay: overlay configuration
    :return: new overlaid configuration
    :returntype dict:

def overlay_config(base, overlay):
    '''Overlay one configuration over another.

    This overlays `overlay` on top of `base` as follows:

    * If either isn't a dictionary, returns `overlay`.
    * Any key in `base` not present in `overlay` is present in the
      result with its original value.
    * Any key in `overlay` with value :const:`None` is not present in
      the result, unless it also is :const:`None` in `base`.
    * Any key in `overlay` not present in `base` and not :const:`None`
      is present in the result with its new value.
    * Any key in both `overlay` and `base` with a non-:const:`None` value
      is recursively overlaid.

    >>> overlay_config({'a': 'b'}, {'a': 'c'})
    {'a': 'c'}
    >>> overlay_config({'a': 'b'}, {'c': 'd'})
    {'a': 'b', 'c': 'd'}
    >>> overlay_config({'a': {'b': 'c'}},
    ...                {'a': {'b': 'd', 'e': 'f'}})
    {'a': {'b': 'd', 'e': 'f'}}
    >>> overlay_config({'a': 'b', 'c': 'd'}, {'a': None})
    {'c': 'd'}

    :param dict base: original configuration
    :param dict overlay: overlay configuration
    :return: new overlaid configuration
    :returntype dict:

    '''
    if not isinstance(base, collections.Mapping):
        return overlay
    if not isinstance(overlay, collections.Mapping):
        return overlay
    result = dict()
    for k in iterkeys(base):
        if k not in overlay:
            result[k] = base[k]
    for k, v in iteritems(overlay):
        if v is not None or (k in base and base[k] is None):
            if k in base:
                v = overlay_config(base[k], v)
            result[k] = v
    return result