Skip to content

Commit 49706cc

Browse files
author
James William Pye
committed
Minor doc updates and get rid of path attribute and [un]subscribe in api.
1 parent fa24e03 commit 49706cc

4 files changed

Lines changed: 25 additions & 64 deletions

File tree

postgresql/api.py

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ def read(self,
504504
quantity : "Number of rows to read" = None
505505
) -> ["Row"]:
506506
"""
507-
Read the specified number of rows and return them in a list.
507+
Read, fetch, the specified number of rows and return them in a list.
508508
This alters the cursor's position.
509509
510-
If the quantity is a negative value, read backwards.
510+
If the quantity is a negative value, fetch backwards.
511511
"""
512512

513513
@abstractmethod
@@ -886,30 +886,6 @@ class Settings(
886886
"""
887887
ife_label = 'SETTINGS'
888888

889-
def getpath(self) -> [str]:
890-
"""
891-
Returns a sequence of the schemas that make up the current search_path.
892-
"""
893-
def setpath(self, seq : [str]):
894-
"""
895-
Set the "search_path" setting to the given a sequence of schema names,
896-
[Implementations must properly escape and join the strings]
897-
"""
898-
path = propertydoc(abstractproperty(
899-
getpath, setpath,
900-
doc = """
901-
An interface to a structured ``search_path`` setting:
902-
903-
>>> db.settings.path
904-
['public', '$user']
905-
906-
It may also be used to set the path:
907-
908-
>>> db.settings.path = ('public', 'tools')
909-
"""
910-
))
911-
del getpath, setpath
912-
913889
@abstractmethod
914890
def __getitem__(self, key):
915891
"""
@@ -928,8 +904,8 @@ def __setitem__(self, key, value):
928904
@abstractmethod
929905
def __call__(self, **kw):
930906
"""
931-
Create a context manager applying the given settings. This is normally used
932-
in conjunction with a with-statement:
907+
Create a context manager applying the given settings on __enter__ and
908+
restoring the old values on __exit__.
933909
934910
>>> with db.settings(search_path = 'local,public'):
935911
... ...
@@ -974,31 +950,6 @@ def items(self):
974950
Return an iterator to all of the setting value pairs.
975951
"""
976952

977-
@abstractmethod
978-
def subscribe(self, key, callback):
979-
"""
980-
Subscribe to changes of the setting using the callback. When the setting
981-
is changed, the callback will be invoked with the connection, the key,
982-
and the new value. If the old value is locally cached, its value will
983-
still be available for inspection, but there is no guarantee.
984-
If `None` is passed as the key, the callback will be called whenever any
985-
setting is remotely changed.
986-
987-
>>> def watch(connection, key, newval):
988-
...
989-
>>> db.settings.subscribe('TimeZone', watch)
990-
"""
991-
992-
@abstractmethod
993-
def unsubscribe(self, key, callback):
994-
"""
995-
Stop listening for changes to a setting. The setting name(`key`), and
996-
the callback used to subscribe must be given again for successful
997-
termination of the subscription.
998-
999-
>>> db.settings.unsubscribe('TimeZone', watch)
1000-
"""
1001-
1002953
class Database(InterfaceElement):
1003954
"""
1004955
The interface to an individual database. `Connection` objects inherit from
@@ -1259,7 +1210,6 @@ def __init__(self,
12591210
password : str = None,
12601211
database : str = None,
12611212
settings : (dict, [(str,str)]) = None,
1262-
path : "sequence of schema names to set the search_path to" = None
12631213
):
12641214
if user is None:
12651215
# sure, it's a "required" keyword, makes for better documentation
@@ -1268,7 +1218,6 @@ def __init__(self,
12681218
self.password = password
12691219
self.database = database
12701220
self.settings = settings
1271-
self.path = path
12721221

12731222
class Connection(Database):
12741223
"""

postgresql/configfile.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,5 @@ def getset(self, keys):
331331
for x in (keys - set(cfg.keys())):
332332
cfg[x] = None
333333
return cfg
334-
335-
def subscribe(self):
336-
pass
337-
338-
def unsubscribe(self):
339-
pass
340334
##
341335
# vim: ts=3:sw=3:noet:

postgresql/driver/pq3.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,12 +1521,31 @@ def _notify(self, msg):
15211521
self.cache[key] = val
15221522

15231523
def subscribe(self, key, callback):
1524+
"""
1525+
Subscribe to changes of the setting using the callback. When the setting
1526+
is changed, the callback will be invoked with the connection, the key,
1527+
and the new value. If the old value is locally cached, its value will
1528+
still be available for inspection, but there is no guarantee.
1529+
If `None` is passed as the key, the callback will be called whenever any
1530+
setting is remotely changed.
1531+
1532+
>>> def watch(connection, key, newval):
1533+
...
1534+
>>> db.settings.subscribe('TimeZone', watch)
1535+
"""
15241536
subs = self._subscriptions = getattr(self, '_subscriptions', {})
15251537
callbacks = subs.setdefault(key, [])
15261538
if callback not in callbacks:
15271539
callbacks.append(callback)
15281540

15291541
def unsubscribe(self, key, callback):
1542+
"""
1543+
Stop listening for changes to a setting. The setting name(`key`), and
1544+
the callback used to subscribe must be given again for successful
1545+
termination of the subscription.
1546+
1547+
>>> db.settings.unsubscribe('TimeZone', watch)
1548+
"""
15301549
subs = getattr(self, '_subscriptions', {})
15311550
callbacks = subs.get(key, ())
15321551
if callback in callbacks:

postgresql/unittest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def configure_cluster(self):
5151
e.raise_exception()
5252
self.cluster.settings.update(dict(
5353
port = str(self.cluster_port), # XXX: identify an available port and use it
54-
max_connections = '16',
55-
shared_buffers = '64',
54+
max_connections = '8',
55+
shared_buffers = '32',
5656
listen_addresses = 'localhost',
5757
log_destination = 'stderr',
5858
log_min_messages = 'FATAL',
@@ -69,7 +69,6 @@ def initialize_database(self):
6969
"where datname = 'test'"
7070
).first() is None:
7171
c.execute('create database test')
72-
print("============ INITIALIZED test ==============")
7372

7473
def run(self, *args, **kw):
7574
if not self.cluster.initialized():

0 commit comments

Comments
 (0)