diff options
author | Barry Warsaw <barry@python.org> | 2015-01-26 11:14:06 -0500 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2015-01-26 11:14:06 -0500 |
commit | 841db73600e3f203243c773109d71ab88d3334bc (patch) | |
tree | 051f44833ae1ec1b31c5f893c6eca8b39e07a83c /cloudinit/user_data.py | |
parent | 3246c85763d5cdebb3e240fcd5ae29834cbf6299 (diff) | |
download | vyos-cloud-init-841db73600e3f203243c773109d71ab88d3334bc.tar.gz vyos-cloud-init-841db73600e3f203243c773109d71ab88d3334bc.zip |
More test repairs.
Diffstat (limited to 'cloudinit/user_data.py')
-rw-r--r-- | cloudinit/user_data.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py index 9111bd39..ff21259c 100644 --- a/cloudinit/user_data.py +++ b/cloudinit/user_data.py @@ -109,6 +109,15 @@ class UserDataProcessor(object): ctype = None ctype_orig = part.get_content_type() payload = part.get_payload(decode=True) + # In Python 3, decoding the payload will ironically hand us a + # bytes object. 'decode' means to decode according to + # Content-Transfer-Encoding, not according to any charset in the + # Content-Type. So, if we end up with bytes, first try to decode + # to str via CT charset, and failing that, try utf-8 using + # surrogate escapes. + if six.PY3 and isinstance(payload, bytes): + charset = part.get_charset() or 'utf-8' + payload = payload.decode(charset, errors='surrogateescape') was_compressed = False # When the message states it is of a gzipped content type ensure |