diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 0a3c8e75..03a8743d 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -184,10 +184,10 @@ def fill_config_defaults(thisconfig): def regsub_file(pattern, repl, path): - with open(path, 'r') as f: + with open(path, 'rb') as f: text = f.read() - text = re.sub(pattern, repl, text) - with open(path, 'w') as f: + text = re.sub(bytes(pattern, 'utf8'), bytes(repl, 'utf8'), text) + with open(path, 'wb') as f: f.write(text) @@ -1724,14 +1724,14 @@ def remove_signing_keys(build_dir): if 'build.gradle' in files: path = os.path.join(root, 'build.gradle') - with open(path, "r") as o: + with open(path, "r", encoding='utf8') as o: lines = o.readlines() changed = False opened = 0 i = 0 - with open(path, "w") as o: + with open(path, "w", encoding='utf8') as o: while i < len(lines): line = lines[i] i += 1 diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index a9be8ef0..ded6cd1a 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -836,7 +836,7 @@ def get_default_app_info(metadatapath=None): for root, dirs, files in os.walk(os.getcwd()): if 'build.gradle' in files: p = os.path.join(root, 'build.gradle') - with open(p) as f: + with open(p, 'rb') as f: data = f.read() m = pattern.search(data) if m: diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index 53c938fb..41ecbb50 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -199,7 +199,7 @@ def scan_source(build_dir, root_dir, build): elif ext == 'java': if not os.path.isfile(fp): continue - with open(fp, 'r') as f: + with open(fp, 'r', encoding='utf8') as f: for line in f: if 'DexClassLoader' in line: count += handleproblem('DexClassLoader', fd, fp) @@ -208,7 +208,7 @@ def scan_source(build_dir, root_dir, build): elif ext == 'gradle': if not os.path.isfile(fp): continue - with open(fp, 'r') as f: + with open(fp, 'r', encoding='utf8') as f: lines = f.readlines() for i, line in enumerate(lines): if is_used_by_gradle(line): diff --git a/tests/build.TestCase b/tests/build.TestCase index b3b90fc3..369c3836 100755 --- a/tests/build.TestCase +++ b/tests/build.TestCase @@ -57,13 +57,13 @@ class BuildTest(unittest.TestCase): fdroidserver.build.config = {} fdroidserver.build.config['build_tools'] = teststring fdroidserver.build.adapt_gradle(testsdir) - pattern = re.compile("buildToolsVersion[\s=]+'%s'\s+" % teststring) + pattern = re.compile(bytes("buildToolsVersion[\s=]+'%s'\s+" % teststring, 'utf8')) for p in ('source-files/fdroid/fdroidclient/build.gradle', 'source-files/Zillode/syncthing-silk/build.gradle', 'source-files/open-keychain/open-keychain/build.gradle', 'source-files/osmandapp/osmand/build.gradle', 'source-files/open-keychain/open-keychain/OpenKeychain/build.gradle'): - with open(os.path.join(testsdir, p), 'r') as f: + with open(os.path.join(testsdir, p), 'rb') as f: filedata = f.read() self.assertIsNotNone(pattern.search(filedata))