Skip to content

Commit ec7d145

Browse files
author
James William Pye
committed
Split pq3.Connector into addressing specific subclasses.
Additionally: - Isolate Database specific APIs from Connection APIs. (pg_api.Connection inherits from pg_api.Database) - Correct ife_snapshot_text for many classes. - Remove __getitem__ method from Cursor APIs. - Rewrite pq3.Connection.connect . Loop over SocketCreator's that are created by the Connector . Use the ClientCannotConnectError when unable to connect for any reason; The specific cause is included in a `connection_failures` attribute on the exception instance. . Properly, perhaps, support the sslmode parameter. - Remove references to `long` from typio. - Add an attribute_map method to TypeIO for client_encoding dependent decoding of TupleDescriptor's `attribute_map` property. The connector split resulted in a nice cleanup of the code. It also helped substantiate `Driver`'s existence due to selectivity methods on the driver implementation.
1 parent 8cb6673 commit ec7d145

9 files changed

Lines changed: 1204 additions & 626 deletions

File tree

postgresql/api.py

Lines changed: 383 additions & 133 deletions
Large diffs are not rendered by default.

postgresql/cluster.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,21 @@ def ready_for_connections(self):
261261
addrs = d['listen_addresses'].split(',')
262262
if 'localhost' in addrs or '*' in addrs:
263263
host = 'localhost'
264+
ipv = None
264265
elif '127.0.0.1' in addrs:
265266
host = '127.0.0.1'
267+
ipv = 4
266268
elif '::1' in addrs:
267269
host = '::1'
270+
ipv = 6
268271

269272
try:
270273
pg_driver.connect(
271274
user = 'ping',
272275
host = host,
273276
port = int(d.get('port') or 5432),
274277
database = 'template1',
278+
ipv = ipv,
275279
).close()
276280
except pg_exc.CannotConnectNowError:
277281
return False
@@ -299,11 +303,7 @@ def wait_until_started(self,
299303
return
300304

301305
if time.time() - start >= timeout:
302-
raise pg_exc.ClusterTimeoutError(
303-
"start operation timed out: %d seconds elapsed" %(
304-
timeout
305-
)
306-
)
306+
raise pg_exc.ClusterTimeoutError((self, type(self).wait_until_started))
307307
time.sleep(delay)
308308

309309
def wait_until_stopped(self,
@@ -322,9 +322,7 @@ def wait_until_stopped(self,
322322
while self.running():
323323
if time.time() - start >= timeout:
324324
raise pg_exc.ClusterTimeoutError(
325-
"stop operation timed out: %d seconds elapsed" %(
326-
timeout
327-
)
325+
(self, type(self).wait_until_stopped)
328326
)
329327
time.sleep(delay)
330328
##

postgresql/driver/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
"""
66
Driver package for connecting to PostgreSQL via a data stream(sockets).
77
"""
8-
__all__ = ['Connector', 'Connection', 'connect', 'implementation']
8+
__all__ = ['IP4', 'IP6', 'Host', 'Unix', 'connect', 'implementation']
99

1010
from .pq3 import implementation
11-
Connector = implementation.Connector
12-
Connection = implementation.Connector.Connection
11+
12+
IP4 = implementation.IP4
13+
IP6 = implementation.IP6
14+
Host = implementation.Host
15+
Unix = implementation.Unix
16+
1317
connect = implementation.connect

0 commit comments

Comments
 (0)