Skip to content

Commit 79550af

Browse files
author
James William Pye
committed
Fix some missed s/self/typ/g substitutions in classemthods.
. Remember to descend the PSs initialization transaction as well. . Cleanup ife_snapshot_text on PSs
1 parent 2bb50ba commit 79550af

2 files changed

Lines changed: 30 additions & 17 deletions

File tree

postgresql/driver/pq3.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,15 @@ class Cursor(pg_api.Cursor):
514514
_cursor_type = None
515515

516516
@classmethod
517-
def from_query(type,
517+
def from_query(
518+
typ,
518519
parameters, query,
519520
with_hold = False,
520521
with_scroll = False,
521522
insensitive = True,
522523
fetchcount = None,
523524
):
524-
c = super().__new__(type)
525+
c = super().__new__(typ)
525526
c.parameters = parameters
526527
c.query = query
527528
c.with_hold = with_hold
@@ -532,7 +533,7 @@ def from_query(type,
532533
# If the cursor is not scrollable, and fetchcount
533534
# was not supplied, set it as the default fetchcount.
534535
if not with_scroll and fetchcount is None:
535-
fetchcount = type.default_fetchcount
536+
fetchcount = typ.default_fetchcount
536537
c.__init__(ID(c), query.connection, fetchcount = fetchcount)
537538
return c
538539

@@ -948,15 +949,16 @@ class PreparedStatement(pg_api.PreparedStatement):
948949
statement_id = None
949950

950951
@classmethod
951-
def from_query_string(type,
952+
def from_query_string(
953+
typ,
952954
string : "SQL statement to prepare",
953955
connection : "connection to bind the query to",
954956
statement_id : "statement_id to use instead of generating one" = None
955957
) -> "PreparedStatement instance":
956958
"""
957959
Create a PreparedStatement from a query string.
958960
"""
959-
r = super().__new__(type)
961+
r = super().__new__(typ)
960962
r.string = string
961963
r.__init__(statement_id or ID(r), connection)
962964
return r
@@ -973,8 +975,8 @@ def __repr__(self):
973975
return '<{mod}.{name}[{ci}] {state}>'.format(
974976
mod = type(self).__module__,
975977
name = type(self).__name__,
976-
ci = ci,
977-
state = self.closed and 'closed' or 'prepared',
978+
ci = self.connection.connector._pq_iri,
979+
state = self.state,
978980
)
979981

980982
@property
@@ -991,6 +993,17 @@ def command(self) -> str:
991993
def closed(self) -> bool:
992994
return self._cid != self.connection._cid
993995

996+
@property
997+
def state(self) -> str:
998+
if self.closed:
999+
if self._pq_xact is not None:
1000+
if self.string is not None:
1001+
return 'parsing'
1002+
else:
1003+
return 'describing'
1004+
return 'closed'
1005+
return 'prepared'
1006+
9941007
def close(self):
9951008
if self._cid == self.connection._cid:
9961009
self.connection._closestatements.append(self._pq_statement_id)
@@ -1010,11 +1023,10 @@ def prepare(self):
10101023

10111024
def ife_snapshot_text(self):
10121025
s = ""
1013-
if self.closed:
1014-
s += "[closed] "
1015-
if self.title:
1016-
s += self.title + ", "
1017-
s += "statement_id(" + repr(self._pq_statement_id or self.statement_id) + ")"
1026+
s += "[" + self.state + "] "
1027+
if self.ife_object_title != pg_api.InterfaceElement.ife_object_title:
1028+
s += self.ife_object_title + ", "
1029+
s += "statement_id(" + repr(self.statement_id) + ")"
10181030
s += os.linesep + ' ' * 2 + (os.linesep + ' ' * 2).join(
10191031
str(self.string).split(os.linesep)
10201032
)
@@ -1051,6 +1063,7 @@ def _init(self):
10511063
)
10521064
)
10531065
self._pq_xact = pq.Transaction(cmd)
1066+
self.ife_descend(self._pq_xact)
10541067
self.connection._pq_push(self._pq_xact)
10551068

10561069
def _fini(self):

postgresql/protocol/element3.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def serialize(self):
151151
@classmethod
152152
def parse(typ, data):
153153
if data != b'':
154-
raise ValueError("empty message(%r) had data" %(self.type,))
154+
raise ValueError("empty message(%r) had data" %(typ.type,))
155155
return typ.SingleInstance
156156

157157
class Notify(Message):
@@ -321,7 +321,7 @@ def parse(typ, data):
321321
kw = {}
322322
for frag in data.split(b'\x00'):
323323
if frag:
324-
kw[self._dtm[frag[0:1]]] = frag[1:]
324+
kw[typ._dtm[frag[0:1]]] = frag[1:]
325325
return typ(**kw)
326326

327327
class Error(Notice):
@@ -481,7 +481,7 @@ def bytes(self):
481481

482482
@classmethod
483483
def parse(typ, data):
484-
if data[0:4] != self.packed_version:
484+
if data[0:4] != typ.packed_version:
485485
raise ValueError("invalid cancel query code")
486486
return typ(*unpack("!xxxxLL", data))
487487

@@ -504,7 +504,7 @@ def serialize(self):
504504

505505
@classmethod
506506
def parse(typ, data):
507-
if data != self.packed_version:
507+
if data != typ.packed_version:
508508
raise ValueError("invalid SSL Negotiation code")
509509
return NegotiateSSLMessage
510510
NegotiateSSLMessage = Message.__new__(NegotiateSSL)
@@ -532,7 +532,7 @@ def bytes(self):
532532

533533
@classmethod
534534
def parse(typ, data):
535-
if data[0:4] != self.version.bytes():
535+
if data[0:4] != typ.packed_version:
536536
raise ValueError("invalid version code {1}".format(repr(data[0:4])))
537537
kw = dict()
538538
key = None

0 commit comments

Comments
 (0)