def parse_pair(v, default=(None, None)):
    """
    Expand a scalar or 2-tuple into a 2-tuple

    If any element of that is None, the corresponding value from default
    is substituted.
    """
    try:
        v = tuple(v)
    except TypeError:
        v = (v, v)
    return (default[0] if v[0] is None else v[0],
            default[1] if v[1] is None else v[1])