88class Error (Exception ):
99 """
1010 Raised whenever an error is encountered with compressing or decompressing
11- data using brotlipy .
11+ data using brotlicffi .
1212
1313 .. versionadded:: 0.5.1
1414 """
1515 pass
1616
1717
18- #: An alias of :class:`Error <brotli .Error>` that exists for compatibility with
19- #: the original C brotli module.
18+ #: An alias of :class:`Error <brotlicffi .Error>` that
19+ #: exists for compatibility with the original C brotli module.
2020#:
2121#: .. versionadded: 0.5.1
2222error = Error
@@ -51,7 +51,7 @@ class BrotliEncoderMode(enum.IntEnum):
5151#: .. note:: This name is defined for compatibility with the Brotli C
5252#: extension. If you're not interested in that compatibility, it is
5353#: recommended that you use :class:`BrotliEncoderMode
54- #: <brotli .BrotliEncoderMode>` instead.
54+ #: <brotlicffi .BrotliEncoderMode>` instead.
5555#:
5656#: .. versionadded:: 0.5.0
5757MODE_GENERIC = BrotliEncoderMode .GENERIC
@@ -62,7 +62,7 @@ class BrotliEncoderMode(enum.IntEnum):
6262#: .. note:: This name is defined for compatibility with the Brotli C
6363#: extension. If you're not interested in that compatibility, it is
6464#: recommended that you use :class:`BrotliEncoderMode
65- #: <brotli .BrotliEncoderMode>` instead.
65+ #: <brotlicffi .BrotliEncoderMode>` instead.
6666#:
6767#: .. versionadded:: 0.5.0
6868MODE_TEXT = BrotliEncoderMode .TEXT
@@ -73,7 +73,7 @@ class BrotliEncoderMode(enum.IntEnum):
7373#: .. note:: This name is defined for compatibility with the Brotli C
7474#: extension. If you're not interested in that compatibility, it is
7575#: recommended that you use :class:`BrotliEncoderMode
76- #: <brotli .BrotliEncoderMode>` instead.
76+ #: <brotlicffi .BrotliEncoderMode>` instead.
7777#:
7878#: .. versionadded:: 0.5.0
7979MODE_FONT = BrotliEncoderMode .FONT
@@ -194,7 +194,7 @@ def _validate_lgblock(val):
194194def _set_parameter (encoder , parameter , parameter_name , val ):
195195 """
196196 This helper function sets a specific Brotli encoder parameter, checking
197- the return code and raising :class:`Error <brotli .Error>` if it is
197+ the return code and raising :class:`Error <brotlicffi .Error>` if it is
198198 invalid.
199199 """
200200 rc = lib .BrotliEncoderSetParameter (encoder , parameter , val )
@@ -333,8 +333,7 @@ def flush(self):
333333 will not destroy the compressor. It can be used, for example, to ensure
334334 that given chunks of content will decompress immediately.
335335 """
336- chunks = []
337- chunks .append (self ._compress (b'' , lib .BROTLI_OPERATION_FLUSH ))
336+ chunks = [self ._compress (b'' , lib .BROTLI_OPERATION_FLUSH )]
338337
339338 while lib .BrotliEncoderHasMoreOutput (self ._encoder ) == lib .BROTLI_TRUE :
340339 chunks .append (self ._compress (b'' , lib .BROTLI_OPERATION_FLUSH ))
@@ -460,7 +459,14 @@ def finish(self):
460459 assert (
461460 lib .BrotliDecoderHasMoreOutput (self ._decoder ) == lib .BROTLI_FALSE
462461 )
463- if lib . BrotliDecoderIsFinished ( self ._decoder ) == lib . BROTLI_FALSE :
462+ if not self .is_finished () :
464463 raise Error ("Decompression error: incomplete compressed stream." )
465464
466465 return b''
466+
467+ def is_finished (self ):
468+ """
469+ Returns ``True`` if the decompression stream
470+ is complete, ``False`` otherwise
471+ """
472+ return lib .BrotliDecoderIsFinished (self ._decoder ) == lib .BROTLI_TRUE
0 commit comments