Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues related to Python 3 compatibility #2125

Merged
merged 3 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ def do_compile(self, params, target_filename, filenames, remove):
conn = httplib.HTTPSConnection("closure-compiler.appspot.com")
conn.request("POST", "/compile", urlencode(params), 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 @@ -456,7 +458,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
2 changes: 1 addition & 1 deletion i18n/create_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main():
# Read in synonyms file, which must be output in every language.
synonym_defs = read_json_file(os.path.join(
os.curdir, args.source_synonym_file))

# synonym_defs is also being sorted to ensure the same order is kept
synonym_text = '\n'.join([u'Blockly.Msg["{0}"] = Blockly.Msg["{1}"];'
.format(key, synonym_defs[key]) for key in sorted(synonym_defs)])
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