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

Unified Diff: recipes.py

Issue 2798393002: Work around unicode issues by re-encoding properties as utf-8 (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipes.py
diff --git a/recipes.py b/recipes.py
index 0626c1f356f2ef24611b9eab21b59192bc8d006c..a3214a5414681040b610ab46e01943587547d9d2 100755
--- a/recipes.py
+++ b/recipes.py
@@ -182,6 +182,21 @@ def new_handle_recipe_return(result, result_filename, stream_engine):
return 0
+def strip_unicode(obj):
iannucci 2017/04/06 18:10:12 Could we move this function to e.g. util.py and th
+ if isinstance(obj, unicode):
+ return obj.encode('utf-8', 'replace')
+
+ if isinstance(obj, list):
+ return map(strip_unicode, obj)
+
+ if isinstance(obj, dict):
+ new_obj = type(obj)(
+ (strip_unicode(k), strip_unicode(v)) for k, v in obj.iteritems() )
+ return new_obj
+
+ return obj
+
+
def run(package_deps, args, op_args):
from recipe_engine import run as recipe_run
from recipe_engine import loader
@@ -232,6 +247,11 @@ def run(package_deps, args, op_args):
properties['recipe'] = args.recipe
+ # Work around unicode issues by re-encoding properties as utf-8.
+ properties = strip_unicode(properties)
+ reload(sys)
iannucci 2017/04/06 18:10:12 Now that I think about this, I would actually do t
+ sys.setdefaultencoding('UTF8')
+
os.environ['PYTHONUNBUFFERED'] = '1'
os.environ['PYTHONIOENCODING'] = 'UTF-8'
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698