@@ -40,8 +40,8 @@ def serialization(self, writer):
4040 writer (self .serialize ())
4141
4242 @classmethod
43- def parse (self , data ):
44- return self (data )
43+ def parse (typ , data ):
44+ return typ (data )
4545
4646class StringMessage (Message ):
4747 """
@@ -127,15 +127,15 @@ def serialize(self):
127127 return self [1 ]
128128
129129 @classmethod
130- def parse (self , data ):
130+ def parse (typ , data ):
131131 if ulong .unpack (data [1 :5 ])[0 ] != len (data ) - 1 :
132132 raise ValueError (
133133 "invalid wire message where data is %d bytes and " \
134134 "internal size stamp is %d bytes" % (
135135 len (data ), ulong .unpack (data [1 :5 ])[0 ] + 1
136136 )
137137 )
138- return self ((data [0 ], data [5 :]))
138+ return typ ((data [0 ], data [5 :]))
139139
140140class EmptyMessage (Message ):
141141 'An abstract message that is always empty'
@@ -149,10 +149,10 @@ def serialize(self):
149149 return b''
150150
151151 @classmethod
152- def parse (self , data ):
152+ def parse (typ , data ):
153153 if data != b'' :
154154 raise ValueError ("empty message(%r) had data" % (self .type ,))
155- return self .SingleInstance
155+ return typ .SingleInstance
156156
157157class Notify (Message ):
158158 'Asynchronous notification message'
@@ -170,10 +170,10 @@ def serialize(self):
170170 self .parameter + b'\x00 '
171171
172172 @classmethod
173- def parse (self , data ):
173+ def parse (typ , data ):
174174 pid = ulong .unpack (data [0 :4 ])[0 ]
175175 relname , param , nothing = data [4 :].split (b'\x00 ' , 2 )
176- return self (pid , relname , param )
176+ return typ (pid , relname , param )
177177
178178class ShowOption (Message ):
179179 """ShowOption(name, value)
@@ -189,17 +189,17 @@ def serialize(self):
189189 return self .name + b'\x00 ' + self .value + b'\x00 '
190190
191191 @classmethod
192- def parse (self , data ):
193- return self (* (data .split (b'\x00 ' , 2 )[0 :2 ]))
192+ def parse (typ , data ):
193+ return typ (* (data .split (b'\x00 ' , 2 )[0 :2 ]))
194194
195195class Complete (StringMessage ):
196196 'Command completion message.'
197197 type = b'C'
198198 __slots__ = ()
199199
200200 @classmethod
201- def parse (self , data ):
202- return self (data [: - 1 ] )
201+ def parse (typ , data ):
202+ return typ (data . rstrip ( b' \x00 ' ) )
203203
204204 def extract_count (self ):
205205 """
@@ -317,12 +317,12 @@ def serialize(self):
317317 ]) + b'\x00 '
318318
319319 @classmethod
320- def parse (self , data ):
320+ def parse (typ , data ):
321321 kw = {}
322322 for frag in data .split (b'\x00 ' ):
323323 if frag :
324324 kw [self ._dtm [frag [0 :1 ]]] = frag [1 :]
325- return self (** kw )
325+ return typ (** kw )
326326
327327class Error (Notice ):
328328 """Incoming error"""
@@ -342,9 +342,9 @@ def serialize(self):
342342 ulong .pack (len (self .result )) + self .result
343343
344344 @classmethod
345- def parse (self , data ):
345+ def parse (typ , data ):
346346 if data == b'\xff \xff \xff \xff ' :
347- return self (None )
347+ return typ (None )
348348 size = ulong .unpack (data [0 :4 ])[0 ]
349349 data = data [4 :]
350350 if size != len (data ):
@@ -353,7 +353,7 @@ def parse(self, data):
353353 len (data ), size
354354 )
355355 )
356- return self (data )
356+ return typ (data )
357357
358358class AttributeTypes (TupleMessage ):
359359 """Tuple attribute types"""
@@ -364,12 +364,12 @@ def serialize(self):
364364 return ushort .pack (len (self )) + b'' .join ([ulong .pack (x ) for x in self ])
365365
366366 @classmethod
367- def parse (self , data ):
367+ def parse (typ , data ):
368368 ac = ushort .unpack (data [0 :2 ])[0 ]
369369 args = data [2 :]
370370 if len (args ) != ac * 4 :
371371 raise ValueError ("invalid argument type data size" )
372- return self (unpack ('!%dL' % (ac ,), args ))
372+ return typ (unpack ('!%dL' % (ac ,), args ))
373373
374374class TupleDescriptor (TupleMessage ):
375375 """Tuple description"""
@@ -397,7 +397,7 @@ def serialize(self):
397397 ])
398398
399399 @classmethod
400- def parse (self , data ):
400+ def parse (typ , data ):
401401 ac = ushort .unpack (data [0 :2 ])[0 ]
402402 atts = []
403403 data = data [2 :]
@@ -408,10 +408,10 @@ def parse(self, data):
408408 name = data [0 :eoan ]
409409 data = data [eoan + 1 :]
410410 # name, relationId, columnNumber, typeId, typlen, typmod, format
411- atts .append ((name ,) + self .struct .unpack (data [0 :18 ]))
411+ atts .append ((name ,) + typ .struct .unpack (data [0 :18 ]))
412412 data = data [18 :]
413413 ca += 1
414- return self (atts )
414+ return typ (atts )
415415
416416class Tuple (TupleMessage ):
417417 """Incoming tuple"""
@@ -425,7 +425,7 @@ def serialize(self):
425425 ])
426426
427427 @classmethod
428- def parse (self , data ):
428+ def parse (typ , data ):
429429 natts = ushort .unpack (data [0 :2 ])[0 ]
430430 atts = list ()
431431 offset = 2
@@ -443,7 +443,7 @@ def parse(self, data):
443443 att = data [ao :offset ]
444444 atts .append (att )
445445 natts -= 1
446- return self (atts )
446+ return typ (atts )
447447
448448class KillInformation (Message ):
449449 'Backend cancellation information'
@@ -459,8 +459,8 @@ def serialize(self):
459459 return self .struct .pack (self .pid , self .key )
460460
461461 @classmethod
462- def parse (self , data ):
463- return self ( * self .struct .unpack (data ))
462+ def parse (typ , data ):
463+ return typ ( * typ .struct .unpack (data ))
464464
465465class CancelQuery (KillInformation ):
466466 'Abort the query in the specified backend'
@@ -480,10 +480,10 @@ def bytes(self):
480480 return ulong .pack (len (data )) + data
481481
482482 @classmethod
483- def parse (self , data ):
483+ def parse (typ , data ):
484484 if data [0 :4 ] != self .packed_version :
485485 raise ValueError ("invalid cancel query code" )
486- return self (* unpack ("!xxxxLL" , data ))
486+ return typ (* unpack ("!xxxxLL" , data ))
487487
488488class NegotiateSSL (Message ):
489489 "Discover backend's SSL support"
@@ -492,7 +492,7 @@ class NegotiateSSL(Message):
492492 packed_version = version .bytes ()
493493 __slots__ = ()
494494
495- def __new__ (subtype ):
495+ def __new__ (typ ):
496496 return NegotiateSSLMessage
497497
498498 def bytes (self ):
@@ -503,7 +503,7 @@ def serialize(self):
503503 return self .packed_version
504504
505505 @classmethod
506- def parse (self , data ):
506+ def parse (typ , data ):
507507 if data != self .packed_version :
508508 raise ValueError ("invalid SSL Negotiation code" )
509509 return NegotiateSSLMessage
@@ -531,7 +531,7 @@ def bytes(self):
531531 return ulong .pack (len (data ) + 4 ) + data
532532
533533 @classmethod
534- def parse (self , data ):
534+ def parse (typ , data ):
535535 if data [0 :4 ] != self .version .bytes ():
536536 raise ValueError ("invalid version code {1}" .format (repr (data [0 :4 ])))
537537 kw = dict ()
@@ -542,8 +542,7 @@ def parse(self, data):
542542 continue
543543 kw [key ] = value
544544 key = None
545- return self (kw )
546-
545+ return typ (kw )
547546
548547AuthRequest_OK = 0
549548AuthRequest_Cleartext = 3
@@ -585,8 +584,8 @@ def serialize(self):
585584 return ulong .pack (self .request ) + self .salt
586585
587586 @classmethod
588- def parse (subtype , data ):
589- return subtype (ulong .unpack (data [0 :4 ])[0 ], data [4 :])
587+ def parse (typ , data ):
588+ return typ (ulong .unpack (data [0 :4 ])[0 ], data [4 :])
590589
591590class Password (StringMessage ):
592591 'Password supplement'
@@ -623,8 +622,8 @@ class Query(StringMessage):
623622 __slots__ = ()
624623
625624 @classmethod
626- def parse (self , data ):
627- return self (data [0 :- 1 ])
625+ def parse (typ , data ):
626+ return typ (data [0 :- 1 ])
628627
629628class Parse (Message ):
630629 """Parse a query with the specified argument types"""
@@ -637,14 +636,14 @@ def __init__(self, name, statement, argtypes):
637636 self .argtypes = argtypes
638637
639638 @classmethod
640- def parse (self , data ):
639+ def parse (typ , data ):
641640 name , statement , args = data .split (b'\x00 ' , 2 )
642641 ac = ushort .unpack (args [0 :2 ])[0 ]
643642 args = args [2 :]
644643 if len (args ) != ac * 4 :
645644 raise ValueError ("invalid argument type data" )
646645 at = unpack ('!%dL' % (ac ,), args )
647- return self (name , statement , at )
646+ return typ (name , statement , at )
648647
649648 def serialize (self ):
650649 ac = ushort .pack (len (self .argtypes ))
@@ -690,7 +689,7 @@ def serialize(self):
690689 b'' .join (self .rformats )
691690
692691 @classmethod
693- def parse (subtype , message_data ):
692+ def parse (typ , message_data ):
694693 name , statement , data = message_data .split (b'\x00 ' , 2 )
695694 ac = ushort .unpack (data [:2 ])[0 ]
696695 offset = 2 + (2 * ac )
@@ -719,7 +718,7 @@ def parse(subtype, message_data):
719718 offset = ao + (2 * rfc )
720719 rformats = unpack (("2s" * rfc ), data [ao :offset ])
721720
722- return subtype (name , statement , aformats , args , rformats )
721+ return typ (name , statement , aformats , args , rformats )
723722
724723class Execute (Message ):
725724 """Fetch results from the specified Portal"""
@@ -734,9 +733,9 @@ def serialize(self):
734733 return self .name + pack ("!BL" , 0 , self .max )
735734
736735 @classmethod
737- def parse (self , data ):
736+ def parse (typ , data ):
738737 name , max = data .split (b'\x00 ' , 1 )
739- return self (name , ulong .unpack (max )[0 ])
738+ return typ (name , ulong .unpack (max )[0 ])
740739
741740class Describe (StringMessage ):
742741 """Describe a Portal or Prepared Statement"""
@@ -747,14 +746,14 @@ def serialize(self):
747746 return self .subtype + self .data + b'\x00 '
748747
749748 @classmethod
750- def parse (subtype , data ):
751- if data [0 ] != subtype .subtype :
749+ def parse (typ , data ):
750+ if data [0 ] != typ .subtype :
752751 raise ValueError (
753752 "invalid Describe message subtype, %r; expected %r" % (
754- subtype .subtype , data [0 ]
753+ typ .subtype , data [0 ]
755754 )
756755 )
757- return subtype (data [1 :- 1 ])
756+ return typ (data [1 :- 1 ])
758757
759758class DescribeStatement (Describe ):
760759 subtype = b'S'
@@ -773,14 +772,14 @@ def serialize(self):
773772 return self .subtype + self .data + b'\x00 '
774773
775774 @classmethod
776- def parse (subtype , data ):
777- if data [0 ] != subtype .subtype :
775+ def parse (typ , data ):
776+ if data [0 ] != typ .subtype :
778777 raise ValueError (
779778 "invalid Close message subtype, %r; expected %r" % (
780- subtype .subtype , data [0 ]
779+ typ .subtype , data [0 ]
781780 )
782781 )
783- return subtype (data [1 :- 1 ])
782+ return typ (data [1 :- 1 ])
784783
785784class CloseStatement (Close ):
786785 """Close the specified Statement"""
@@ -813,7 +812,7 @@ def serialize(self):
813812 ]) + self .rformat
814813
815814 @classmethod
816- def parse (self , data ):
815+ def parse (typ , data ):
817816 oid = ulong .unpack (data [0 :4 ])[0 ]
818817
819818 ac = ushort .unpack (data [4 :6 ])[0 ]
@@ -838,7 +837,7 @@ def parse(self, data):
838837 args .append (att )
839838 natts -= 1
840839
841- return self (oid , aformats , args , data [offset :])
840+ return typ (oid , aformats , args , data [offset :])
842841
843842class CopyBegin (Message ):
844843 type = None
@@ -855,12 +854,12 @@ def serialize(self):
855854 ])
856855
857856 @classmethod
858- def parse (subtype , data ):
859- format , natts = subtype .struct .unpack (data [:3 ])
857+ def parse (typ , data ):
858+ format , natts = typ .struct .unpack (data [:3 ])
860859 formats_str = data [3 :]
861860 if len (formats_str ) != natts * 2 :
862861 raise ValueError ("number of formats and data do not match up" )
863- return subtype (format , [
862+ return typ (format , [
864863 ushort .unpack (formats_str [x :x + 2 ])[0 ] for x in range (0 , natts * 2 , 2 )
865864 ])
866865
@@ -885,16 +884,16 @@ def serialize(self):
885884 return self .data
886885
887886 @classmethod
888- def parse (subtype , data ):
889- return subtype (data )
887+ def parse (typ , data ):
888+ return typ (data )
890889
891890class CopyFail (StringMessage ):
892891 type = b'f'
893892 __slots__ = ()
894893
895894 @classmethod
896- def parse (self , data ):
897- return self (data [:- 1 ])
895+ def parse (typ , data ):
896+ return typ (data [:- 1 ])
898897
899898class CopyDone (EmptyMessage ):
900899 type = b'c'
0 commit comments