Skip to content

Commit afb4700

Browse files
committed
adjust locking once more
1 parent bf935be commit afb4700

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/brotlicffi/_api.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,17 +430,6 @@ def decompress(self, data, output_buffer_limit=None):
430430
:type output_buffer_limit: ``int`` or ``None``
431431
:returns: A bytestring containing the decompressed data.
432432
"""
433-
if self._unconsumed_data and data:
434-
raise error(
435-
"brotli: decoder process called with data when "
436-
"'can_accept_more_data()' is False"
437-
)
438-
439-
# We should avoid operations on the `self._unconsumed_data` if no data
440-
# is to be processed.
441-
if output_buffer_limit is not None and output_buffer_limit <= 0:
442-
return b''
443-
444433
if not self.lock.acquire(blocking=False):
445434
raise error(
446435
"Concurrently sharing Decompressor instances is not allowed")
@@ -451,6 +440,16 @@ def decompress(self, data, output_buffer_limit=None):
451440
return b''.join(chunks)
452441

453442
def _decompress(self, data, output_buffer_limit):
443+
if self._unconsumed_data and data:
444+
raise error(
445+
"brotli: decoder process called with data when "
446+
"'can_accept_more_data()' is False"
447+
)
448+
449+
# We should avoid operations on the `self._unconsumed_data` if no data
450+
# is to be processed.
451+
if output_buffer_limit is not None and output_buffer_limit <= 0:
452+
return b''
454453
# Use unconsumed data if available, use new data otherwise.
455454
if self._unconsumed_data:
456455
input_data = self._unconsumed_data

0 commit comments

Comments
 (0)