55from ._brotlicffi import ffi , lib
66
77
8- class Error (Exception ):
8+ class error (Exception ):
99 """
1010 Raised whenever an error is encountered with compressing or decompressing
1111 data using brotlicffi.
@@ -15,11 +15,11 @@ class Error(Exception):
1515 pass
1616
1717
18- #: An alias of :class:`Error <brotlicffi.Error >` that
19- #: exists for compatibility with the original C brotli module.
18+ #: An alias of :class:`error <brotli.error >` that
19+ #: exists for compatibility with the original CFFI brotli module.
2020#:
21- #: .. versionadded: 0.5.1
22- error = Error
21+ #: .. versionadded: 0.8.0
22+ Error = error
2323
2424
2525class BrotliEncoderMode (enum .IntEnum ):
@@ -159,15 +159,15 @@ def _validate_mode(val):
159159 try :
160160 val = BrotliEncoderMode (val )
161161 except ValueError :
162- raise Error ("%s is not a valid encoder mode" % val )
162+ raise error ("%s is not a valid encoder mode" % val )
163163
164164
165165def _validate_quality (val ):
166166 """
167167 Validate that the quality setting is valid.
168168 """
169169 if not (0 <= val <= 11 ):
170- raise Error (
170+ raise error (
171171 "%d is not a valid quality, must be between 0 and 11" % val
172172 )
173173
@@ -177,15 +177,15 @@ def _validate_lgwin(val):
177177 Validate that the lgwin setting is valid.
178178 """
179179 if not (10 <= val <= 24 ):
180- raise Error ("%d is not a valid lgwin, must be between 10 and 24" % val )
180+ raise error ("%d is not a valid lgwin, must be between 10 and 24" % val )
181181
182182
183183def _validate_lgblock (val ):
184184 """
185185 Validate that the lgblock setting is valid.
186186 """
187187 if (val != 0 ) and not (16 <= val <= 24 ):
188- raise Error (
188+ raise error (
189189 "%d is not a valid lgblock, must be either 0 or between 16 and 24"
190190 % val
191191 )
@@ -214,7 +214,7 @@ def _set_parameter(encoder, parameter, parameter_name, val):
214214 # function returns a value we can live in hope that the brotli folks will
215215 # enforce their own constraints.
216216 if rc != lib .BROTLI_TRUE : # pragma: no cover
217- raise Error (
217+ raise error (
218218 "Error setting parameter %s: %d" % (parameter_name , val )
219219 )
220220
@@ -309,7 +309,7 @@ def _compress(self, data, operation):
309309 ffi .NULL
310310 )
311311 if rc != lib .BROTLI_TRUE : # pragma: no cover
312- raise Error ("Error encountered compressing data." )
312+ raise error ("Error encountered compressing data." )
313313
314314 assert not input_size [0 ]
315315
@@ -327,6 +327,8 @@ def compress(self, data):
327327 """
328328 return self ._compress (data , lib .BROTLI_OPERATION_PROCESS )
329329
330+ process = compress
331+
330332 def flush (self ):
331333 """
332334 Flush the compressor. This will emit the remaining output data, but
@@ -414,7 +416,7 @@ def decompress(self, data):
414416 if rc == lib .BROTLI_DECODER_RESULT_ERROR :
415417 error_code = lib .BrotliDecoderGetErrorCode (self ._decoder )
416418 error_message = lib .BrotliDecoderErrorString (error_code )
417- raise Error (
419+ raise error (
418420 "Decompression error: %s" % ffi .string (error_message )
419421 )
420422
@@ -433,6 +435,8 @@ def decompress(self, data):
433435
434436 return b'' .join (chunks )
435437
438+ process = decompress
439+
436440 def flush (self ):
437441 """
438442 Complete the decompression, return whatever data is remaining to be
@@ -460,7 +464,7 @@ def finish(self):
460464 lib .BrotliDecoderHasMoreOutput (self ._decoder ) == lib .BROTLI_FALSE
461465 )
462466 if not self .is_finished ():
463- raise Error ("Decompression error: incomplete compressed stream." )
467+ raise error ("Decompression error: incomplete compressed stream." )
464468
465469 return b''
466470
0 commit comments