mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Backport gzip.decompress for Python 2
Python 2 doesn't have gzip.decompress(data: bytes) -> bytes function. Backport the two line function from Python 3.6. Fixes: https://pagure.io/freeipa/issue/7563 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
import collections
|
||||
import gzip
|
||||
import io
|
||||
import logging
|
||||
import xml.dom.minidom
|
||||
import zlib
|
||||
@@ -63,6 +64,15 @@ DEFAULT_PROFILE = u'caIPAserviceCert'
|
||||
KDC_PROFILE = u'KDCs_PKINIT_Certs'
|
||||
|
||||
|
||||
if six.PY3:
|
||||
gzip_decompress = gzip.decompress # pylint: disable=no-member
|
||||
else:
|
||||
# note: gzip.decompress available in Python >= 3.2
|
||||
def gzip_decompress(data):
|
||||
with gzip.GzipFile(fileobj=io.BytesIO(data)) as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def error_from_xml(doc, message_template):
|
||||
try:
|
||||
item_node = doc.getElementsByTagName("Error")
|
||||
@@ -232,8 +242,7 @@ def _httplib_request(
|
||||
|
||||
encoding = res.getheader('Content-Encoding')
|
||||
if encoding == 'gzip':
|
||||
# note: gzip.decompress available in Python >= 3.2
|
||||
http_body = gzip.decompress(http_body) # pylint: disable=no-member
|
||||
http_body = gzip_decompress(http_body)
|
||||
elif encoding == 'deflate':
|
||||
http_body = zlib.decompress(http_body)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user