(cstr)
return res
r"""Parse Postgres connect string.

    >>> parse_connect_string("host=foo")
    [('host', 'foo')]
    >>> parse_connect_string(r" host = foo password = ' f\\\o\'o ' ")
    [('host', 'foo'), ('password', "' f\\o'o '")]
r"""Parse Postgres connect string.
r Parse Postgres connect string .
def parse_connect_string(cstr):
    r"""Parse Postgres connect string.

    >>> parse_connect_string("host=foo")
    [('host', 'foo')]
    >>> parse_connect_string(r" host = foo password = ' f\\\o\'o ' ")
    [('host', 'foo'), ('password', "' f\\o'o '")]
    """
    global _cstr_rc, _cstr_unesc_rc
    if not _cstr_rc:
        _cstr_rc = re.compile(_cstr_rx, re.X)
        _cstr_unesc_rc = re.compile(_cstr_unesc_rx)
    pos = 0
    res = []
    while pos < len(cstr):
        m = _cstr_rc.match(cstr, pos)
        if not m:
            raise ValueError('Invalid connect string')
        pos = m.end()
        k = m.group(1)
        v = m.group(2)
        if v[0] == "'":
            v = _cstr_unesc_rc.sub(r"\1", v)
        res.append( (k,v) )
    return res
def parse_connect_string ( cstr ) : global _cstr_rc , _cstr_unesc_rc if not _cstr_rc : _cstr_rc = re . compile ( _cstr_rx , re . X ) _cstr_unesc_rc = re . compile ( _cstr_unesc_rx ) pos = 0 res = [ ] while pos < len ( cstr ) : m = _cstr_rc . match ( cstr , pos ) if not m : raise ValueError ( 'Invalid connect string' ) pos = m . end ( ) k = m . group ( 1 ) v = m . group ( 2 ) if v [ 0 ] == "'" : v = _cstr_unesc_rc . sub ( r"\1" , v ) res . append ( ( k , v ) ) return res