diff --git a/tools/cefbuilds/cef_json_builder.py b/tools/cefbuilds/cef_json_builder.py index ecd835a87..6d41d3f99 100644 --- a/tools/cefbuilds/cef_json_builder.py +++ b/tools/cefbuilds/cef_json_builder.py @@ -8,12 +8,11 @@ import datetime import json import os import re +import sys -try: - # Python 2 +if sys.version_info.major == 2: from urllib2 import urlopen -except Exception as e: - # Python 3 +else: from urllib.request import urlopen # Class used to build the cefbuilds JSON file. See cef_json_builder_example.py diff --git a/tools/file_util.py b/tools/file_util.py index d112ff220..0741f6fd4 100644 --- a/tools/file_util.py +++ b/tools/file_util.py @@ -32,11 +32,9 @@ def write_file(name, data): try: with open(name, 'w', encoding='utf-8') as f: # write the data - try: - # Python 2 + if sys.version_info.major == 2: f.write(data.decode('utf-8')) - except Exception as e: - # Python 3 + else: f.write(data) except IOError as e: (errno, strerror) = e.args diff --git a/tools/issue_1999.py b/tools/issue_1999.py index 6c27d7040..0143690a2 100644 --- a/tools/issue_1999.py +++ b/tools/issue_1999.py @@ -97,11 +97,9 @@ def process_file(path): with open(path, 'w', encoding='utf-8') as fp: str = "\n".join(result) + "\n" - try: - # Python 2 + if sys.version_info.major == 2: fp.write(str.decode('utf-8')) - except Exception as e: - # Python 3 + else: fp.write(str) diff --git a/tools/make_distrib.py b/tools/make_distrib.py index 8dac87272..b3211c558 100644 --- a/tools/make_distrib.py +++ b/tools/make_distrib.py @@ -252,11 +252,9 @@ def eval_transfer_file(cef_dir, script_dir, transfer_cfg, output_dir, quiet): str = cfg['source'] + "\n" with open(readme, 'a', encoding='utf-8') as fp: - try: - # Python 2 + if sys.version_info.major == 2: fp.write(str.decode('utf-8')) - except Exception as e: - # Python 3 + else: fp.write(str) # perform any required post-processing