summaryrefslogtreecommitdiff
path: root/cloudinit/handlers
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-11-06 14:24:19 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-11-06 14:24:19 -0800
commit7ec0ef04b975eb5b4c40f7ae746d706585c73a02 (patch)
treef0a9a58edd1ce6dce4b8e3ec8a6243dcaae23b83 /cloudinit/handlers
parent7d027a031a3649ac04965a09cd26563ac9d760fd (diff)
downloadvyos-cloud-init-7ec0ef04b975eb5b4c40f7ae746d706585c73a02.tar.gz
vyos-cloud-init-7ec0ef04b975eb5b4c40f7ae746d706585c73a02.zip
Use a method instead + at least
attempt the unicode-escape path.
Diffstat (limited to 'cloudinit/handlers')
-rw-r--r--cloudinit/handlers/__init__.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/cloudinit/handlers/__init__.py b/cloudinit/handlers/__init__.py
index e843eb75..d847f331 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:
+ text = "'%s...'" % (text.encode("string-escape"))
+ except TypeError:
+ try:
+ # Unicode doesn't support string-escape...
+ text = "'%s...'" % (text.encode('unicode-escape'))
+ except TypeError:
+ # Give up...
+ text = "'%s...'" % (text)
+ return text
+
+
def walker_callback(pdata, ctype, filename, payload):
if ctype in PART_CONTENT_TYPES:
walker_handle_handler(pdata, ctype, filename, payload)
@@ -171,11 +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)
- try:
- details = "'%s...'" % (start.encode("string-escape"))
- except TypeError:
- # Unicode doesn't support string-escape...
- details = "'%s...'" % (start)
+ details = _escape_string(start)
if ctype == NOT_MULTIPART_TYPE:
LOG.warning("Unhandled non-multipart (%s) userdata: %s",
ctype, details)