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