Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: recipe_engine/util.py

Issue 2798393002: Work around unicode issues by re-encoding properties as utf-8 (Closed)
Patch Set: comment Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | recipe_modules/json/api.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The LUCI Authors. All rights reserved. 1 # Copyright 2013 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 import datetime 6 import datetime
7 import functools 7 import functools
8 import logging 8 import logging
9 import os 9 import os
10 import sys 10 import sys
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 it (iterable): An iterable to traverse. 302 it (iterable): An iterable to traverse.
303 exc_types (list): An optional list of specific exception types to defer. 303 exc_types (list): An optional list of specific exception types to defer.
304 If empty, Exception will be used. Any Exceptions not referenced by this 304 If empty, Exception will be used. Any Exceptions not referenced by this
305 list will skip deferring and be immediately raised. 305 list will skip deferring and be immediately raised.
306 """ 306 """
307 mexc_builder = MultiException.Builder() 307 mexc_builder = MultiException.Builder()
308 for e in it: 308 for e in it:
309 with mexc_builder.catch(*exc_types): 309 with mexc_builder.catch(*exc_types):
310 fn(e) 310 fn(e)
311 mexc_builder.raise_if_any() 311 mexc_builder.raise_if_any()
312
313 def strip_unicode(obj):
314 """Recursively re-encodes strings as utf-8 inside |obj|. Returns the result.
315 """
316 if isinstance(obj, unicode):
317 return obj.encode('utf-8', 'replace')
318
319 if isinstance(obj, list):
320 return map(strip_unicode, obj)
321
322 if isinstance(obj, dict):
323 new_obj = type(obj)(
324 (strip_unicode(k), strip_unicode(v)) for k, v in obj.iteritems() )
325 return new_obj
326
327 return obj
OLDNEW
« no previous file with comments | « no previous file | recipe_modules/json/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698