def quote_dsn_param(s, _special=" \\'"):
    """Apply the escaping rule required by PQconnectdb."""
    if not s:
        return "''"
    for char in _special:
        if char in s:
            return "'%s'" % s.replace('\\', '\\\\').replace("'", "\\'")
    return s
