summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-03-04 17:09:32 -0500
committerScott Moser <smoser@ubuntu.com>2015-03-04 17:09:32 -0500
commit56a594cb47342b89629e0876bd63b4e724d5e1a2 (patch)
tree787e72e1bba979810aa998eeab6eade13fbd06a4 /cloudinit
parent068ee3d324350fd998e2a27e5be2991ea9bab52f (diff)
parent5eb2aab5d010e7b8d5e4146959e50f2a9f67d504 (diff)
downloadvyos-cloud-init-56a594cb47342b89629e0876bd63b4e724d5e1a2.tar.gz
vyos-cloud-init-56a594cb47342b89629e0876bd63b4e724d5e1a2.zip
Add util.message_from_string to wrap email.message_from_string.
This is to work-around the fact that email.message_from_string uses cStringIO in Python 2.6, which can't handle Unicode.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceCloudSigma.py2
-rw-r--r--cloudinit/user_data.py4
-rw-r--r--cloudinit/util.py7
3 files changed, 9 insertions, 4 deletions
diff --git a/cloudinit/sources/DataSourceCloudSigma.py b/cloudinit/sources/DataSourceCloudSigma.py
index 76597116..f8f94759 100644
--- a/cloudinit/sources/DataSourceCloudSigma.py
+++ b/cloudinit/sources/DataSourceCloudSigma.py
@@ -59,7 +59,7 @@ class DataSourceCloudSigma(sources.DataSource):
LOG.warn("failed to get hypervisor product name via dmi data")
return False
else:
- LOG.debug("detected hypervisor as {}".format(sys_product_name))
+ LOG.debug("detected hypervisor as %s", sys_product_name)
return 'cloudsigma' in sys_product_name.lower()
LOG.warn("failed to query dmi data for system product name")
diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py
index 663a9048..eb3c7336 100644
--- a/cloudinit/user_data.py
+++ b/cloudinit/user_data.py
@@ -22,8 +22,6 @@
import os
-import email
-
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
@@ -338,7 +336,7 @@ def convert_string(raw_data, headers=None):
headers = {}
data = util.decode_binary(util.decomp_gzip(raw_data))
if "mime-version:" in data[0:4096].lower():
- msg = email.message_from_string(data)
+ msg = util.message_from_string(data)
for (key, val) in headers.items():
_replace_header(msg, key, val)
else:
diff --git a/cloudinit/util.py b/cloudinit/util.py
index b6065410..971c1c2d 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -23,6 +23,7 @@
import contextlib
import copy as obj_copy
import ctypes
+import email
import errno
import glob
import grp
@@ -2187,3 +2188,9 @@ def read_dmi_data(key):
LOG.warn("did not find either path %s or dmidecode command",
DMI_SYS_PATH)
return None
+
+
+def message_from_string(string):
+ if sys.version_info[:2] < (2, 7):
+ return email.message_from_file(six.StringIO(string))
+ return email.message_from_string(string)