From 1dbbd2a80cbb7331c53fdf1c9fd0c6e8817a072f Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 2 Mar 2016 09:31:06 -0800 Subject: [PATCH] Remove debugging and fix the place where bytes are being handed to StringIO --- lib/ansible/template/__init__.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index 5e654e9e88f..6a07566fa0e 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -40,6 +40,7 @@ from ansible.template.safe_eval import safe_eval from ansible.template.template import AnsibleJ2Template from ansible.template.vars import AnsibleJ2Vars from ansible.utils.debug import debug +from ansible.utils.unicode import to_unicode try: from hashlib import sha1 @@ -255,10 +256,10 @@ class Templar: if prev_idx is not None: # replace the opening data.seek(prev_idx, os.SEEK_SET) - data.write(self.environment.comment_start_string) + data.write(to_unicode(self.environment.comment_start_string)) # replace the closing data.seek(token_start, os.SEEK_SET) - data.write(self.environment.comment_end_string) + data.write(to_unicode(self.environment.comment_end_string)) else: raise AnsibleError("Error while cleaning data for safety: unhandled regex match") @@ -291,13 +292,6 @@ class Templar: if hasattr(variable, '__UNSAFE__'): if isinstance(variable, text_type): return self._clean_data(variable) - elif isinstance(variable, binary_type): - # If we're unicode sandwiching, then we shouldn't get here but - # seems like we are. Will have to decide whether to turn them - # into text_type instead - raise AnsibleError("variable is str: %s" % variable) - #elif isinstance(variable, binary_type): - # return self._clean_data(bytes(variable)) else: # Do we need to convert these into text_type as well? # return self._clean_data(to_unicode(variable._obj, nonstring='passthru')) @@ -504,8 +498,7 @@ class Templar: ) else: debug("failing because of a type error, template data is: %s" % data) - import traceback - raise AnsibleError("an unexpected type error occurred. Error was %s, tracback: %s" % (te, traceback.format_exc())) + raise AnsibleError("an unexpected type error occurred. Error was %s" % te) if preserve_trailing_newlines: # The low level calls above do not preserve the newline