Skip to content

Commit

Permalink
Fix issues related to Python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tansly committed Jul 12, 2019
1 parent d3f6ffb commit b93da0b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ def do_compile_remote(self, params, target_filename):
conn = httplib.HTTPSConnection("closure-compiler.appspot.com")
conn.request("POST", "/compile", urlencode(remoteParams), headers)
response = conn.getresponse()
json_str = response.read()
# Decode is necessary for Python 3.4 compatibility
json_str = response.read().decode("utf-8")
conn.close()

# Parse the JSON response.
Expand Down Expand Up @@ -505,7 +506,7 @@ def _rebuild(self, srcs, dests):
# If a destination file was missing, rebuild.
return True
else:
print("Error checking file creation times: " + e)
print("Error checking file creation times: " + str(e))

def run(self):
# The files msg/json/{en,qqq,synonyms}.json depend on msg/messages.js.
Expand Down
4 changes: 2 additions & 2 deletions i18n/dedup_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def main():
try:
with codecs.open(filename, 'r', 'utf-8') as infile:
j = json.load(infile)
except ValueError, e:
except ValueError as e:
print('Error reading ' + filename)
raise InputError(file, str(e))
raise InputError(filename, str(e))

# Built up output strings as an array to make output of delimiters easier.
output = []
Expand Down
2 changes: 1 addition & 1 deletion i18n/json_to_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _process_file(path_to_json, target_lang, key_dict):
if key != '@metadata':
try:
identifier = key_dict[key]
except KeyError, e:
except KeyError as e:
print('Key "%s" is in %s but not in %s' %
(key, keyfile, args.key_file))
raise e
Expand Down
2 changes: 1 addition & 1 deletion i18n/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def contains_all_chars(orig, result):
u'block of actions.']
for sentence in sentences:
output = common.insert_breaks(sentence, 30, 50)
self.assert_(contains_all_chars(sentence, output),
self.assertTrue(contains_all_chars(sentence, output),
u'Mismatch between:\n{0}\n{1}'.format(
re.sub(spaces, '', sentence),
re.sub(spaces, '', output)))
Expand Down
10 changes: 5 additions & 5 deletions i18n/xliff_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_value(tag_name):
try:
result['source'] = get_value('source')
result['target'] = get_value('target')
except InputError, e:
except InputError as e:
raise InputError(key, e.msg)

# Get notes, using the from value as key and the data as value.
Expand Down Expand Up @@ -112,8 +112,8 @@ def _process_file(filename):
except IOError:
# Don't get caught by below handler
raise
except Exception, e:
print
except Exception as e:
print()
raise InputError(filename, str(e))

# Make sure needed fields are present and non-empty.
Expand Down Expand Up @@ -146,8 +146,8 @@ def _process_file(filename):
results.append(unit)

return results
except IOError, e:
print 'Error with file {0}: {1}'.format(filename, e.strerror)
except IOError as e:
print('Error with file {0}: {1}'.format(filename, e.strerror))
sys.exit(1)


Expand Down

0 comments on commit b93da0b

Please sign in to comment.