@@ -9,8 +9,8 @@ from libc.string cimport memcpy
99
1010import collections
1111
12- from . import exceptions
13-
12+ class BufferError ( Exception ):
13+ pass
1414
1515@cython.no_gc_clear
1616@cython.final
@@ -31,7 +31,7 @@ cdef class WriteBuffer:
3131 self ._size = 0
3232
3333 if self ._view_count:
34- raise exceptions. BufferError(
34+ raise BufferError(
3535 ' Deallocating buffer with attached memoryviews' )
3636
3737 def __getbuffer__ (self , Py_buffer *buffer , int flags ):
@@ -47,7 +47,7 @@ cdef class WriteBuffer:
4747
4848 cdef inline _check_readonly(self ):
4949 if self ._view_count:
50- raise exceptions. BufferError(' the buffer is in read-only mode' )
50+ raise BufferError(' the buffer is in read-only mode' )
5151
5252 cdef inline _ensure_alloced(self , ssize_t extra_length):
5353 cdef ssize_t new_size = extra_length + self ._length
@@ -90,7 +90,7 @@ cdef class WriteBuffer:
9090
9191 cdef inline start_message(self , char type ):
9292 if self ._length != 0 :
93- raise exceptions. BufferError(
93+ raise BufferError(
9494 ' cannot start_message for a non-empty buffer' )
9595 self ._ensure_alloced(5 )
9696 self ._message_mode = 1
@@ -103,12 +103,12 @@ cdef class WriteBuffer:
103103
104104 self ._check_readonly()
105105 if not self ._message_mode:
106- raise exceptions. BufferError(
106+ raise BufferError(
107107 ' end_message can only be called with start_message' )
108108 if self ._length < 5 :
109- raise exceptions. BufferError(' end_message: buffer is too small' )
109+ raise BufferError(' end_message: buffer is too small' )
110110 if mlen > _MAXINT32:
111- raise exceptions. BufferError(' end_message: message is too large' )
111+ raise BufferError(' end_message: message is too large' )
112112
113113 hton.pack_int32(& self ._buf[1 ], < int32_t> mlen)
114114 return self
@@ -164,7 +164,7 @@ cdef class WriteBuffer:
164164
165165 cpython.PyBytes_AsStringAndSize(data, & buf, & size)
166166 if size > _MAXINT32:
167- raise exceptions. BufferError(' string is too large' )
167+ raise BufferError(' string is too large' )
168168 # `size` does not account for the NULL at the end.
169169 self .write_int32(< int32_t> size)
170170 self .write_cstr(buf, size)
@@ -252,7 +252,7 @@ cdef class ReadBuffer:
252252 bytes data_bytes
253253
254254 if not cpython.PyBytes_CheckExact(data):
255- raise exceptions. BufferError(' feed_data: bytes object expected' )
255+ raise BufferError(' feed_data: bytes object expected' )
256256
257257 # Uncomment the below code to test code paths that
258258 # read single int/str/bytes sequences are split over
@@ -284,9 +284,9 @@ cdef class ReadBuffer:
284284 cdef inline _ensure_first_buf(self ):
285285 if PG_DEBUG:
286286 if self ._len0 == 0 :
287- raise exceptions. BufferError(' empty first buffer' )
287+ raise BufferError(' empty first buffer' )
288288 if self ._length == 0 :
289- raise exceptions. BufferError(' empty buffer' )
289+ raise BufferError(' empty buffer' )
290290
291291 if self ._pos0 == self ._len0:
292292 self ._switch_to_next_buf()
@@ -306,7 +306,7 @@ cdef class ReadBuffer:
306306
307307 if PG_DEBUG:
308308 if self ._len0 < 1 :
309- raise exceptions. BufferError(
309+ raise BufferError(
310310 ' debug: second buffer of ReadBuffer is empty' )
311311
312312 cdef inline const char * _try_read_bytes(self , ssize_t nbytes):
@@ -394,13 +394,13 @@ cdef class ReadBuffer:
394394 return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
395395
396396 if nbytes > self ._length:
397- raise exceptions. BufferError(
397+ raise BufferError(
398398 ' not enough data to read {} bytes' .format(nbytes))
399399
400400 if self ._current_message_ready:
401401 self ._current_message_len_unread -= nbytes
402402 if self ._current_message_len_unread < 0 :
403- raise exceptions. BufferError(' buffer overread' )
403+ raise BufferError(' buffer overread' )
404404
405405 result = cpython.PyBytes_FromStringAndSize(NULL , nbytes)
406406 buf = cpython.PyBytes_AS_STRING(result)
@@ -410,7 +410,7 @@ cdef class ReadBuffer:
410410 cdef bytes read_len_prefixed_bytes(self ):
411411 cdef int32_t size = self .read_int32()
412412 if size < 0 :
413- raise exceptions. BufferError(
413+ raise BufferError(
414414 ' negative length for a len-prefixed bytes value' )
415415 if size == 0 :
416416 return b' '
@@ -423,7 +423,7 @@ cdef class ReadBuffer:
423423
424424 size = self .read_int32()
425425 if size < 0 :
426- raise exceptions. BufferError(
426+ raise BufferError(
427427 ' negative length for a len-prefixed bytes value' )
428428
429429 if size == 0 :
@@ -453,13 +453,13 @@ cdef class ReadBuffer:
453453
454454 if PG_DEBUG:
455455 if not self ._buf0:
456- raise exceptions. BufferError(
456+ raise BufferError(
457457 ' debug: first buffer of ReadBuffer is empty' )
458458
459459 self ._ensure_first_buf()
460460 first_byte = self ._try_read_bytes(1 )
461461 if first_byte is NULL :
462- raise exceptions. BufferError(' not enough data to read one byte' )
462+ raise BufferError(' not enough data to read one byte' )
463463
464464 return first_byte[0 ]
465465
@@ -504,7 +504,7 @@ cdef class ReadBuffer:
504504
505505 cdef inline read_null_str(self ):
506506 if not self ._current_message_ready:
507- raise exceptions. BufferError(
507+ raise BufferError(
508508 ' read_null_str only works when the message guaranteed '
509509 ' to be in the buffer' )
510510
@@ -542,7 +542,7 @@ cdef class ReadBuffer:
542542
543543 self ._current_message_len_unread -= nread
544544 if self ._current_message_len_unread < 0 :
545- raise exceptions. BufferError(
545+ raise BufferError(
546546 ' read_null_str: buffer overread' )
547547
548548 return result
@@ -555,7 +555,7 @@ cdef class ReadBuffer:
555555
556556 self ._current_message_len_unread -= nread
557557 if self ._current_message_len_unread < 0 :
558- raise exceptions. BufferError(
558+ raise BufferError(
559559 ' read_null_str: buffer overread' )
560560
561561 self ._ensure_first_buf()
@@ -573,7 +573,7 @@ cdef class ReadBuffer:
573573 self ._ensure_first_buf()
574574 cbuf = self ._try_read_bytes(1 )
575575 if cbuf == NULL :
576- raise exceptions. BufferError(
576+ raise BufferError(
577577 ' failed to read one byte on a non-empty buffer' )
578578 self ._current_message_type = cbuf[0 ]
579579
@@ -611,7 +611,7 @@ cdef class ReadBuffer:
611611
612612 cdef int32_t put_message(self ) except - 1 :
613613 if not self ._current_message_ready:
614- raise exceptions. BufferError(
614+ raise BufferError(
615615 ' cannot put message: no message taken' )
616616 self ._current_message_ready = False
617617 return 0
@@ -634,15 +634,15 @@ cdef class ReadBuffer:
634634
635635 cdef discard_message(self ):
636636 if not self ._current_message_ready:
637- raise exceptions. BufferError(' no message to discard' )
637+ raise BufferError(' no message to discard' )
638638 if self ._current_message_len_unread > 0 :
639639 self ._read_and_discard(self ._current_message_len_unread)
640640 self ._current_message_len_unread = 0
641641 self ._finish_message()
642642
643643 cdef bytes consume_message(self ):
644644 if not self ._current_message_ready:
645- raise exceptions. BufferError(' no message to consume' )
645+ raise BufferError(' no message to consume' )
646646 if self ._current_message_len_unread > 0 :
647647 mem = self .read_bytes(self ._current_message_len_unread)
648648 else :
@@ -653,14 +653,14 @@ cdef class ReadBuffer:
653653 cdef redirect_messages(self , WriteBuffer buf, char mtype,
654654 int stop_at = 0 ):
655655 if not self ._current_message_ready:
656- raise exceptions. BufferError(
656+ raise BufferError(
657657 ' consume_full_messages called on a buffer without a '
658658 ' complete first message' )
659659 if mtype != self ._current_message_type:
660- raise exceptions. BufferError(
660+ raise BufferError(
661661 ' consume_full_messages called with a wrong mtype' )
662662 if self ._current_message_len_unread != self ._current_message_len - 4 :
663- raise exceptions. BufferError(
663+ raise BufferError(
664664 ' consume_full_messages called on a partially read message' )
665665
666666 cdef:
0 commit comments