Skip to content

Commit 4453354

Browse files
author
James William Pye
committed
Fix StringMessages.
Consistency check was failing due to +b'\x00' changes.
1 parent 0f249fc commit 4453354

2 files changed

Lines changed: 10 additions & 18 deletions

File tree

postgresql/protocol/element3.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def serialize(self):
6565

6666
@classmethod
6767
def parse(typ, data):
68-
if data[-1] != b'\x00':
68+
if not data.endswith(b'\x00'):
6969
raise ValueError("string message not NUL-terminated")
7070
return typ(data[:-1])
7171

@@ -618,11 +618,7 @@ class Synchronize(EmptyMessage):
618618
class Query(StringMessage):
619619
"""Execute the query with the given arguments"""
620620
type = b'Q'
621-
__slots__ = ()
622-
623-
@classmethod
624-
def parse(typ, data):
625-
return typ(data[0:-1])
621+
__slots__ = ('data',)
626622

627623
class Parse(Message):
628624
"""Parse a query with the specified argument types"""
@@ -739,7 +735,7 @@ def parse(typ, data):
739735
class Describe(StringMessage):
740736
"""Describe a Portal or Prepared Statement"""
741737
type = b'D'
742-
__slots__ = ()
738+
__slots__ = ('data',)
743739

744740
def serialize(self):
745741
return self.subtype + self.data + b'\x00'
@@ -752,15 +748,15 @@ def parse(typ, data):
752748
typ.subtype, data[0:1]
753749
)
754750
)
755-
return typ(data[1:-1])
751+
return super().parse(data[1:])
756752

757753
class DescribeStatement(Describe):
758754
subtype = b'S'
759-
__slots__ = ()
755+
__slots__ = ('data',)
760756

761757
class DescribePortal(Describe):
762758
subtype = b'P'
763-
__slots__ = ()
759+
__slots__ = ('data',)
764760

765761
class Close(StringMessage):
766762
"""Generic Close"""
@@ -778,7 +774,7 @@ def parse(typ, data):
778774
typ.subtype, data[0:1]
779775
)
780776
)
781-
return typ(data[1:-1])
777+
return super().parse(data[1:])
782778

783779
class CloseStatement(Close):
784780
"""Close the specified Statement"""
@@ -888,14 +884,10 @@ def parse(typ, data):
888884

889885
class CopyFail(StringMessage):
890886
type = b'f'
891-
__slots__ = ()
892-
893-
@classmethod
894-
def parse(typ, data):
895-
return typ(data[:-1])
887+
__slots__ = ('data',)
896888

897889
class CopyDone(EmptyMessage):
898890
type = b'c'
899-
__slots__ = ()
891+
__slots__ = ('data',)
900892
CopyDoneMessage = Message.__new__(CopyDone)
901893
CopyDone.SingleInstance = CopyDoneMessage

postgresql/test/test_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class p_buffer(buffer_test, unittest.TestCase):
100100
detail = b'bleh',
101101
hint = b'dont spit into the fan',
102102
),
103-
e3.Notify(123, b"wood_table"),
103+
e3.Notify(123, b'wood_table'),
104104
e3.KillInformation(19320, 589483),
105105
e3.ShowOption(b'foo', b'bar'),
106106
e3.Authentication(4, b'salt'),

0 commit comments

Comments
 (0)