diff --git a/py_opengauss/driver/dbapi20.py b/py_opengauss/driver/dbapi20.py index aa8c88c5c9f4de847f0236b215e2359655258e84..1c425accdde14f2a3ffc4709f00af777f40b7d25 100644 --- a/py_opengauss/driver/dbapi20.py +++ b/py_opengauss/driver/dbapi20.py @@ -434,10 +434,11 @@ def connect(**kw): for addr in addrs: param = deepcopy(kw) if ":" in addr: - host, str_port = addr.strip().split(':') - port = int(str_port) - param['host'] = host - param['port'] = port + parts = addr.strip().rsplit(":", 1) + host, str_port = parts + port = int(str_port) + param['host'] = host + param['port'] = port else: param['host'] = addr kws.append(param) diff --git a/py_opengauss/resolved/riparse.py b/py_opengauss/resolved/riparse.py index 0c205d3f331752425f3c93443ee4529cf24ff8b3..c3ca0eb16b717f221a4c29e4d38b73328fdccb22 100644 --- a/py_opengauss/resolved/riparse.py +++ b/py_opengauss/resolved/riparse.py @@ -225,28 +225,28 @@ def unsplit(t): return s def split_ip(ip, fieldproc = unescape): - if ip[0] == '[': - # IPvN addr - next_pos = ip.find(']') - if next_pos == -1: - # unterminated IPvN block - next_pos = len(ip) - 1 - addr = ip[:next_pos + 1] - pos = next_pos + 1 - next_pos = addr.find(':', pos) - if next_pos == -1: - port = None - else: - port = fieldproc(addr[next_pos + 1:]) - else: - next_pos = ip.find(':') - if next_pos == -1: - addr = fieldproc(ip) - port = None - else: - addr = fieldproc(ip[:next_pos]) - port = fieldproc(ip[next_pos + 1:]) - return addr, port + if ip[0] == '[': + # IPvN addr + next_pos = ip.find(']') + if next_pos == -1: + # unterminated IPvN block + next_pos = len(ip) - 1 + addr = ip[:next_pos + 1] + pos = next_pos + 1 + next_pos = ip.find(':', pos) + if next_pos == -1: + port = None + else: + port = fieldproc(ip[next_pos + 1:]) + else: + next_pos = ip.rfind(':') + if next_pos == -1: + addr = fieldproc(ip) + port = None + else: + addr = fieldproc(ip[:next_pos]) + port = fieldproc(ip[next_pos + 1:]) + return addr, port def split_netloc(netloc, fieldproc = unescape): """