summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-11-07 09:01:58 -0500
committerScott Moser <smoser@ubuntu.com>2012-11-07 09:01:58 -0500
commitce5a554672f4ffbc383af08a35d22a1dd89ce41f (patch)
tree8980eb868ed8b9acd9f2d6f0d656edcf605b92d9
parentc508fa0c4159f93df077a2d46ed481fd5d8c8803 (diff)
parent9850895442afe55079cecf4fd96fe8430ed960ea (diff)
downloadvyos-cloud-init-ce5a554672f4ffbc383af08a35d22a1dd89ce41f.tar.gz
vyos-cloud-init-ce5a554672f4ffbc383af08a35d22a1dd89ce41f.zip
support unicode in user-data input of unknown types
Fix the case where a unknown type is seen and it has contents which are in unicode. That caused python to blow-up when this happens since 'string-escape' doesn't work on unicode (at least in 2.6). LP: #1075756
-rw-r--r--ChangeLog1
-rw-r--r--cloudinit/handlers/__init__.py15
2 files changed, 15 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 1243ce7f..ac84c75f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
mime or cloud-archive config (LP: #1065116).
- tools/Z99-cloud-locale-test.sh: avoid warning when user's shell is
zsh (LP: #1073077)
+ - fix stack trace when unknown user-data input had unicode (LP: #1075756)
0.7.0:
- add a 'exception_cb' argument to 'wait_for_url'. If provided, this
method will be called back with the exception received and the message.
diff --git a/cloudinit/handlers/__init__.py b/cloudinit/handlers/__init__.py
index 99caed1f..8d6dcd4d 100644
--- a/cloudinit/handlers/__init__.py
+++ b/cloudinit/handlers/__init__.py
@@ -160,6 +160,19 @@ def _extract_first_or_bytes(blob, size):
return start
+def _escape_string(text):
+ try:
+ return text.encode("string-escape")
+ except TypeError:
+ try:
+ # Unicode doesn't support string-escape...
+ return text.encode('unicode-escape')
+ except TypeError:
+ # Give up...
+ pass
+ return text
+
+
def walker_callback(pdata, ctype, filename, payload):
if ctype in PART_CONTENT_TYPES:
walker_handle_handler(pdata, ctype, filename, payload)
@@ -171,7 +184,7 @@ def walker_callback(pdata, ctype, filename, payload):
elif payload:
# Extract the first line or 24 bytes for displaying in the log
start = _extract_first_or_bytes(payload, 24)
- details = "'%s...'" % (start.encode("string-escape"))
+ details = "'%s...'" % (_escape_string(start))
if ctype == NOT_MULTIPART_TYPE:
LOG.warning("Unhandled non-multipart (%s) userdata: %s",
ctype, details)