my_activity.py: Fix to work with non-ascii characters

The default encoding for python 2.7 strings is ascii.  Some of
the titles of issues, such as http://crbug.com/477941, contain
non-ascii characters, and cause my_activity.py to throw an
exception.  Re-encode the unicode title string to ascii with
the 'replace' option, to replace non-ascii characters with '?'.

R=maruel@chromium.org
BUG=none
TEST=Run `my_activity.py` with #477941 in my issues list; correctly
     lists issues without throwing an exception.

Review URL: https://codereview.chromium.org/1151053003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@295425 0039d316-1c4b-4281-b951-d872f2087c98
parent 31f3df06
...@@ -37,6 +37,7 @@ import urllib ...@@ -37,6 +37,7 @@ import urllib
import urllib2 import urllib2
import auth import auth
import fix_encoding
import gerrit_util import gerrit_util
import rietveld import rietveld
from third_party import upload from third_party import upload
...@@ -611,7 +612,7 @@ class MyActivity(object): ...@@ -611,7 +612,7 @@ class MyActivity(object):
values = dict(required_values.items() + optional_values.items()) values = dict(required_values.items() + optional_values.items())
else: else:
values = required_values values = required_values
print output_format.format(**values) print output_format.format(**values).encode(sys.getdefaultencoding())
def filter_issue(self, issue, should_filter_by_user=True): def filter_issue(self, issue, should_filter_by_user=True):
...@@ -861,6 +862,9 @@ def main(): ...@@ -861,6 +862,9 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
# Fix encoding to support non-ascii issue titles.
fix_encoding.fix_encoding()
try: try:
sys.exit(main()) sys.exit(main())
except KeyboardInterrupt: except KeyboardInterrupt:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment