| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |