def get_uncompressed(data_str, parse_as_yaml=None):
"""
Converts character string "data_str" as "utf-8" into bytes, then
decodes it as "base64" and decompress with gzip/zlib. The resulted
"bytes" are converted again into standard for Python3 "utf-8"
string. Raises zlib.error or binascii.Error if something went
wrong. If "parse_as_yaml" is True, try to load uncompressed
content with "load_yaml". The latter may raise ValueError or
YAMLError if something went wrong. Need to use zlib to make it
backward compatible with the zlib compressed DAGs
"""
parse_as_yaml = False if parse_as_yaml is None else parse_as_yaml
try:
uncompressed = gzip.decompress(
base64.b64decode(
data_str.encode("utf-8") + b'=='
)
).decode("utf-8")
except Exception:
uncompressed = zlib.decompress(
base64.b64decode(
data_str.encode("utf-8") + b'=='
)
).decode("utf-8")
return load_yaml(uncompressed) if parse_as_yaml else uncompressed
Added
+ b'=='