From 8be1671867a12ad2c7479618c5d1bee36fef9f22 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Thu, 31 Jul 2014 19:57:14 +0200 Subject: [PATCH] Fix unicode handling issue of utils.str.format on Python 2. --- src/utils/str.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils/str.py b/src/utils/str.py index a227ff7dc..f3003b43a 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -448,6 +448,13 @@ def format(s, *args, **kwargs): # to add the character to the _formatRe regexp or it will be ignored # (and hard to debug if you don't know the trick). # Of course, you should also document it in the docstring above. + if sys.version_info.major < 3: + def pred(s): + if isinstance(s, unicode): + return s.encode('utf8') + else: + return s + args = map(pred, args) args = list(args) args.reverse() # For more efficient popping. def sub(match):