grit: xtb_reader: parse inputs in binary mode
When parsing opening files in text mode for XTB parsing, Python 3 will use the active system locale. If the locale is not UTF-8, we run into errors as Python tries to convert to ASCII. To avoid this, open the XTB files in binary mode before passing to the XML layers. Normally another option would be to use io.open with an explicit encoding='utf-8' setting, and indeed, that works fine for Python 3. Unfortunately Python 2's XML libs don't handle unicode strings well leading to similar ASCII encoding errors. It seems to work fine when opened in binary mode though, so lets go that route. Due to Python 2's implementation of bytes, the xtb_reader.Parse API change shouldn't be noticed. The code didn't work well with Python 3, so there aren't any users there yet :). Not that it seems like a big deal as cs.chromium.org says all API users are internal. Bug: 983071 Test: `./grit/test_suite_all.py` passes Change-Id: Idbd282ce9b93c4fcb4bb2dc4cce1dba3a84f6c27 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2043315Reviewed-by:Lei Zhang <thestig@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org> Cr-Commit-Position: refs/heads/master@{#739443}
Showing
Please register or sign in to comment