static-http 0.1.4__tar.gz → 0.1.5__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.
Files changed (24) hide show
  1. {static_http-0.1.4/src/static_http.egg-info → static_http-0.1.5}/PKG-INFO +1 -1
  2. {static_http-0.1.4 → static_http-0.1.5}/pyproject.toml +1 -1
  3. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/__init__.py +1 -1
  4. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/qrcode.py +35 -65
  5. {static_http-0.1.4 → static_http-0.1.5/src/static_http.egg-info}/PKG-INFO +1 -1
  6. {static_http-0.1.4 → static_http-0.1.5}/tests/test_qrcode.py +59 -0
  7. {static_http-0.1.4 → static_http-0.1.5}/LICENSE +0 -0
  8. {static_http-0.1.4 → static_http-0.1.5}/README.md +0 -0
  9. {static_http-0.1.4 → static_http-0.1.5}/setup.cfg +0 -0
  10. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/__main__.py +0 -0
  11. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/cli.py +0 -0
  12. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/keyboard.py +0 -0
  13. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/ranges.py +0 -0
  14. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/server.py +0 -0
  15. {static_http-0.1.4 → static_http-0.1.5}/src/http_here/urls.py +0 -0
  16. {static_http-0.1.4 → static_http-0.1.5}/src/static_http.egg-info/SOURCES.txt +0 -0
  17. {static_http-0.1.4 → static_http-0.1.5}/src/static_http.egg-info/dependency_links.txt +0 -0
  18. {static_http-0.1.4 → static_http-0.1.5}/src/static_http.egg-info/entry_points.txt +0 -0
  19. {static_http-0.1.4 → static_http-0.1.5}/src/static_http.egg-info/requires.txt +0 -0
  20. {static_http-0.1.4 → static_http-0.1.5}/src/static_http.egg-info/top_level.txt +0 -0
  21. {static_http-0.1.4 → static_http-0.1.5}/tests/test_cli.py +0 -0
  22. {static_http-0.1.4 → static_http-0.1.5}/tests/test_ranges.py +0 -0
  23. {static_http-0.1.4 → static_http-0.1.5}/tests/test_server.py +0 -0
  24. {static_http-0.1.4 → static_http-0.1.5}/tests/test_urls.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: static-http
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: A temporary dependency-free static HTTP server with byte-range support.
5
5
  Author: John Paul Ellis
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "static-http"
7
- version = "0.1.4"
7
+ version = "0.1.5"
8
8
  description = "A temporary dependency-free static HTTP server with byte-range support."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,3 +1,3 @@
1
1
  """Utilities for running a dependency-free local static HTTP server."""
2
2
 
3
- __version__ = "0.1.4"
3
+ __version__ = "0.1.5"
@@ -36,37 +36,28 @@ def _gf_mul(x: int, y: int) -> int:
36
36
  return result
37
37
 
38
38
 
39
- def _gf_pow(x: int, power: int) -> int:
40
- result = 1
41
- for _ in range(power):
42
- result = _gf_mul(result, x)
43
- return result
44
-
45
-
46
39
  def _generator_poly(degree: int) -> list[int]:
47
- result = [1]
48
- for i in range(degree):
49
- result = _poly_mul(result, [1, _gf_pow(2, i)])
50
- return result
51
-
52
-
53
- def _poly_mul(left: list[int], right: list[int]) -> list[int]:
54
- result = [0] * (len(left) + len(right) - 1)
55
- for i, left_value in enumerate(left):
56
- for j, right_value in enumerate(right):
57
- result[i + j] ^= _gf_mul(left_value, right_value)
40
+ result = [0] * degree
41
+ result[-1] = 1
42
+ root = 1
43
+ for _ in range(degree):
44
+ for i in range(degree):
45
+ result[i] = _gf_mul(result[i], root)
46
+ if i + 1 < degree:
47
+ result[i] ^= result[i + 1]
48
+ root = _gf_mul(root, 0x02)
58
49
  return result
59
50
 
60
51
 
61
52
  def _reed_solomon(data: list[int], degree: int) -> list[int]:
62
- generator = _generator_poly(degree)
63
- result = data + [0] * degree
64
- for i, value in enumerate(data):
65
- if value == 0:
66
- continue
67
- for j, coefficient in enumerate(generator):
68
- result[i + j] ^= _gf_mul(coefficient, value)
69
- return result[-degree:]
53
+ divisor = _generator_poly(degree)
54
+ result = [0] * degree
55
+ for byte in data:
56
+ factor = byte ^ result.pop(0)
57
+ result.append(0)
58
+ for i, coefficient in enumerate(divisor):
59
+ result[i] ^= _gf_mul(coefficient, factor)
60
+ return result
70
61
 
71
62
 
72
63
  def _append_bits(bits: list[int], value: int, length: int) -> None:
@@ -139,7 +130,6 @@ def _draw_function_patterns(matrix: list[list[bool | None]], function: list[list
139
130
  _set_function(matrix, function, 6, i, i % 2 == 0)
140
131
  _set_function(matrix, function, i, 6, i % 2 == 0)
141
132
 
142
- _set_function(matrix, function, size - 8, 8, True)
143
133
  _draw_format_bits(matrix, function, 0)
144
134
 
145
135
 
@@ -199,44 +189,24 @@ def _format_bits(mask: int) -> int:
199
189
  def _draw_format_bits(matrix: list[list[bool | None]], function: list[list[bool]], mask: int) -> None:
200
190
  bits = _format_bits(mask)
201
191
  size = len(matrix)
202
- positions_a = [
203
- (8, 0),
204
- (8, 1),
205
- (8, 2),
206
- (8, 3),
207
- (8, 4),
208
- (8, 5),
209
- (8, 7),
210
- (8, 8),
211
- (7, 8),
212
- (5, 8),
213
- (4, 8),
214
- (3, 8),
215
- (2, 8),
216
- (1, 8),
217
- (0, 8),
218
- ]
219
- positions_b = [
220
- (size - 1, 8),
221
- (size - 2, 8),
222
- (size - 3, 8),
223
- (size - 4, 8),
224
- (size - 5, 8),
225
- (size - 6, 8),
226
- (size - 7, 8),
227
- (8, size - 8),
228
- (8, size - 7),
229
- (8, size - 6),
230
- (8, size - 5),
231
- (8, size - 4),
232
- (8, size - 3),
233
- (8, size - 2),
234
- (8, size - 1),
235
- ]
236
- for i, (row, col) in enumerate(positions_a):
237
- _set_function(matrix, function, row, col, ((bits >> i) & 1) == 1)
238
- for i, (row, col) in enumerate(positions_b):
239
- _set_function(matrix, function, row, col, ((bits >> i) & 1) == 1)
192
+ for i in range(15):
193
+ dark = ((bits >> i) & 1) == 1
194
+
195
+ if i < 6:
196
+ _set_function(matrix, function, i, 8, dark)
197
+ elif i < 8:
198
+ _set_function(matrix, function, i + 1, 8, dark)
199
+ else:
200
+ _set_function(matrix, function, size - 15 + i, 8, dark)
201
+
202
+ if i < 8:
203
+ _set_function(matrix, function, 8, size - i - 1, dark)
204
+ elif i == 8:
205
+ _set_function(matrix, function, 8, 7, dark)
206
+ else:
207
+ _set_function(matrix, function, 8, 14 - i, dark)
208
+
209
+ _set_function(matrix, function, size - 8, 8, True)
240
210
 
241
211
 
242
212
  def _penalty(matrix: list[list[bool | None]]) -> int:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: static-http
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: A temporary dependency-free static HTTP server with byte-range support.
5
5
  Author: John Paul Ellis
6
6
  License-Expression: MIT
@@ -45,6 +45,65 @@ def test_qr_known_format_bits_and_version_selection() -> None:
45
45
  assert len(qrcode._build_matrix("http://192.168.1.205:8080/")) == 25
46
46
 
47
47
 
48
+ def test_reed_solomon_matches_known_version_2_l_codewords() -> None:
49
+ data = qrcode._encode_data(b"http://localhost:8080/", 2)
50
+
51
+ assert data == [
52
+ 65,
53
+ 102,
54
+ 135,
55
+ 71,
56
+ 71,
57
+ 3,
58
+ 162,
59
+ 242,
60
+ 246,
61
+ 198,
62
+ 246,
63
+ 54,
64
+ 22,
65
+ 198,
66
+ 134,
67
+ 247,
68
+ 55,
69
+ 67,
70
+ 163,
71
+ 131,
72
+ 3,
73
+ 131,
74
+ 2,
75
+ 240,
76
+ 236,
77
+ 17,
78
+ 236,
79
+ 17,
80
+ 236,
81
+ 17,
82
+ 236,
83
+ 17,
84
+ 236,
85
+ 17,
86
+ ]
87
+ assert qrcode._reed_solomon(data, qrcode._ECC_CODEWORDS[2]) == [224, 235, 163, 25, 95, 161, 5, 47, 66, 94]
88
+
89
+
90
+ def test_format_bits_use_dark_module_and_second_copy_positions() -> None:
91
+ size = 25
92
+ matrix = [[None for _ in range(size)] for _ in range(size)]
93
+ function = [[False for _ in range(size)] for _ in range(size)]
94
+
95
+ qrcode._draw_function_patterns(matrix, function, 2)
96
+ qrcode._draw_format_bits(matrix, function, 4)
97
+ bits = qrcode._format_bits(4)
98
+
99
+ assert matrix[size - 8][8] is True
100
+ assert matrix[0][8] == bool(bits & 1)
101
+ assert matrix[8][size - 1] == bool(bits & 1)
102
+ assert matrix[8][7] == bool((bits >> 8) & 1)
103
+ assert matrix[size - 1][8] == bool(bits & 1)
104
+ assert function[size - 8][8] is True
105
+
106
+
48
107
  def test_qr_warns_when_terminal_too_narrow() -> None:
49
108
  fake_size = namedtuple("Size", "columns lines")(20, 24)
50
109
  monkeypatch = pytest.MonkeyPatch()
File without changes
File without changes
File without changes