flexablelib 3.7.1__tar.gz → 3.7.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.
Files changed (132) hide show
  1. {flexablelib-3.7.1 → flexablelib-3.7.2}/CHANGELOG.md +32 -0
  2. {flexablelib-3.7.1 → flexablelib-3.7.2}/PKG-INFO +9 -9
  3. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/_frames.py +12 -1
  4. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/_images.py +71 -8
  5. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/table.py +51 -8
  6. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib.egg-info/PKG-INFO +9 -9
  7. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib.egg-info/SOURCES.txt +4 -0
  8. flexablelib-3.7.2/flexablelib.egg-info/requires.txt +35 -0
  9. {flexablelib-3.7.1 → flexablelib-3.7.2}/package.json +1 -1
  10. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/conftest.py +15 -0
  11. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v218_features.py +2 -1
  12. flexablelib-3.7.2/tests/test_v372_ascii.py +120 -0
  13. flexablelib-3.7.2/tests/test_v372_fixes.py +212 -0
  14. flexablelib-3.7.2/tests/test_v372_labels.py +118 -0
  15. flexablelib-3.7.2/tests/test_v372_narrow.py +70 -0
  16. flexablelib-3.7.1/flexablelib.egg-info/requires.txt +0 -35
  17. {flexablelib-3.7.1 → flexablelib-3.7.2}/.coveragerc +0 -0
  18. {flexablelib-3.7.1 → flexablelib-3.7.2}/LICENSE +0 -0
  19. {flexablelib-3.7.1 → flexablelib-3.7.2}/MANIFEST.in +0 -0
  20. {flexablelib-3.7.1 → flexablelib-3.7.2}/README.md +0 -0
  21. {flexablelib-3.7.1 → flexablelib-3.7.2}/examples/admin.py +0 -0
  22. {flexablelib-3.7.1 → flexablelib-3.7.2}/examples/dashboard.py +0 -0
  23. {flexablelib-3.7.1 → flexablelib-3.7.2}/examples/keys.py +0 -0
  24. {flexablelib-3.7.1 → flexablelib-3.7.2}/examples/video/demo.py +0 -0
  25. {flexablelib-3.7.1 → flexablelib-3.7.2}/examples/video/render.py +0 -0
  26. {flexablelib-3.7.1 → flexablelib-3.7.2}/examples/video/scenes.py +0 -0
  27. {flexablelib-3.7.1 → flexablelib-3.7.2}/examples/video/thumbnail.py +0 -0
  28. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/__init__.py +0 -0
  29. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/_legacy/__init__.py +0 -0
  30. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/_legacy/screen.py +0 -0
  31. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/_legacy/widgets.py +0 -0
  32. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/_speedups.c +0 -0
  33. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/_width_tables.h +0 -0
  34. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/box_topology.py +0 -0
  35. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/cells.py +0 -0
  36. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/colors.py +0 -0
  37. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/columns.py +0 -0
  38. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/fast.py +0 -0
  39. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/identifiers.py +0 -0
  40. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/layout.py +0 -0
  41. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/merges.py +0 -0
  42. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/options.py +0 -0
  43. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/py.typed +0 -0
  44. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/readers.py +0 -0
  45. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/screen.py +0 -0
  46. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/style_compositions.py +0 -0
  47. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/table_strings.py +0 -0
  48. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/text_width.py +0 -0
  49. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/utils.py +0 -0
  50. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/widgets.py +0 -0
  51. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib/writers.py +0 -0
  52. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib.egg-info/dependency_links.txt +0 -0
  53. {flexablelib-3.7.1 → flexablelib-3.7.2}/flexablelib.egg-info/top_level.txt +0 -0
  54. {flexablelib-3.7.1 → flexablelib-3.7.2}/pytest.ini +0 -0
  55. {flexablelib-3.7.1 → flexablelib-3.7.2}/setup.cfg +0 -0
  56. {flexablelib-3.7.1 → flexablelib-3.7.2}/setup.py +0 -0
  57. {flexablelib-3.7.1 → flexablelib-3.7.2}/style_examples.md +0 -0
  58. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/helpers.py +0 -0
  59. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_align_indicators.py +0 -0
  60. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_box_topology.py +0 -0
  61. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_cells.py +0 -0
  62. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_columns.py +0 -0
  63. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_excel.py +0 -0
  64. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_features.py +0 -0
  65. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_issues.py +0 -0
  66. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_merge_edge_matrix.py +0 -0
  67. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_merge_fill.py +0 -0
  68. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_merges.py +0 -0
  69. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_public_api_edges.py +0 -0
  70. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_readme_examples.py +0 -0
  71. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_stress_matrix.py +0 -0
  72. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_style_line_widths.py +0 -0
  73. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_styles.py +0 -0
  74. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_text_width.py +0 -0
  75. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_two_pass_measurement.py +0 -0
  76. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_upstream_issues.py +0 -0
  77. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v2021_fixes.py +0 -0
  78. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v210_rows_copy.py +0 -0
  79. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v2110_fixes.py +0 -0
  80. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v211_fixes.py +0 -0
  81. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v213_features.py +0 -0
  82. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v214_features.py +0 -0
  83. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v215_features.py +0 -0
  84. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v216_features.py +0 -0
  85. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v217_features.py +0 -0
  86. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v219_coverage.py +0 -0
  87. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v219_fixes.py +0 -0
  88. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v220_exports.py +0 -0
  89. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v221_fixes.py +0 -0
  90. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v222_fixes.py +0 -0
  91. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v223_fixes.py +0 -0
  92. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v224_fixes.py +0 -0
  93. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v230_none.py +0 -0
  94. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v231_fixes.py +0 -0
  95. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v232_merge_ansi.py +0 -0
  96. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v300_style_names.py +0 -0
  97. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v310_layout.py +0 -0
  98. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v320_tui.py +0 -0
  99. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v330_components.py +0 -0
  100. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v330_frames.py +0 -0
  101. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v330_layout.py +0 -0
  102. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v330_tui.py +0 -0
  103. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v331_formats.py +0 -0
  104. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v331_panel_width.py +0 -0
  105. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v331_readers_bom.py +0 -0
  106. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v331_readers_edges.py +0 -0
  107. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v331_tabs.py +0 -0
  108. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v340_accessibility.py +0 -0
  109. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v340_core.py +0 -0
  110. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v340_input.py +0 -0
  111. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v350_images.py +0 -0
  112. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v350_images_core.py +0 -0
  113. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v352_fixes.py +0 -0
  114. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v353_fixes.py +0 -0
  115. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v354_fixes.py +0 -0
  116. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v355_fixes.py +0 -0
  117. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v360_features.py +0 -0
  118. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v370_features.py +0 -0
  119. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/test_v371_fixes.py +0 -0
  120. {flexablelib-3.7.1 → flexablelib-3.7.2}/tests/wincon_child.py +0 -0
  121. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/bench_frames.py +0 -0
  122. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/bench_images.py +0 -0
  123. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/benchmark.py +0 -0
  124. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/gen_ascii_table.py +0 -0
  125. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/generate_width_tables.py +0 -0
  126. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/image_demo.py +0 -0
  127. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/pty_check.py +0 -0
  128. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/readme_gallery.py +0 -0
  129. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/stress_matrix.py +0 -0
  130. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/style_examples.py +0 -0
  131. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/text_to_png.py +0 -0
  132. {flexablelib-3.7.1 → flexablelib-3.7.2}/tools/wheel_check.py +0 -0
@@ -2,6 +2,38 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.7.2] - 2026-11-17
6
+
7
+ ### Fixed
8
+ - **Damaged or hostile images** read by the built-in decoders (PNG, GIF,
9
+ BMP, PNM -- used without Pillow, or when Pillow gives up on one of
10
+ those formats): a bad pixel token, a cut header, a palette or block that
11
+ points past the data, an unknown bit depth or interlace method now
12
+ raise `ImageError` (they could raise `ValueError`, `IndexError` or
13
+ `struct.error`). A header that asks for more than `MAX_PIXELS` pixels
14
+ (Pillow's limit), or for more pixel data than the file holds, is
15
+ refused before any memory is set aside -- a few bytes could ask for
16
+ gigabytes and end the process. The C `unfilter` raises `ImageError`
17
+ like the Python one, also for a row of zero bytes, and the Python
18
+ `quantize` refuses an empty or short image like the C one.
19
+ - **ASCII mode** (`FLEXABLELIB_ASCII=1`): the erase-key, info, plus,
20
+ stopwatch, pause, stop, record, refresh and diagonal-arrow symbols used
21
+ in help lines and status texts get one-column ASCII stand-ins
22
+ (`SignatureInput` showed `⌫`, `Stopwatch` its clock).
23
+ - **Table titles, subtitles and captions** longer than the width the
24
+ table has to fit into (`max_width` or the terminal) wrap at spaces
25
+ instead of running past it, never narrower than the table itself; in
26
+ card mode they keep to the width the cards are rendered at.
27
+ - **`too_narrow_message`** is also shown when the drawn table is still
28
+ wider than the space (a float column keeps the digits in front of its
29
+ point), with `{needed}` the width it took; the overflowing table was
30
+ returned before.
31
+
32
+ ### Tests
33
+ - The suite starts every test with `NO_COLOR` and `FORCE_COLOR` unset, so
34
+ it gives the same result whatever the shell exports and no test leaks
35
+ colour into the next.
36
+
5
37
  ## [3.7.1] - 2026-11-16
6
38
 
7
39
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 3.7.1
3
+ Version: 3.7.2
4
4
  Summary: Fast, dependency-free terminal tables for Python: 54 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Author: Benjamin Ramirez
@@ -46,15 +46,15 @@ Requires-Dist: openpyxl>=3.0; extra == "excel"
46
46
  Provides-Extra: html
47
47
  Requires-Dist: lxml>=4.0; extra == "html"
48
48
  Provides-Extra: tui
49
- Requires-Dist: flexablelib-tui==3.7.1; extra == "tui"
49
+ Requires-Dist: flexablelib-tui==3.7.2; extra == "tui"
50
50
  Provides-Extra: components
51
- Requires-Dist: flexablelib-components==3.7.1; extra == "components"
51
+ Requires-Dist: flexablelib-components==3.7.2; extra == "components"
52
52
  Provides-Extra: speed
53
- Requires-Dist: flexablelib-speedups==3.7.1; extra == "speed"
53
+ Requires-Dist: flexablelib-speedups==3.7.2; extra == "speed"
54
54
  Provides-Extra: images
55
55
  Requires-Dist: Pillow>=8; extra == "images"
56
- Requires-Dist: flexablelib-tui==3.7.1; extra == "images"
57
- Requires-Dist: flexablelib-components==3.7.1; extra == "images"
56
+ Requires-Dist: flexablelib-tui==3.7.2; extra == "images"
57
+ Requires-Dist: flexablelib-components==3.7.2; extra == "images"
58
58
  Provides-Extra: svg
59
59
  Requires-Dist: cairosvg>=2.5; extra == "svg"
60
60
  Provides-Extra: all
@@ -62,9 +62,9 @@ Requires-Dist: pandas>=1.0; extra == "all"
62
62
  Requires-Dist: openpyxl>=3.0; extra == "all"
63
63
  Requires-Dist: lxml>=4.0; extra == "all"
64
64
  Requires-Dist: Pillow>=8; extra == "all"
65
- Requires-Dist: flexablelib-tui==3.7.1; extra == "all"
66
- Requires-Dist: flexablelib-components==3.7.1; extra == "all"
67
- Requires-Dist: flexablelib-speedups==3.7.1; extra == "all"
65
+ Requires-Dist: flexablelib-tui==3.7.2; extra == "all"
66
+ Requires-Dist: flexablelib-components==3.7.2; extra == "all"
67
+ Requires-Dist: flexablelib-speedups==3.7.2; extra == "all"
68
68
  Dynamic: author
69
69
  Dynamic: author-email
70
70
  Dynamic: classifier
@@ -200,11 +200,22 @@ def _build_ascii_fold():
200
200
  put('↔⇔', '-')
201
201
  put('↕⇕', '|')
202
202
  put('↵⏎↩', '<')
203
+ put('↗↙', '/')
204
+ put('↖↘', '\\')
205
+ put('↻↺⟳⟲', 'o')
206
+ # Keys and media controls in help lines and status texts.
207
+ put('⌫', '<')
208
+ put('⌦', '>')
209
+ put('⏸', '=')
210
+ put('⏹', '#')
211
+ put('⏺', 'o')
212
+ put('⏱⏲', 'o')
203
213
  # Checks, crosses, warnings, stars, ballot boxes.
204
214
  put('✔✓√', '+')
205
215
  put('✖✗✘×', 'x')
206
216
  put('⚠', '!')
207
- put('ℹ', 'i')
217
+ put('ℹⓘ', 'i')
218
+ put('✚', '+')
208
219
  put('★☆✦✧⭑', '*')
209
220
  put('☐', '.')
210
221
  put('☑☒', 'x')
@@ -34,6 +34,22 @@ class ImageError(ValueError):
34
34
  """An image that could not be read, with a reason people can read."""
35
35
 
36
36
 
37
+ # Largest picture the built-in decoders accept, in pixels: the size Pillow
38
+ # refuses as a decompression bomb. A header is only a few bytes, so without a
39
+ # limit a small damaged or hostile file could ask for gigabytes of memory.
40
+ MAX_PIXELS = 178956970
41
+
42
+
43
+ def _check_size(width, height, kind):
44
+ """Refuse a header size that is empty, negative or absurdly large."""
45
+ if width <= 0 or height <= 0:
46
+ raise ImageError('{0} sin tamaño ({1}×{2})'.format(kind, width,
47
+ height))
48
+ if width * height > MAX_PIXELS:
49
+ raise ImageError('imagen demasiado grande ({0}×{1})'.format(
50
+ width, height))
51
+
52
+
37
53
  class Bitmap(object):
38
54
  """``width`` x ``height`` pixels, ``data`` as RGBA bytes, row by row."""
39
55
 
@@ -262,14 +278,29 @@ def decode_png(data):
262
278
  raise ImageError('PNG sin cabecera o sin datos')
263
279
  width, height, depth, ctype, _comp, _filt, interlace = header
264
280
  channels = {0: 1, 2: 3, 3: 1, 4: 2, 6: 4}.get(ctype)
265
- if channels is None or depth not in (1, 2, 4, 8, 16):
281
+ if channels is None or depth not in (1, 2, 4, 8, 16) \
282
+ or interlace not in (0, 1):
266
283
  raise ImageError('PNG no soportado')
267
284
  if ctype == 3 and not palette:
268
285
  raise ImageError('PNG con paleta pero sin PLTE')
286
+ _check_size(width, height, 'PNG')
287
+ # The size the header promises: never inflate more than that, so a
288
+ # small compressed stream cannot fill the memory.
289
+ if interlace:
290
+ expected = 0
291
+ for x0, y0, dx, dy in _ADAM7:
292
+ pw = (width - x0 + dx - 1) // dx
293
+ ph = (height - y0 + dy - 1) // dy
294
+ if pw > 0 and ph > 0:
295
+ expected += ph * ((pw * channels * depth + 7) // 8 + 1)
296
+ else:
297
+ expected = height * ((width * channels * depth + 7) // 8 + 1)
269
298
  try:
270
- raw = zlib.decompress(b''.join(idat))
299
+ raw = zlib.decompressobj().decompress(b''.join(idat), expected)
271
300
  except zlib.error:
272
301
  raise ImageError('PNG dañado')
302
+ if len(raw) < expected:
303
+ raise ImageError('PNG truncado')
273
304
  bpp = max(1, channels * depth // 8)
274
305
  if not interlace:
275
306
  stride = (width * channels * depth + 7) // 8
@@ -354,6 +385,7 @@ def decode_pnm(data):
354
385
  maxval = 1 if bitmap else head[2]
355
386
  except (ValueError, IndexError):
356
387
  raise ImageError('cabecera PNM dañada')
388
+ _check_size(width, height, 'PNM')
357
389
  n = width * height
358
390
  channels = 3 if magic in (b'P3', b'P6') else 1
359
391
  if magic in (b'P4', b'P5', b'P6'):
@@ -381,7 +413,10 @@ def decode_pnm(data):
381
413
  values = raw if maxval == 255 else bytes(
382
414
  min(255, v * 255 // max(1, maxval)) for v in raw)
383
415
  else:
384
- nums, pos = _pnm_tokens(data, n * channels, pos)
416
+ try:
417
+ nums, pos = _pnm_tokens(data, n * channels, pos)
418
+ except ValueError:
419
+ raise ImageError('PNM dañado')
385
420
  if len(nums) < n * channels:
386
421
  raise ImageError('PNM truncado')
387
422
  if bitmap:
@@ -422,9 +457,14 @@ def decode_bmp(data):
422
457
  '<iiHHI', data[18:34])
423
458
  top_down = height < 0
424
459
  height = abs(height)
460
+ _check_size(width, height, 'BMP')
461
+ if bits not in (1, 2, 4, 8, 16, 24, 32):
462
+ raise ImageError('BMP de {0} bits'.format(bits))
425
463
  colors = struct.unpack('<I', data[46:50])[0] if header >= 40 else 0
426
464
  masks = None
427
465
  if compression in (3, 6):
466
+ if len(data) < 70:
467
+ raise ImageError('BMP truncado')
428
468
  masks = struct.unpack('<III', data[54:66])
429
469
  alpha_mask = struct.unpack('<I', data[66:70])[0] if header >= 56 \
430
470
  else 0
@@ -435,10 +475,15 @@ def decode_bmp(data):
435
475
  if bits <= 8:
436
476
  count = colors or (1 << bits)
437
477
  start = 14 + header
438
- for i in range(count):
439
- b, g, r = data[start + i * 4:start + i * 4 + 3]
478
+ for i in range(min(count, 256)):
479
+ entry = data[start + i * 4:start + i * 4 + 3]
480
+ if len(entry) < 3:
481
+ break
482
+ b, g, r = entry
440
483
  palette.append((r, g, b))
441
484
  stride = ((width * bits + 31) // 32) * 4
485
+ if len(data) < offset + stride * height:
486
+ raise ImageError('BMP truncado')
442
487
  out = bytearray(width * height * 4)
443
488
  shifts = [_mask_shift(m) for m in masks] if masks else None
444
489
  for row in range(height):
@@ -520,7 +565,10 @@ def _lzw(data, min_size, count):
520
565
  def decode_gif(data, all_frames=False):
521
566
  if data[:6] not in (b'GIF87a', b'GIF89a'):
522
567
  raise ImageError('no es GIF')
568
+ if len(data) < 13:
569
+ raise ImageError('GIF truncado')
523
570
  width, height, flags = struct.unpack('<HHB', data[6:11])
571
+ _check_size(width, height, 'GIF')
524
572
  pos = 13
525
573
  global_table = None
526
574
  if flags & 0x80:
@@ -550,8 +598,13 @@ def decode_gif(data, all_frames=False):
550
598
  continue
551
599
  if block != 0x2C:
552
600
  raise ImageError('GIF dañado')
601
+ if len(data) < pos + 10:
602
+ raise ImageError('GIF truncado')
553
603
  x0, y0, fw, fh, fflags = struct.unpack('<HHHHB', data[pos:pos + 9])
554
604
  pos += 9
605
+ if fw * fh > MAX_PIXELS:
606
+ raise ImageError('imagen demasiado grande ({0}×{1})'.format(
607
+ fw, fh))
555
608
  table = global_table
556
609
  if fflags & 0x80:
557
610
  n = 2 << (fflags & 7)
@@ -824,9 +877,17 @@ def decode(data, all_frames=False):
824
877
  raise ImageError('no se pudo leer la imagen ({0})'.format(
825
878
  error))
826
879
  if kind in _PURE:
827
- if kind == 'gif':
828
- return decode_gif(data, all_frames)
829
- bitmap = _PURE[kind](data)
880
+ try:
881
+ if kind == 'gif':
882
+ return decode_gif(data, all_frames)
883
+ bitmap = _PURE[kind](data)
884
+ except ImageError:
885
+ raise
886
+ except (ValueError, IndexError, KeyError, OverflowError,
887
+ ZeroDivisionError, struct.error, zlib.error):
888
+ # A header or block that points past the data or holds values
889
+ # the format does not allow: the file is damaged.
890
+ raise ImageError('{0} dañado'.format(kind.upper())) from None
830
891
  return [bitmap] if all_frames else bitmap
831
892
  if kind is None:
832
893
  raise ImageError('formato de imagen desconocido')
@@ -975,6 +1036,8 @@ def _py_quantize(data, width, height, colors, alpha_threshold):
975
1036
  """
976
1037
  colors = max(1, min(255, colors))
977
1038
  n = width * height
1039
+ if width <= 0 or height <= 0 or len(data) < n * 4:
1040
+ raise ValueError('bad image size')
978
1041
  count = [0] * 32768
979
1042
  sums = [0] * (32768 * 3)
980
1043
  keys = [0] * n
@@ -2148,6 +2148,9 @@ class Table(object):
2148
2148
  A table squeezed far below the width of its own data wraps every cell
2149
2149
  to a couple of characters and becomes unreadable. Setting a message
2150
2150
  says so plainly instead. None, the default, renders the table anyway.
2151
+ The message is also shown when the table, once drawn, is still wider
2152
+ than the space -- the digits in front of a decimal point are never
2153
+ cut -- with ``{needed}`` the width it took.
2151
2154
 
2152
2155
  The message may use ``{needed}`` and ``{available}`` placeholders::
2153
2156
 
@@ -3149,9 +3152,21 @@ class Table(object):
3149
3152
 
3150
3153
  # A table with no columns has nothing to number: the index column
3151
3154
  # alone would have no cells, so it is drawn as without the index.
3152
- return self.__form_string(
3155
+ table_string = self.__form_string(
3153
3156
  table_with_i=self.__show_index and len(self.__columns) != 0
3154
3157
  )
3158
+ if self.__too_narrow_message is not None and len(self.__columns):
3159
+ # Numbers are never cut, so a table whose columns could each
3160
+ # shrink to the minimum can still come out wider than the space:
3161
+ # the caller asked to be told rather than get it overflowing.
3162
+ available = self.__available_width()
3163
+ drawn = max((visible_width(line)
3164
+ for line in table_string.split('\n')), default=0)
3165
+ if drawn > available:
3166
+ return self.__too_narrow_message.format(
3167
+ needed=drawn, available=available
3168
+ )
3169
+ return table_string
3155
3170
 
3156
3171
  def __get_string_table_width(self) -> int:
3157
3172
  """
@@ -4721,14 +4736,27 @@ class Table(object):
4721
4736
  lines.append(self.__aligned_label(text, table_width, spec))
4722
4737
  return '\n'.join(lines)
4723
4738
 
4724
- def __aligned_label(self, text, table_width, spec=None):
4725
- """Place ``text`` left/centre/right over ``table_width`` columns."""
4739
+ def __aligned_label(self, text, table_width, spec=None, limit=None):
4740
+ """
4741
+ Place ``text`` left/centre/right over ``table_width`` columns; a line
4742
+ wider than ``limit`` (by default the table width or the width the
4743
+ table has to fit into, whichever is more) is wrapped.
4744
+ """
4726
4745
  text = expand_tabs(str(text), TAB_SIZE)
4727
4746
  if '\n' in text:
4728
4747
  # Every line is placed on its own; aligning the block as a whole
4729
4748
  # left the lines after the first at column 0.
4730
- return '\n'.join(self.__aligned_label(line, table_width, spec)
4749
+ return '\n'.join(self.__aligned_label(line, table_width, spec,
4750
+ limit)
4731
4751
  for line in text.split('\n'))
4752
+ if limit is None:
4753
+ limit = self.__label_limit(table_width)
4754
+ if visible_width(text) > limit:
4755
+ # Wider than the table and than the width it must fit into: it
4756
+ # wraps (at spaces when it can) instead of running past it.
4757
+ return '\n'.join(self.__aligned_label(line, table_width, spec,
4758
+ limit)
4759
+ for line in wrap_to_width(text, max(1, limit)))
4732
4760
  if spec and self.__colors_active:
4733
4761
  text = colorize(text, spec)
4734
4762
  width = visible_width(text)
@@ -4741,6 +4769,13 @@ class Table(object):
4741
4769
  return ' ' * (table_width - width) + text
4742
4770
  return ' ' * ((table_width - width) // 2) + text
4743
4771
 
4772
+ def __label_limit(self, table_width):
4773
+ """
4774
+ Widest a title, subtitle or caption line may be: the table's own
4775
+ width, or the width it has to fit into when that is more.
4776
+ """
4777
+ return max(1, table_width, self.__body_width())
4778
+
4744
4779
  def __inset_border_labels(self, table_string, head, tail):
4745
4780
  """
4746
4781
  Set the title into the top rule and/or the caption into the bottom
@@ -4886,8 +4921,15 @@ class Table(object):
4886
4921
  if not self.__caption or self.__caption_position == 'border':
4887
4922
  return None
4888
4923
  table_width = drawn_width or self.__get_string_table_width()
4889
- lines = []
4924
+ limit = self.__label_limit(table_width)
4925
+ captions = []
4890
4926
  for caption in expand_tabs(self.__caption, TAB_SIZE).split('\n'):
4927
+ if visible_width(caption) > limit:
4928
+ captions.extend(wrap_to_width(caption, limit))
4929
+ else:
4930
+ captions.append(caption)
4931
+ lines = []
4932
+ for caption in captions:
4891
4933
  caption_width = visible_width(caption)
4892
4934
  if caption_width >= table_width:
4893
4935
  lines.append(caption)
@@ -6532,10 +6574,10 @@ class Table(object):
6532
6574
  lines = []
6533
6575
  if self.__title:
6534
6576
  lines.append(self.__aligned_label(self.__title, width,
6535
- self.__title_color))
6577
+ self.__title_color, width))
6536
6578
  if self.__subtitle:
6537
6579
  for line in self.__subtitle.split('\n'):
6538
- lines.append(self.__aligned_label(line, width, 'dim'))
6580
+ lines.append(self.__aligned_label(line, width, 'dim', width))
6539
6581
  if cards:
6540
6582
  min_width = opts.get('min_width')
6541
6583
  if min_width is None:
@@ -6545,7 +6587,8 @@ class Table(object):
6545
6587
  min_width=min(int(min_width), width))
6546
6588
  lines.append(grid.render(width=width))
6547
6589
  if self.__caption:
6548
- lines.append(self.__aligned_label(self.__caption, width))
6590
+ lines.append(self.__aligned_label(self.__caption, width,
6591
+ limit=width))
6549
6592
  out = '\n'.join(lines)
6550
6593
  if not self.__colors_active:
6551
6594
  out = strip_ansi(out)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 3.7.1
3
+ Version: 3.7.2
4
4
  Summary: Fast, dependency-free terminal tables for Python: 54 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Author: Benjamin Ramirez
@@ -46,15 +46,15 @@ Requires-Dist: openpyxl>=3.0; extra == "excel"
46
46
  Provides-Extra: html
47
47
  Requires-Dist: lxml>=4.0; extra == "html"
48
48
  Provides-Extra: tui
49
- Requires-Dist: flexablelib-tui==3.7.1; extra == "tui"
49
+ Requires-Dist: flexablelib-tui==3.7.2; extra == "tui"
50
50
  Provides-Extra: components
51
- Requires-Dist: flexablelib-components==3.7.1; extra == "components"
51
+ Requires-Dist: flexablelib-components==3.7.2; extra == "components"
52
52
  Provides-Extra: speed
53
- Requires-Dist: flexablelib-speedups==3.7.1; extra == "speed"
53
+ Requires-Dist: flexablelib-speedups==3.7.2; extra == "speed"
54
54
  Provides-Extra: images
55
55
  Requires-Dist: Pillow>=8; extra == "images"
56
- Requires-Dist: flexablelib-tui==3.7.1; extra == "images"
57
- Requires-Dist: flexablelib-components==3.7.1; extra == "images"
56
+ Requires-Dist: flexablelib-tui==3.7.2; extra == "images"
57
+ Requires-Dist: flexablelib-components==3.7.2; extra == "images"
58
58
  Provides-Extra: svg
59
59
  Requires-Dist: cairosvg>=2.5; extra == "svg"
60
60
  Provides-Extra: all
@@ -62,9 +62,9 @@ Requires-Dist: pandas>=1.0; extra == "all"
62
62
  Requires-Dist: openpyxl>=3.0; extra == "all"
63
63
  Requires-Dist: lxml>=4.0; extra == "all"
64
64
  Requires-Dist: Pillow>=8; extra == "all"
65
- Requires-Dist: flexablelib-tui==3.7.1; extra == "all"
66
- Requires-Dist: flexablelib-components==3.7.1; extra == "all"
67
- Requires-Dist: flexablelib-speedups==3.7.1; extra == "all"
65
+ Requires-Dist: flexablelib-tui==3.7.2; extra == "all"
66
+ Requires-Dist: flexablelib-components==3.7.2; extra == "all"
67
+ Requires-Dist: flexablelib-speedups==3.7.2; extra == "all"
68
68
  Dynamic: author
69
69
  Dynamic: author-email
70
70
  Dynamic: classifier
@@ -111,6 +111,10 @@ tests/test_v355_fixes.py
111
111
  tests/test_v360_features.py
112
112
  tests/test_v370_features.py
113
113
  tests/test_v371_fixes.py
114
+ tests/test_v372_ascii.py
115
+ tests/test_v372_fixes.py
116
+ tests/test_v372_labels.py
117
+ tests/test_v372_narrow.py
114
118
  tests/wincon_child.py
115
119
  tools/bench_frames.py
116
120
  tools/bench_images.py
@@ -0,0 +1,35 @@
1
+
2
+ [all]
3
+ pandas>=1.0
4
+ openpyxl>=3.0
5
+ lxml>=4.0
6
+ Pillow>=8
7
+ flexablelib-tui==3.7.2
8
+ flexablelib-components==3.7.2
9
+ flexablelib-speedups==3.7.2
10
+
11
+ [components]
12
+ flexablelib-components==3.7.2
13
+
14
+ [excel]
15
+ openpyxl>=3.0
16
+
17
+ [html]
18
+ lxml>=4.0
19
+
20
+ [images]
21
+ Pillow>=8
22
+ flexablelib-tui==3.7.2
23
+ flexablelib-components==3.7.2
24
+
25
+ [pandas]
26
+ pandas>=1.0
27
+
28
+ [speed]
29
+ flexablelib-speedups==3.7.2
30
+
31
+ [svg]
32
+ cairosvg>=2.5
33
+
34
+ [tui]
35
+ flexablelib-tui==3.7.2
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexablelib",
3
- "version": "3.7.1",
3
+ "version": "3.7.2",
4
4
  "private": true,
5
5
  "description": "Flexible console and HTML tables for Python: styles, merges, colors, widths, decimal alignment.",
6
6
  "repository": {
@@ -54,6 +54,21 @@ def repo_root_cwd(monkeypatch):
54
54
  monkeypatch.chdir(REPO_ROOT)
55
55
 
56
56
 
57
+ @pytest.fixture(autouse=True)
58
+ def colour_environment(monkeypatch):
59
+ """
60
+ Start every test with no NO_COLOR / FORCE_COLOR in the environment.
61
+
62
+ Colour depends on those variables, so without this a developer who
63
+ exports NO_COLOR=1 (or a CI runner with FORCE_COLOR set) gets different
64
+ results, and a test that writes ``os.environ['FORCE_COLOR']`` directly
65
+ leaks colour into every test that runs after it. ``monkeypatch`` puts the
66
+ original values back after each test, including over direct writes.
67
+ """
68
+ monkeypatch.delenv('NO_COLOR', raising=False)
69
+ monkeypatch.delenv('FORCE_COLOR', raising=False)
70
+
71
+
57
72
  @pytest.fixture(autouse=True)
58
73
  def default_terminal(monkeypatch):
59
74
  """
@@ -95,7 +95,8 @@ def test_vertical_center_align():
95
95
  assert rows == [(len(lines) - 1) // 2]
96
96
 
97
97
 
98
- def test_colour_still_applies_with_alignment():
98
+ def test_colour_still_applies_with_alignment(monkeypatch):
99
+ monkeypatch.setenv('FORCE_COLOR', '1')
99
100
  table = _framed()
100
101
  table.border_text('v2', where='top', align='right', color='red')
101
102
  assert '\x1b[31m' in table.compose()
@@ -0,0 +1,120 @@
1
+ """3.7.2: ASCII mode -- the symbols components put in help lines and status
2
+ texts have one-column ASCII stand-ins, in the C and the Python fold alike."""
3
+
4
+ import os
5
+
6
+ import pytest
7
+
8
+ C = pytest.importorskip('flexablelib_components')
9
+
10
+ from flexablelib import _frames as F # noqa: E402
11
+ from flexablelib.text_width import strip_ansi, visible_width # noqa: E402
12
+ from flexablelib_tui import App, accessibility as a11y # noqa: E402
13
+
14
+
15
+ @pytest.fixture(params=['python'] + (['c'] if F.available() else []))
16
+ def frames_backend(request):
17
+ old = F.BACKEND
18
+ F.use(request.param)
19
+ yield request.param
20
+ F.use(old)
21
+
22
+
23
+ class TestAsciiFold:
24
+ @pytest.mark.parametrize('glyph,ascii_char', [
25
+ ('⌫', '<'), ('⌦', '>'), ('ⓘ', 'i'), ('✚', '+'), ('⏱', 'o'),
26
+ ('⏲', 'o'), ('⏸', '='), ('⏹', '#'), ('⏺', 'o'), ('↻', 'o'),
27
+ ('↺', 'o'), ('↗', '/'), ('↙', '/'), ('↖', '\\'), ('↘', '\\'),
28
+ ])
29
+ def test_new_stand_ins(self, frames_backend, glyph, ascii_char):
30
+ assert F.ascii_fold(glyph) == ascii_char
31
+ assert F.ascii_fold('\x1b[1m' + glyph + 'x') == \
32
+ '\x1b[1m' + ascii_char + 'x'
33
+
34
+ def test_every_stand_in_keeps_the_width(self):
35
+ for cp, char in F.ASCII_FOLD.items():
36
+ if 0x2800 <= cp <= 0x28FF:
37
+ continue
38
+ assert visible_width(chr(cp)) == visible_width(char) == 1, \
39
+ hex(cp)
40
+
41
+ def test_c_table_matches_python(self):
42
+ header = os.path.join(os.path.dirname(os.path.dirname(
43
+ os.path.abspath(__file__))), 'packages', 'speedups',
44
+ 'flexablelib_speedups', '_ascii_table.h')
45
+ text = open(header, encoding='utf-8').read()
46
+ count = sum(1 for cp in F.ASCII_FOLD if not 0x2800 <= cp <= 0x28FF)
47
+ assert '#define ASCII_FOLD_COUNT {0}'.format(count) in text
48
+ for cp in (0x232B, 0x24D8, 0x271A, 0x23F1, 0x21BB):
49
+ assert '{{0x{0:04X}, '.format(cp) in text
50
+
51
+ def test_signature_help_line_is_ascii(self, frames_backend):
52
+ with a11y.configure(ascii=True, screen_reader=False,
53
+ reduced_motion=False, focus_marker=False):
54
+ pad = C.SignatureInput('Firma', columns=8, rows=2)
55
+ app = App(body=pad)
56
+ app.run(keys=[], size=(70, 8))
57
+ frame = strip_ansi(app.render(70, 8))
58
+ assert 'deshacer' in frame
59
+ assert frame.isascii(), [ch for ch in frame if not ch.isascii()]
60
+
61
+ def test_stopwatch_is_ascii_with_colours(self, frames_backend):
62
+ with a11y.configure(ascii=True, screen_reader=False,
63
+ reduced_motion=False, focus_marker=False):
64
+ watch = C.Stopwatch('Tiempo', use_colors=True)
65
+ app = App(body=watch)
66
+ app.run(keys=[], size=(70, 4))
67
+ frame = strip_ansi(app.render(70, 4))
68
+ assert '00:00' in frame
69
+ assert frame.isascii(), [ch for ch in frame if not ch.isascii()]
70
+
71
+
72
+ class TestMarksReference:
73
+ """The pure-Python mark extraction (used without the C package) on
74
+ nested, unclosed and malformed marks, checked against the C one."""
75
+
76
+ CASES = [
77
+ F.mark_open(1) + 'ab' + F.MARK_CLOSE + 'cd',
78
+ F.mark_open(1) + 'a' + F.mark_open(2) + '中' + F.MARK_CLOSE + 'b',
79
+ F.mark_open(3) + 'unclosed',
80
+ F.mark_open(4) + 'x' + F.mark_open(5) + 'y',
81
+ 'a' + F.MARK_CLOSE + 'b', # close with no open
82
+ '\x1b]8970;x1\x07plain', # ident not a number
83
+ '\x1b]8970;1234567890\x07ten digits', # ident too long
84
+ '\x1b]8970;12 no terminator',
85
+ '\x1b[31m' + F.mark_open(7) + 'red' + F.MARK_CLOSE + '\x1b[0m',
86
+ ]
87
+
88
+ def test_regions(self):
89
+ py = F._PYTHON['extract_marks']
90
+ clean, regions = py([self.CASES[1]])
91
+ assert clean == ['a中b']
92
+ assert sorted(regions) == [(1, 0, 0, 4, 0), (2, 0, 1, 3, 1)]
93
+ clean, regions = py([self.CASES[3]])
94
+ assert clean == ['xy']
95
+ assert sorted(regions) == [(4, 0, 0, 2, 0), (5, 0, 1, 2, 1)]
96
+ clean, regions = py([self.CASES[5]])
97
+ assert clean == ['plain'] and regions == []
98
+
99
+ def test_c_matches(self):
100
+ if not F.available():
101
+ pytest.skip('speedups not built')
102
+ for line in self.CASES:
103
+ assert F._C['extract_marks']([line, 'x', line]) == \
104
+ F._PYTHON['extract_marks']([line, 'x', line]), repr(line)
105
+
106
+
107
+ class TestExpandGraphics:
108
+ def test_without_marks_unchanged(self):
109
+ assert F.expand_graphics('plain') == 'plain'
110
+
111
+ def test_finds_the_module_again_after_a_reload(self, monkeypatch):
112
+ import sys
113
+ import types
114
+ line = F.GRAPHICS_MARK + '1\x07'
115
+ monkeypatch.setattr(F, '_graphics_expander', None)
116
+ fake = types.SimpleNamespace(expand=lambda text: 'EXPANDED')
117
+ monkeypatch.setitem(sys.modules, 'flexablelib_tui.graphics', fake)
118
+ assert F.expand_graphics(line) == 'EXPANDED'
119
+ monkeypatch.delitem(sys.modules, 'flexablelib_tui.graphics')
120
+ assert F.expand_graphics(line) == line