Prevents UnicodeEncodeError
jctanner authored on 2013/12/17 06:23:16... | ... |
@@ -128,9 +128,15 @@ def display(msg, color=None, stderr=False, screen_only=False, log_only=False, ru |
128 | 128 |
msg2 = stringc(msg, color) |
129 | 129 |
if not log_only: |
130 | 130 |
if not stderr: |
131 |
- print msg2 |
|
131 |
+ try: |
|
132 |
+ print msg2 |
|
133 |
+ except UnicodeEncodeError: |
|
134 |
+ print msg2.encode('utf-8') |
|
132 | 135 |
else: |
133 |
- print >>sys.stderr, msg2 |
|
136 |
+ try: |
|
137 |
+ print >>sys.stderr, msg2 |
|
138 |
+ except UnicodeEncodeError: |
|
139 |
+ print >>sys.stderr, msg2.encode('utf-8') |
|
134 | 140 |
if constants.DEFAULT_LOG_PATH != '': |
135 | 141 |
while msg.startswith("\n"): |
136 | 142 |
msg = msg.replace("\n","") |
... | ... |
@@ -136,7 +136,10 @@ class ModuleReplacer(object): |
136 | 136 |
complex_args_json = utils.jsonify(complex_args) |
137 | 137 |
# We force conversion of module_args to str because module_common calls shlex.split, |
138 | 138 |
# a standard library function that incorrectly handles Unicode input before Python 2.7.3. |
139 |
- encoded_args = repr(module_args.encode('utf-8')) |
|
139 |
+ try: |
|
140 |
+ encoded_args = repr(module_args.encode('utf-8')) |
|
141 |
+ except UnicodeDecodeError: |
|
142 |
+ encoded_args = repr(module_args) |
|
140 | 143 |
encoded_lang = repr(C.DEFAULT_MODULE_LANG) |
141 | 144 |
encoded_complex = repr(complex_args_json) |
142 | 145 |
|