From 5eb2aab5d010e7b8d5e4146959e50f2a9f67d504 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 4 Mar 2015 17:20:48 +0000 Subject: 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. --- cloudinit/util.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cloudinit/util.py') 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) -- cgit v1.2.3