|
19 | 19 | hasattr(zlib.decompressobj(), "copy"), |
20 | 20 | 'requires Decompress.copy()') |
21 | 21 |
|
| 22 | + |
| 23 | +def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION): |
| 24 | + # Register "1.2.3" as "1.2.3.0" |
| 25 | + # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux" |
| 26 | + v = zlib_version.split('-', 1)[0].split('.') |
| 27 | + if len(v) < 4: |
| 28 | + v.append('0') |
| 29 | + elif not v[-1].isnumeric(): |
| 30 | + v[-1] = '0' |
| 31 | + return tuple(map(int, v)) |
| 32 | + |
| 33 | + |
| 34 | +ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple() |
| 35 | + |
| 36 | + |
22 | 37 | # bpo-46623: On s390x, when a hardware accelerator is used, using different |
23 | 38 | # ways to compress data with zlib can produce different compressed data. |
24 | 39 | # Simplified test_pair() code: |
@@ -477,9 +492,8 @@ def test_flushes(self): |
477 | 492 | sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH', |
478 | 493 | 'Z_PARTIAL_FLUSH'] |
479 | 494 |
|
480 | | - ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.')) |
481 | 495 | # Z_BLOCK has a known failure prior to 1.2.5.3 |
482 | | - if ver >= (1, 2, 5, 3): |
| 496 | + if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3): |
483 | 497 | sync_opt.append('Z_BLOCK') |
484 | 498 |
|
485 | 499 | sync_opt = [getattr(zlib, opt) for opt in sync_opt |
@@ -797,16 +811,7 @@ def test_large_unconsumed_tail(self, size): |
797 | 811 |
|
798 | 812 | def test_wbits(self): |
799 | 813 | # wbits=0 only supported since zlib v1.2.3.5 |
800 | | - # Register "1.2.3" as "1.2.3.0" |
801 | | - # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux" |
802 | | - v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.') |
803 | | - if len(v) < 4: |
804 | | - v.append('0') |
805 | | - elif not v[-1].isnumeric(): |
806 | | - v[-1] = '0' |
807 | | - |
808 | | - v = tuple(map(int, v)) |
809 | | - supports_wbits_0 = v >= (1, 2, 3, 5) |
| 814 | + supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5) |
810 | 815 |
|
811 | 816 | co = zlib.compressobj(level=1, wbits=15) |
812 | 817 | zlib15 = co.compress(HAMLET_SCENE) + co.flush() |
|
0 commit comments