Skip to content

Commit 4ad9805

Browse files
author
James William Pye
committed
Rename client3 to xact3.
This is making room for the real client3 module.
1 parent 570abfc commit 4ad9805

3 files changed

Lines changed: 41 additions & 50 deletions

File tree

postgresql/driver/pq3.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ..python.itertools import interlace
3030

3131
from ..protocol.buffer import pq_message_stream
32-
from ..protocol import client3 as pq
32+
from ..protocol import xact3 as pq
3333
from ..protocol import typio as pg_typio
3434

3535
TypeLookup = """
@@ -248,7 +248,7 @@ def __init__(self, cursor_id, database):
248248
if not cursor_id:
249249
# Driver uses the empty id(b'').
250250
##
251-
raise TypeError("invalid cursor identifier, " + repr(cursor_id))
251+
raise ValueError("invalid cursor identifier, " + repr(cursor_id))
252252
self.cursor_id = str(cursor_id)
253253
self._quoted_cursor_id = '"' + self.cursor_id.replace('"', '""') + '"'
254254
self.database = database
@@ -287,25 +287,6 @@ def close(self):
287287
self._complete_message = None
288288
self.__class__ = Cursor
289289

290-
def restart(self):
291-
if self.parameters is None:
292-
e = pg_exc.OperationError(
293-
"cannot restart cursor when parameters are unknown"
294-
)
295-
self.ife_descend(e)
296-
e.raise_exception()
297-
298-
if self.statement is None:
299-
e = pg_exc.OperationError(
300-
"cannot restart cursor when statement is unknown"
301-
)
302-
self.ife_descend(e)
303-
e.raise_exception()
304-
305-
if not self.closed:
306-
self.close()
307-
self._init()
308-
309290
def _pq_parameters(self):
310291
return list(pg_typio.row_pack(
311292
self.parameters,
@@ -518,7 +499,7 @@ def _init(self, setup):
518499
self.chunksize = 0
519500

520501
more = self._pq_xp_fetchmore(self.chunksize)
521-
x = pq.Transaction(
502+
x = pq.Instruction(
522503
setup + more + (pq.element.SynchronizeMessage,)
523504
)
524505
self._state = (
@@ -534,7 +515,7 @@ def _dispatch_for_more(self):
534515
more = self._pq_xp_fetchmore(self.chunksize)
535516
if more:
536517
new_x = more + (pq.element.SynchronizeMessage,)
537-
new_x = pq.Transaction(new_x)
518+
new_x = pq.Instruction(new_x)
538519
self.ife_descend(new_x)
539520
self._state = (
540521
self._state[0],
@@ -567,7 +548,7 @@ def _buffer_more(self, count):
567548
# No previous transaction started, so make one.
568549
##
569550
more = self._pq_xp_fetchmore(count)
570-
x = pq.Transaction(more + (pq.element.SynchronizeMessage,))
551+
x = pq.Instruction(more + (pq.element.SynchronizeMessage,))
571552
self.ife_descend(x)
572553
self._state = (offset, buffer, x)
573554
self.database._pq_push(x)
@@ -638,7 +619,7 @@ def seek(self, offset, whence = 'ABSOLUTE'):
638619
cmd = self._pq_xp_move(b'', b'LAST') + \
639620
self._pq_xp_move(str(offset).encode('ascii'), b'BACKWARD')
640621

641-
x = pq.Transaction(cmd + (pq.element.SynchronizeMessage,))
622+
x = pq.Instruction(cmd + (pq.element.SynchronizeMessage,))
642623
self.ife_descend(x)
643624
self._state = (0, [], x)
644625
self.database._pq_push(x)
@@ -775,7 +756,7 @@ def _init(self):
775756
pq.element.DescribePortal(self._pq_cursor_id),
776757
pq.element.FlushMessage,
777758
)
778-
self._state = (0, [], pq.Transaction(setup))
759+
self._state = (0, [], pq.Instruction(setup))
779760
self.database._pq_push(self._state[2])
780761

781762
def _fini(self):
@@ -809,7 +790,7 @@ class UtilityCursor(CursorStrategy):
809790
cursor_type = 'utility'
810791

811792
def _init(self):
812-
self._pq_xact = pq.Transaction((
793+
self._pq_xact = pq.Instruction((
813794
pq.element.Bind(
814795
b'',
815796
self.statement._pq_statement_id,
@@ -1031,7 +1012,7 @@ def _init(self):
10311012
pq.element.SynchronizeMessage,
10321013
)
10331014
)
1034-
self._pq_xact = pq.Transaction(cmd)
1015+
self._pq_xact = pq.Instruction(cmd)
10351016
self.ife_descend(self._pq_xact)
10361017
self.database._pq_push(self._pq_xact)
10371018

@@ -1109,7 +1090,7 @@ def first(self, *parameters):
11091090
params = ()
11101091

11111092
# Run the statement
1112-
x = pq.Transaction((
1093+
x = pq.Instruction((
11131094
pq.element.Bind(
11141095
b'',
11151096
self._pq_statement_id,
@@ -1166,7 +1147,7 @@ def _copy_data_in(self,
11661147
to the socket's send.
11671148
"""
11681149
tps = tps or 500
1169-
x = pq.Transaction((
1150+
x = pq.Instruction((
11701151
pq.element.Bind(
11711152
b'',
11721153
self._pq_statement_id,
@@ -1248,7 +1229,7 @@ def _load_bulk_tuples(self, tupleseq, tps = None):
12481229
else:
12491230
last = pq.element.SynchronizeMessage
12501231
xm.append(last)
1251-
self.database._pq_push(pq.Transaction(xm))
1232+
self.database._pq_push(pq.Instruction(xm))
12521233
self.database._pq_complete()
12531234
except:
12541235
##
@@ -1934,7 +1915,7 @@ def synchronize(self):
19341915
"""
19351916
if self._pq_xact is not None:
19361917
self._pq_complete()
1937-
x = pq.Transaction((pq.element.SynchronizeMessage,))
1918+
x = pq.Instruction((pq.element.SynchronizeMessage,))
19381919
self._pq_xact = x
19391920
self._pq_complete()
19401921

@@ -1950,7 +1931,7 @@ def interrupt(self, timeout = None):
19501931
s.close()
19511932

19521933
def execute(self, query : str) -> None:
1953-
q = pq.Transaction((
1934+
q = pq.Instruction((
19541935
pq.element.Query(self.typio._encode(query)[0]),
19551936
))
19561937
self.ife_descend(q)
@@ -2405,12 +2386,12 @@ def _backend_gc(self):
24052386
xm.append(pq.element.CloseStatement(x))
24062387
statements += 1
24072388
xm.append(pq.element.SynchronizeMessage)
2408-
x = pq.Transaction(xm)
2389+
x = pq.Instruction(xm)
24092390
self._pq_xact = x
24102391
del self._closeportals[:portals], self._closestatements[:statements]
24112392
self._pq_complete()
24122393

2413-
def _pq_push(self, xact : pq.ProtocolState):
2394+
def _pq_push(self, xact : pq.Transaction):
24142395
'[internal] setup the given transaction to be processed'
24152396
# Push any queued closures onto the transaction or a new transaction.
24162397
if xact.state is pq.Complete:
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
def return_arg(x):
2929
return x
3030

31-
class ProtocolState(pg_api.InterfaceElement):
31+
class Transaction(pg_api.InterfaceElement):
3232
ife_label = 'PROTOCOL'
3333
ife_ancestor = None
3434
_ife_exclude_snapshot = True
@@ -49,7 +49,7 @@ def ife_snapshot_text(self):
4949
s += repr(self.error_message)
5050
return s
5151

52-
class Negotiation(ProtocolState):
52+
class Negotiation(Transaction):
5353
"""
5454
Negotiation is a protocol transaction used to manage the initial stage of a
5555
connection to PostgreSQL.
@@ -246,13 +246,13 @@ def state_machine(self):
246246
)
247247
self.last_ready = element.Ready.parse(x[1])
248248

249-
class Transaction(ProtocolState):
249+
class Instruction(Transaction):
250250
"""
251-
A transaction object is state machine that is initialized with the request
252-
messages to be sent to the server. It provides the messages to be sent and
253-
takes the response messages for order and integrity validation:
251+
Manage the state of a sequence of request messages to be sent to the server.
252+
It provides the messages to be sent and takes the response messages for order
253+
and integrity validation:
254254
255-
Transaction([postgresql.protocol.element3.Message(), ..])
255+
Instruction([postgresql.protocol.element3.Message(), ..])
256256
257257
A message must be one of:
258258
@@ -383,9 +383,19 @@ class Transaction(ProtocolState):
383383

384384
def __init__(self, commands):
385385
"""
386-
Initialize a `Transaction` instance using the given commands. Commands are
387-
`postgresql.protocol.element3.Message` instances. (Of course,
388-
subclasses thereof.)
386+
Initialize an `Instruction` instance using the given commands.
387+
388+
Commands are `postgresql.protocol.element3.Message` instances:
389+
390+
* `postgresql.protocol.element3.Query`
391+
* `postgresql.protocol.element3.Function`
392+
* `postgresql.protocol.element3.Parse`
393+
* `postgresql.protocol.element3.Bind`
394+
* `postgresql.protocol.element3.Describe`
395+
* `postgresql.protocol.element3.Close`
396+
* `postgresql.protocol.element3.Execute`
397+
* `postgresql.protocol.element3.Synchronize`
398+
* `postgresql.protocol.element3.Flush`
389399
"""
390400
# Commands are accessed by index.
391401
self.commands = tuple(commands)

postgresql/test/test_protocol.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import struct
77
import decimal
88
import postgresql.protocol.element3 as e3
9-
import postgresql.protocol.client3 as c3
9+
import postgresql.protocol.xact3 as x3
1010
import postgresql.protocol.pbuffer as p_buffer_module
1111
import postgresql.protocol.typstruct as pg_typstruct
1212
import postgresql.protocol.typio as pg_typio
@@ -195,7 +195,7 @@ def testEmptyMessages(self):
195195
self.failUnless(x is xtype())
196196

197197
##
198-
# client3 tests
198+
# xact3 tests
199199
##
200200

201201
xact_samples = [
@@ -326,15 +326,15 @@ def testEmptyMessages(self):
326326
),
327327
]
328328

329-
class test_client3(unittest.TestCase):
329+
class test_xact3(unittest.TestCase):
330330
def testTransactionSamplesAll(self):
331331
for xcmd, xres in xact_samples:
332-
x = c3.Transaction(xcmd)
332+
x = x3.Instruction(xcmd)
333333
r = tuple([(y.type, y.serialize()) for y in xres])
334334
x.state[1]()
335335
self.failUnlessEqual(x.messages, ())
336336
x.state[1](r)
337-
self.failUnlessEqual(x.state, c3.Complete)
337+
self.failUnlessEqual(x.state, x3.Complete)
338338
rec = []
339339
for y in x.completed:
340340
for z in y[1]:

0 commit comments

Comments
 (0)