1- # -*- coding: utf-8 -*-
21import math
32import enum
43import threading
@@ -153,25 +152,23 @@ def _validate_mode(val):
153152 try :
154153 val = BrotliEncoderMode (val )
155154 except ValueError :
156- raise error ("%s is not a valid encoder mode" % val )
155+ raise error (f" { val } is not a valid encoder mode" )
157156
158157
159158def _validate_quality (val ):
160159 """
161160 Validate that the quality setting is valid.
162161 """
163162 if not (0 <= val <= 11 ):
164- raise error (
165- "%d is not a valid quality, must be between 0 and 11" % val
166- )
163+ raise error (f"{ val } is not a valid quality, must be between 0 and 11" )
167164
168165
169166def _validate_lgwin (val ):
170167 """
171168 Validate that the lgwin setting is valid.
172169 """
173170 if not (10 <= val <= 24 ):
174- raise error ("%d is not a valid lgwin, must be between 10 and 24" % val )
171+ raise error (f" { val } is not a valid lgwin, must be between 10 and 24" )
175172
176173
177174def _validate_lgblock (val ):
@@ -180,8 +177,7 @@ def _validate_lgblock(val):
180177 """
181178 if (val != 0 ) and not (16 <= val <= 24 ):
182179 raise error (
183- "%d is not a valid lgblock, must be either 0 or between 16 and 24"
184- % val
180+ f"{ val } is not a valid lgblock, must be either 0 or between 16 and 24"
185181 )
186182
187183
@@ -208,12 +204,10 @@ def _set_parameter(encoder, parameter, parameter_name, val):
208204 # function returns a value we can live in hope that the brotli folks will
209205 # enforce their own constraints.
210206 if rc != lib .BROTLI_TRUE : # pragma: no cover
211- raise error (
212- "Error setting parameter %s: %d" % (parameter_name , val )
213- )
207+ raise error (f"Error setting parameter { parameter_name } : { val } " )
214208
215209
216- class Compressor ( object ) :
210+ class Compressor :
217211 """
218212 An object that allows for streaming compression of data using the Brotli
219213 compression algorithm.
@@ -334,8 +328,8 @@ def flush(self):
334328 try :
335329 chunks = [self ._compress (b'' , lib .BROTLI_OPERATION_FLUSH )]
336330
337- while (( lib .BrotliEncoderHasMoreOutput (self ._encoder ) ==
338- lib .BROTLI_TRUE )) :
331+ while (lib .BrotliEncoderHasMoreOutput (self ._encoder ) ==
332+ lib .BROTLI_TRUE ):
339333 chunks .append (self ._compress (b'' , lib .BROTLI_OPERATION_FLUSH ))
340334 finally :
341335 self .lock .release ()
@@ -352,15 +346,15 @@ def finish(self):
352346 "Concurrently sharing Compressor objects is not allowed" )
353347 try :
354348 chunks = []
355- while (( lib .BrotliEncoderIsFinished (self ._encoder ) ==
356- lib .BROTLI_FALSE )) :
349+ while (lib .BrotliEncoderIsFinished (self ._encoder ) ==
350+ lib .BROTLI_FALSE ):
357351 chunks .append (self ._compress (b'' , lib .BROTLI_OPERATION_FINISH ))
358352 finally :
359353 self .lock .release ()
360354 return b'' .join (chunks )
361355
362356
363- class Decompressor ( object ) :
357+ class Decompressor :
364358 """
365359 An object that allows for streaming decompression of Brotli-compressed
366360 data.
@@ -595,8 +589,8 @@ def can_accept_more_data(self):
595589 ret = True
596590 if len (self ._unconsumed_data ) > 0 :
597591 ret = False
598- if (( lib .BrotliDecoderHasMoreOutput (self ._decoder ) ==
599- lib .BROTLI_TRUE )) :
592+ if (lib .BrotliDecoderHasMoreOutput (self ._decoder ) ==
593+ lib .BROTLI_TRUE ):
600594 ret = False
601595 finally :
602596 self .lock .release ()
0 commit comments