mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Fix issues related to Python 3 compatibility
This commit is contained in:
committed by
Omer Karaduman
parent
246580b76f
commit
3235c6c831
6
build.py
6
build.py
@@ -336,7 +336,9 @@ class Gen_compressed(threading.Thread):
|
||||
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.
|
||||
@@ -456,7 +458,7 @@ class Gen_langfiles(threading.Thread):
|
||||
# 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.
|
||||
|
||||
@@ -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)])
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -37,7 +37,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
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)))
|
||||
|
||||
@@ -65,7 +65,7 @@ def _parse_trans_unit(trans_unit):
|
||||
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.
|
||||
@@ -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.
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user