falcon-compression 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,23 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: falcon-compression
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Compression middleware for Falcon
5
- Home-page: https://github.com/willnewton/falcon-compression
6
- License: Apache
5
+ License: Apache-2.0
6
+ License-File: LICENSE
7
7
  Author: Will Newton
8
8
  Author-email: will.newton@gmail.com
9
9
  Requires-Python: >=3.9,<4.0
10
- Classifier: License :: Other/Proprietary License
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
11
  Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.10
13
12
  Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
14
19
  Requires-Dist: Brotli (>=1.0.9,<2.0.0)
20
+ Project-URL: Homepage, https://github.com/willnewton/falcon-compression
15
21
  Project-URL: Repository, https://github.com/willnewton/falcon-compression
16
22
  Description-Content-Type: text/markdown
17
23
 
@@ -5,6 +5,7 @@ from .util import wrap_file
5
5
 
6
6
  class BrotliCompressor:
7
7
  encoding = "br"
8
+ priority = 1
8
9
  compression_level = 4
9
10
 
10
11
  def compress(self, data):
@@ -5,6 +5,7 @@ from .util import StreamingBuffer, wrap_file
5
5
 
6
6
  class GzipCompressor:
7
7
  encoding = "gzip"
8
+ priority = 2
8
9
  compression_level = 6
9
10
 
10
11
  def compress(self, data):
@@ -4,7 +4,7 @@ from .gzip import GzipCompressor
4
4
  MIN_SIZE = 200
5
5
 
6
6
 
7
- def parse_q_list(s):
7
+ def parse_q_list(s, priorities):
8
8
  values = []
9
9
  for name in s.split(","):
10
10
  q = 1.0
@@ -16,22 +16,27 @@ def parse_q_list(s):
16
16
  q = 0.0
17
17
  if q == 0.0:
18
18
  continue
19
- values.append((name.strip().lower(), q))
20
- values.sort(key=lambda v: v[1], reverse=True)
19
+ encoding = name.strip().lower()
20
+ if encoding in priorities:
21
+ values.append((encoding, priorities[encoding], q))
22
+ values.sort(key=lambda v: v[1])
23
+ values.sort(key=lambda v: v[2], reverse=True)
21
24
  return [v[0] for v in values]
22
25
 
23
26
 
24
27
  class CompressionMiddleware:
25
28
  def __init__(self):
26
29
  self._compressors = {}
30
+ self._priorities = {}
27
31
  self._add_compressor(GzipCompressor())
28
32
  self._add_compressor(BrotliCompressor())
29
33
 
30
34
  def _add_compressor(self, compressor):
35
+ self._priorities[compressor.encoding] = compressor.priority
31
36
  self._compressors[compressor.encoding] = compressor
32
37
 
33
38
  def _get_compressor(self, accept_encoding):
34
- for encoding in parse_q_list(accept_encoding):
39
+ for encoding in parse_q_list(accept_encoding, self._priorities):
35
40
  compressor = self._compressors.get(encoding)
36
41
  if compressor:
37
42
  return compressor
@@ -1,10 +1,10 @@
1
1
  [tool.poetry]
2
2
  name = "falcon-compression"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "Compression middleware for Falcon"
5
5
  authors = ["Will Newton <will.newton@gmail.com>"]
6
6
  readme = "README.md"
7
- license = "Apache"
7
+ license = "Apache-2.0"
8
8
  homepage = "https://github.com/willnewton/falcon-compression"
9
9
  repository = "https://github.com/willnewton/falcon-compression"
10
10
  include = [
@@ -15,10 +15,10 @@ include = [
15
15
  python = "^3.9"
16
16
  Brotli = "^1.0.9"
17
17
 
18
- [tool.poetry.dev-dependencies]
19
- pytest = ">=6.2.5"
20
- falcon = "^3.1.0"
21
- pytest-benchmark = "^3.4.1"
18
+ [tool.poetry.group.test.dependencies]
19
+ pytest = "^8.0"
20
+ falcon = "^4.4.0"
21
+ pytest-benchmark = "^5.2.0"
22
22
  pytest-cov = "^3.0.0"
23
23
 
24
24
  [build-system]
@@ -1,30 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from setuptools import setup
3
-
4
- packages = \
5
- ['falcon_compression']
6
-
7
- package_data = \
8
- {'': ['*']}
9
-
10
- install_requires = \
11
- ['Brotli>=1.0.9,<2.0.0']
12
-
13
- setup_kwargs = {
14
- 'name': 'falcon-compression',
15
- 'version': '0.2.0',
16
- 'description': 'Compression middleware for Falcon',
17
- 'long_description': '\n# Falcon Compression Middleware\n\nMiddleware to apply content compression to Falcon responses.\n',
18
- 'author': 'Will Newton',
19
- 'author_email': 'will.newton@gmail.com',
20
- 'maintainer': None,
21
- 'maintainer_email': None,
22
- 'url': 'https://github.com/willnewton/falcon-compression',
23
- 'packages': packages,
24
- 'package_data': package_data,
25
- 'install_requires': install_requires,
26
- 'python_requires': '>=3.9,<4.0',
27
- }
28
-
29
-
30
- setup(**setup_kwargs)