|
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:
|
@@ -474,9 +489,8 @@ def test_flushes(self):
|
474 | 489 | sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
|
475 | 490 | 'Z_PARTIAL_FLUSH']
|
476 | 491 |
|
477 |
| - ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.')) |
478 | 492 | # Z_BLOCK has a known failure prior to 1.2.5.3
|
479 |
| - if ver >= (1, 2, 5, 3): |
| 493 | + if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3): |
480 | 494 | sync_opt.append('Z_BLOCK')
|
481 | 495 |
|
482 | 496 | sync_opt = [getattr(zlib, opt) for opt in sync_opt
|
@@ -794,16 +808,7 @@ def test_large_unconsumed_tail(self, size):
|
794 | 808 |
|
795 | 809 | def test_wbits(self):
|
796 | 810 | # wbits=0 only supported since zlib v1.2.3.5
|
797 |
| - # Register "1.2.3" as "1.2.3.0" |
798 |
| - # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux" |
799 |
| - v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.') |
800 |
| - if len(v) < 4: |
801 |
| - v.append('0') |
802 |
| - elif not v[-1].isnumeric(): |
803 |
| - v[-1] = '0' |
804 |
| - |
805 |
| - v = tuple(map(int, v)) |
806 |
| - supports_wbits_0 = v >= (1, 2, 3, 5) |
| 811 | + supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5) |
807 | 812 |
|
808 | 813 | co = zlib.compressobj(level=1, wbits=15)
|
809 | 814 | zlib15 = co.compress(HAMLET_SCENE) + co.flush()
|
|
0 commit comments