1
0
Fork 0

Merging upstream version 4.1.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 20:05:49 +01:00
parent bd17f43dd7
commit 73dcfce521
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
14 changed files with 456 additions and 36 deletions

View file

@ -1,3 +1,4 @@
import ipaddress
import logging
import traceback
from collections import namedtuple
@ -166,6 +167,7 @@ class PGExecute:
host=None,
port=None,
dsn=None,
notify_callback=None,
**kwargs,
):
self._conn_params = {}
@ -178,6 +180,7 @@ class PGExecute:
self.port = None
self.server_version = None
self.extra_args = None
self.notify_callback = notify_callback
self.connect(database, user, password, host, port, dsn, **kwargs)
self.reset_expanded = None
@ -236,6 +239,9 @@ class PGExecute:
self.conn = conn
self.conn.autocommit = True
if self.notify_callback is not None:
self.conn.add_notify_handler(self.notify_callback)
# When we connect using a DSN, we don't really know what db,
# user, etc. we connected to. Let's read it.
# Note: moved this after setting autocommit because of #664.
@ -273,6 +279,11 @@ class PGExecute:
@property
def short_host(self):
try:
ipaddress.ip_address(self.host)
return self.host
except ValueError:
pass
if "," in self.host:
host, _, _ = self.host.partition(",")
else:
@ -431,7 +442,11 @@ class PGExecute:
def handle_notices(n):
nonlocal title
title = f"{n.message_primary}\n{n.message_detail}\n{title}"
title = f"{title}"
if n.message_primary is not None:
title = f"{title}\n{n.message_primary}"
if n.message_detail is not None:
title = f"{title}\n{n.message_detail}"
self.conn.add_notice_handler(handle_notices)