Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# BrotliCFFI documentation build configuration file, created by
# sphinx-quickstart on Sat Oct 3 16:51:16 2015.
Expand Down Expand Up @@ -50,9 +49,9 @@
master_doc = 'index'

# General information about the project.
project = u'brotlicffi'
copyright = u'%d, Cory Benfield' % (datetime.date.today().year,)
author = u'Cory Benfield'
project = 'brotlicffi'
copyright = f'{datetime.date.today():%Y}, Cory Benfield'
author = 'Cory Benfield'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -226,8 +225,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'BrotliCFFI.tex', u'BrotliCFFI Documentation',
u'Cory Benfield', 'manual'),
(master_doc, 'BrotliCFFI.tex', 'BrotliCFFI Documentation',
'Cory Benfield', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -256,7 +255,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'BrotliCFFI', u'BrotliCFFI Documentation',
(master_doc, 'BrotliCFFI', 'BrotliCFFI Documentation',
[author], 1)
]

Expand All @@ -270,7 +269,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'BrotliCFFI', u'BrotliCFFI Documentation',
(master_doc, 'BrotliCFFI', 'BrotliCFFI Documentation',
author, 'BrotliCFFI', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self):
if not bool(sysconfig.get_config_var("Py_GIL_DISABLED")):
class BDistWheel(wheel.bdist_wheel.bdist_wheel):
def finalize_options(self):
self.py_limited_api = "cp3{}".format(sys.version_info[1])
self.py_limited_api = f"cp3{sys.version_info[1]}"
wheel.bdist_wheel.bdist_wheel.finalize_options(self)
cmdclass['bdist_wheel'] = BDistWheel

Expand Down
33 changes: 14 additions & 19 deletions src/brotlicffi/_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import math
import enum
import threading
Expand Down Expand Up @@ -153,25 +152,23 @@ def _validate_mode(val):
try:
val = BrotliEncoderMode(val)
except ValueError:
raise error("%s is not a valid encoder mode" % val)
raise error(f"{val} is not a valid encoder mode")


def _validate_quality(val):
"""
Validate that the quality setting is valid.
"""
if not (0 <= val <= 11):
raise error(
"%d is not a valid quality, must be between 0 and 11" % val
)
raise error(f"{val} is not a valid quality, must be between 0 and 11")


def _validate_lgwin(val):
"""
Validate that the lgwin setting is valid.
"""
if not (10 <= val <= 24):
raise error("%d is not a valid lgwin, must be between 10 and 24" % val)
raise error(f"{val} is not a valid lgwin, must be between 10 and 24")


def _validate_lgblock(val):
Expand All @@ -180,8 +177,8 @@ def _validate_lgblock(val):
"""
if (val != 0) and not (16 <= val <= 24):
raise error(
"%d is not a valid lgblock, must be either 0 or between 16 and 24"
% val
f"{val} is not a valid lgblock, must be either 0 or between 16 "
"and 24"
)


Expand All @@ -208,12 +205,10 @@ def _set_parameter(encoder, parameter, parameter_name, val):
# function returns a value we can live in hope that the brotli folks will
# enforce their own constraints.
if rc != lib.BROTLI_TRUE: # pragma: no cover
raise error(
"Error setting parameter %s: %d" % (parameter_name, val)
)
raise error(f"Error setting parameter {parameter_name}: {val}")


class Compressor(object):
class Compressor:
"""
An object that allows for streaming compression of data using the Brotli
compression algorithm.
Expand Down Expand Up @@ -334,8 +329,8 @@ def flush(self):
try:
chunks = [self._compress(b'', lib.BROTLI_OPERATION_FLUSH)]

while ((lib.BrotliEncoderHasMoreOutput(self._encoder) ==
lib.BROTLI_TRUE)):
while (lib.BrotliEncoderHasMoreOutput(self._encoder) ==
lib.BROTLI_TRUE):
chunks.append(self._compress(b'', lib.BROTLI_OPERATION_FLUSH))
finally:
self.lock.release()
Expand All @@ -352,15 +347,15 @@ def finish(self):
"Concurrently sharing Compressor objects is not allowed")
try:
chunks = []
while ((lib.BrotliEncoderIsFinished(self._encoder) ==
lib.BROTLI_FALSE)):
while (lib.BrotliEncoderIsFinished(self._encoder) ==
lib.BROTLI_FALSE):
chunks.append(self._compress(b'', lib.BROTLI_OPERATION_FINISH))
finally:
self.lock.release()
return b''.join(chunks)


class Decompressor(object):
class Decompressor:
"""
An object that allows for streaming decompression of Brotli-compressed
data.
Expand Down Expand Up @@ -595,8 +590,8 @@ def can_accept_more_data(self):
ret = True
if len(self._unconsumed_data) > 0:
ret = False
if ((lib.BrotliDecoderHasMoreOutput(self._decoder) ==
lib.BROTLI_TRUE)):
if (lib.BrotliDecoderHasMoreOutput(self._decoder) ==
lib.BROTLI_TRUE):
ret = False
finally:
self.lock.release()
Expand Down
1 change: 0 additions & 1 deletion src/brotlicffi/_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
import sys

Expand Down
1 change: 0 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
import os.path

Expand Down
3 changes: 1 addition & 2 deletions test/test_compatibility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
test_compatibility
~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -36,7 +35,7 @@ def test_brotli_version():
)
)
assert brotlicffi.__version__.startswith(
"%s.%s.%s." % (
"{}.{}.{}.".format(
brotli_versions["MAJOR"],
brotli_versions["MINOR"],
brotli_versions["PATCH"]
Expand Down
1 change: 0 additions & 1 deletion test/test_simple_compression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
test_simple_compression
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion test/test_simple_decompression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
test_simple_decompression
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading