diff options
author | Barry Warsaw <barry@python.org> | 2015-01-26 14:48:23 -0500 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2015-01-26 14:48:23 -0500 |
commit | 18b35de06432869a9d859e2978e7e9567eba66a2 (patch) | |
tree | 8627efd630cecb28e0a55a7953953e8c2673cadc /cloudinit/config/cc_seed_random.py | |
parent | de5974fe93dd717e0c7ba6de17db3192cc258cff (diff) | |
download | vyos-cloud-init-18b35de06432869a9d859e2978e7e9567eba66a2.tar.gz vyos-cloud-init-18b35de06432869a9d859e2978e7e9567eba66a2.zip |
Another handling of b64decode.
Also, restore Python 2 compatibility.
Diffstat (limited to 'cloudinit/config/cc_seed_random.py')
-rw-r--r-- | cloudinit/config/cc_seed_random.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cloudinit/config/cc_seed_random.py b/cloudinit/config/cc_seed_random.py index 3b7235bf..981e1b08 100644 --- a/cloudinit/config/cc_seed_random.py +++ b/cloudinit/config/cc_seed_random.py @@ -38,7 +38,13 @@ def _decode(data, encoding=None): if not encoding or encoding.lower() in ['raw']: return data elif encoding.lower() in ['base64', 'b64']: - return base64.b64decode(data) + # Try to give us a native string in both Python 2 and 3, and remember + # that b64decode() returns bytes in Python 3. + decoded = base64.b64decode(data) + try: + return decoded.decode('utf-8') + except UnicodeDecodeError: + return decoded elif encoding.lower() in ['gzip', 'gz']: return util.decomp_gzip(data, quiet=False) else: |