def _conninfo_uri_parse(dsn: str) -> Dict[str, str]:
    """
    >>> r = _conninfo_uri_parse('postgresql://u%2Fse:pass@:%2f123/db%2Fsdf?application_name=mya%2Fpp&ssl=true')
    >>> r == {'application_name': 'mya/pp', 'dbname': 'db/sdf', 'sslmode': 'require',\
              'password': 'pass', 'port': '/123', 'user': 'u/se'}
    True
    >>> r = _conninfo_uri_parse('postgresql://u%2Fse:pass@[::1]/db%2Fsdf?application_name=mya%2Fpp&ssl=true')
    >>> r == {'application_name': 'mya/pp', 'dbname': 'db/sdf', 'host': '::1', 'sslmode': 'require',\
              'password': 'pass', 'user': 'u/se'}
    True
    """
    ret: Dict[str, str] = {}
    r = urlparse(dsn)
    if r.username:
        ret['user'] = r.username
    if r.password:
        ret['password'] = r.password
    if r.path[1:]:
        ret['dbname'] = r.path[1:]
    hosts: List[str] = []
    ports: List[str] = []
    for netloc in r.netloc.split('@')[-1].split(','):
        host = None
        if '[' in netloc and ']' in netloc:
            tmp = netloc.split(']') + ['']
            host = tmp[0][1:]
            netloc = ':'.join(tmp[:2])
        tmp = netloc.rsplit(':', 1)
        if host is None:
            host = tmp[0]
        hosts.append(host)
        ports.append(tmp[1] if len(tmp) == 2 else '')
    if any(map(len, hosts)):
        ret['host'] = ','.join(hosts)
    if any(map(len, ports)):
        ret['port'] = ','.join(ports)
    ret = {name: unquote(value) for name, value in ret.items()}
    ret.update({name: value for name, value in parse_qsl(r.query)})
    if ret.get('ssl') == 'true':
        del ret['ssl']
        ret['sslmode'] = 'require'
    return ret

    >>> r = _conninfo_uri_parse('postgresql://u%2Fse:pass@:%2f123/db%2Fsdf?application_name=mya%2Fpp&ssl=true')
    >>> r == {'application_name': 'mya/pp', 'dbname': 'db/sdf', 'sslmode': 'require',              'password': 'pass', 'port': '/123', 'user': 'u/se'}
    True
    >>> r = _conninfo_uri_parse('postgresql://u%2Fse:pass@[::1]/db%2Fsdf?application_name=mya%2Fpp&ssl=true')
    >>> r == {'application_name': 'mya/pp', 'dbname': 'db/sdf', 'host': '::1', 'sslmode': 'require',              'password': 'pass', 'user': 'u/se'}
    True
    
patroni/postgresql/config.py