diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-02-11 01:09:34 +0000 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-02-11 01:09:34 +0000 |
commit | f62b86bd45c8df78ada32ab4040a639c9d096202 (patch) | |
tree | 8648518e275287eec62680dd6e65358604916502 /cloudinit/util.py | |
parent | b8eb55f9acdf92a58d3c72b0c5e5437c4f0272c1 (diff) | |
download | vyos-cloud-init-f62b86bd45c8df78ada32ab4040a639c9d096202.tar.gz vyos-cloud-init-f62b86bd45c8df78ada32ab4040a639c9d096202.zip |
fix random_seed module
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 3a921afe..c998154a 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -96,11 +96,10 @@ def b64d(source): # Base64 decode some data, accepting bytes or unicode/str, and returning # str/unicode if the result is utf-8 compatible, otherwise returning bytes. decoded = b64decode(source) - if isinstance(decoded, bytes): - try: - return decoded.decode('utf-8') - except UnicodeDecodeError: - return decoded + try: + return decoded.decode('utf-8') + except UnicodeDecodeError: + return decoded def b64e(source): # Base64 encode some data, accepting bytes or unicode/str, and returning @@ -354,11 +353,14 @@ def clean_filename(fn): return fn -def decomp_gzip(data, quiet=True): +def decomp_gzip(data, quiet=True, decode=True): try: buf = six.BytesIO(encode_text(data)) with contextlib.closing(gzip.GzipFile(None, "rb", 1, buf)) as gh: - return decode_binary(gh.read()) + if decode: + return decode_binary(gh.read()) + else: + return gh.read() except Exception as e: if quiet: return data |