def getdefault(doc, key, default):
    """Return the value in 'doc' with key 'key' if present and not None.

    Return the specified default value otherwise.
    """
    value = doc.get(key)
    if value is not None:
        return value
    return default