@@ -9,8 +9,8 @@ from libc.string cimport memcpy
9
9
10
10
import collections
11
11
12
- from . import exceptions
13
-
12
+ class BufferError ( Exception ):
13
+ pass
14
14
15
15
@cython.no_gc_clear
16
16
@cython.final
@@ -31,7 +31,7 @@ cdef class WriteBuffer:
31
31
self ._size = 0
32
32
33
33
if self ._view_count:
34
- raise exceptions. BufferError(
34
+ raise BufferError(
35
35
' Deallocating buffer with attached memoryviews' )
36
36
37
37
def __getbuffer__ (self , Py_buffer *buffer , int flags ):
@@ -47,7 +47,7 @@ cdef class WriteBuffer:
47
47
48
48
cdef inline _check_readonly(self ):
49
49
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' )
51
51
52
52
cdef inline _ensure_alloced(self , ssize_t extra_length):
53
53
cdef ssize_t new_size = extra_length + self ._length
@@ -90,7 +90,7 @@ cdef class WriteBuffer:
90
90
91
91
cdef inline start_message(self , char type ):
92
92
if self ._length != 0 :
93
- raise exceptions. BufferError(
93
+ raise BufferError(
94
94
' cannot start_message for a non-empty buffer' )
95
95
self ._ensure_alloced(5 )
96
96
self ._message_mode = 1
@@ -103,12 +103,12 @@ cdef class WriteBuffer:
103
103
104
104
self ._check_readonly()
105
105
if not self ._message_mode:
106
- raise exceptions. BufferError(
106
+ raise BufferError(
107
107
' end_message can only be called with start_message' )
108
108
if self ._length < 5 :
109
- raise exceptions. BufferError(' end_message: buffer is too small' )
109
+ raise BufferError(' end_message: buffer is too small' )
110
110
if mlen > _MAXINT32:
111
- raise exceptions. BufferError(' end_message: message is too large' )
111
+ raise BufferError(' end_message: message is too large' )
112
112
113
113
hton.pack_int32(& self ._buf[1 ], < int32_t> mlen)
114
114
return self
@@ -164,7 +164,7 @@ cdef class WriteBuffer:
164
164
165
165
cpython.PyBytes_AsStringAndSize(data, & buf, & size)
166
166
if size > _MAXINT32:
167
- raise exceptions. BufferError(' string is too large' )
167
+ raise BufferError(' string is too large' )
168
168
# `size` does not account for the NULL at the end.
169
169
self .write_int32(< int32_t> size)
170
170
self .write_cstr(buf, size)
@@ -252,7 +252,7 @@ cdef class ReadBuffer:
252
252
bytes data_bytes
253
253
254
254
if not cpython.PyBytes_CheckExact(data):
255
- raise exceptions. BufferError(' feed_data: bytes object expected' )
255
+ raise BufferError(' feed_data: bytes object expected' )
256
256
257
257
# Uncomment the below code to test code paths that
258
258
# read single int/str/bytes sequences are split over
@@ -284,9 +284,9 @@ cdef class ReadBuffer:
284
284
cdef inline _ensure_first_buf(self ):
285
285
if PG_DEBUG:
286
286
if self ._len0 == 0 :
287
- raise exceptions. BufferError(' empty first buffer' )
287
+ raise BufferError(' empty first buffer' )
288
288
if self ._length == 0 :
289
- raise exceptions. BufferError(' empty buffer' )
289
+ raise BufferError(' empty buffer' )
290
290
291
291
if self ._pos0 == self ._len0:
292
292
self ._switch_to_next_buf()
@@ -306,7 +306,7 @@ cdef class ReadBuffer:
306
306
307
307
if PG_DEBUG:
308
308
if self ._len0 < 1 :
309
- raise exceptions. BufferError(
309
+ raise BufferError(
310
310
' debug: second buffer of ReadBuffer is empty' )
311
311
312
312
cdef inline const char * _try_read_bytes(self , ssize_t nbytes):
@@ -394,13 +394,13 @@ cdef class ReadBuffer:
394
394
return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
395
395
396
396
if nbytes > self ._length:
397
- raise exceptions. BufferError(
397
+ raise BufferError(
398
398
' not enough data to read {} bytes' .format(nbytes))
399
399
400
400
if self ._current_message_ready:
401
401
self ._current_message_len_unread -= nbytes
402
402
if self ._current_message_len_unread < 0 :
403
- raise exceptions. BufferError(' buffer overread' )
403
+ raise BufferError(' buffer overread' )
404
404
405
405
result = cpython.PyBytes_FromStringAndSize(NULL , nbytes)
406
406
buf = cpython.PyBytes_AS_STRING(result)
@@ -410,7 +410,7 @@ cdef class ReadBuffer:
410
410
cdef bytes read_len_prefixed_bytes(self ):
411
411
cdef int32_t size = self .read_int32()
412
412
if size < 0 :
413
- raise exceptions. BufferError(
413
+ raise BufferError(
414
414
' negative length for a len-prefixed bytes value' )
415
415
if size == 0 :
416
416
return b' '
@@ -423,7 +423,7 @@ cdef class ReadBuffer:
423
423
424
424
size = self .read_int32()
425
425
if size < 0 :
426
- raise exceptions. BufferError(
426
+ raise BufferError(
427
427
' negative length for a len-prefixed bytes value' )
428
428
429
429
if size == 0 :
@@ -453,13 +453,13 @@ cdef class ReadBuffer:
453
453
454
454
if PG_DEBUG:
455
455
if not self ._buf0:
456
- raise exceptions. BufferError(
456
+ raise BufferError(
457
457
' debug: first buffer of ReadBuffer is empty' )
458
458
459
459
self ._ensure_first_buf()
460
460
first_byte = self ._try_read_bytes(1 )
461
461
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' )
463
463
464
464
return first_byte[0 ]
465
465
@@ -504,7 +504,7 @@ cdef class ReadBuffer:
504
504
505
505
cdef inline read_null_str(self ):
506
506
if not self ._current_message_ready:
507
- raise exceptions. BufferError(
507
+ raise BufferError(
508
508
' read_null_str only works when the message guaranteed '
509
509
' to be in the buffer' )
510
510
@@ -542,7 +542,7 @@ cdef class ReadBuffer:
542
542
543
543
self ._current_message_len_unread -= nread
544
544
if self ._current_message_len_unread < 0 :
545
- raise exceptions. BufferError(
545
+ raise BufferError(
546
546
' read_null_str: buffer overread' )
547
547
548
548
return result
@@ -555,7 +555,7 @@ cdef class ReadBuffer:
555
555
556
556
self ._current_message_len_unread -= nread
557
557
if self ._current_message_len_unread < 0 :
558
- raise exceptions. BufferError(
558
+ raise BufferError(
559
559
' read_null_str: buffer overread' )
560
560
561
561
self ._ensure_first_buf()
@@ -573,7 +573,7 @@ cdef class ReadBuffer:
573
573
self ._ensure_first_buf()
574
574
cbuf = self ._try_read_bytes(1 )
575
575
if cbuf == NULL :
576
- raise exceptions. BufferError(
576
+ raise BufferError(
577
577
' failed to read one byte on a non-empty buffer' )
578
578
self ._current_message_type = cbuf[0 ]
579
579
@@ -611,7 +611,7 @@ cdef class ReadBuffer:
611
611
612
612
cdef int32_t put_message(self ) except - 1 :
613
613
if not self ._current_message_ready:
614
- raise exceptions. BufferError(
614
+ raise BufferError(
615
615
' cannot put message: no message taken' )
616
616
self ._current_message_ready = False
617
617
return 0
@@ -634,15 +634,15 @@ cdef class ReadBuffer:
634
634
635
635
cdef discard_message(self ):
636
636
if not self ._current_message_ready:
637
- raise exceptions. BufferError(' no message to discard' )
637
+ raise BufferError(' no message to discard' )
638
638
if self ._current_message_len_unread > 0 :
639
639
self ._read_and_discard(self ._current_message_len_unread)
640
640
self ._current_message_len_unread = 0
641
641
self ._finish_message()
642
642
643
643
cdef bytes consume_message(self ):
644
644
if not self ._current_message_ready:
645
- raise exceptions. BufferError(' no message to consume' )
645
+ raise BufferError(' no message to consume' )
646
646
if self ._current_message_len_unread > 0 :
647
647
mem = self .read_bytes(self ._current_message_len_unread)
648
648
else :
@@ -653,14 +653,14 @@ cdef class ReadBuffer:
653
653
cdef redirect_messages(self , WriteBuffer buf, char mtype,
654
654
int stop_at = 0 ):
655
655
if not self ._current_message_ready:
656
- raise exceptions. BufferError(
656
+ raise BufferError(
657
657
' consume_full_messages called on a buffer without a '
658
658
' complete first message' )
659
659
if mtype != self ._current_message_type:
660
- raise exceptions. BufferError(
660
+ raise BufferError(
661
661
' consume_full_messages called with a wrong mtype' )
662
662
if self ._current_message_len_unread != self ._current_message_len - 4 :
663
- raise exceptions. BufferError(
663
+ raise BufferError(
664
664
' consume_full_messages called on a partially read message' )
665
665
666
666
cdef:
0 commit comments