def get_auth_dict(auth_string):
    """
    Splits WWW-Authenticate and HTTP_AUTHORIZATION strings
    into a dictionaries, e.g.
    {
        nonce  : "951abe58eddbb49c1ed77a3a5fb5fc2e"',
        opaque : "34de40e4f2e4f4eda2a3952fd2abab16"',
        realm  : "realm1"',
        qop    : "auth"'
    }
    """
    amap = {}
    for itm in auth_string.split(", "):
        (k, v) = [s.strip() for s in itm.split("=", 1)]
        amap[k] = v.replace('"', '')
    return amap