From fd101dd2d605bfecd9c6a5bfb3982c49a08e9e11 Mon Sep 17 00:00:00 2001 From: Andrey Shorin Date: Wed, 25 Sep 2013 09:15:08 +0400 Subject: [PATCH] Encode to utf-8 only when needed --- lib/ansible/utils/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index 6af22d07c0..a8b05679b5 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -408,9 +408,11 @@ def merge_hash(a, b): def md5s(data): ''' Return MD5 hex digest of data. ''' - buf = StringIO.StringIO(data) digest = _md5() - digest.update(buf.read().encode('utf-8')) + try: + digest.update(data) + except UnicodeEncodeError: + digest.update(data.encode('utf-8')) return digest.hexdigest() def md5(filename):