5c30a2e
From 95f1e91ef71d912be5f6dddb6fac68671d850fd6 Mon Sep 17 00:00:00 2001
5c30a2e
From: =?UTF-8?q?Franti=C5=A1ek=20Zatloukal?= <fzatlouk@redhat.com>
5c30a2e
Date: Sun, 24 Jul 2022 11:11:01 +0200
5c30a2e
Subject: [PATCH] Python/Build: Use r instead of rU file read modes
5c30a2e
5c30a2e
Fixes Python 3.11 build
5c30a2e
---
5c30a2e
 python/mozbuild/mozbuild/action/process_define_files.py | 2 +-
5c30a2e
 python/mozbuild/mozbuild/preprocessor.py                | 6 +++---
5c30a2e
 python/mozbuild/mozbuild/util.py                        | 4 +++-
5c30a2e
 3 files changed, 7 insertions(+), 5 deletions(-)
5c30a2e
5c30a2e
diff --git a/python/mozbuild/mozbuild/action/process_define_files.py b/python/mozbuild/mozbuild/action/process_define_files.py
5c30a2e
index 6fff0d1..de2bcf4 100644
5c30a2e
--- a/python/mozbuild/mozbuild/action/process_define_files.py
5c30a2e
+++ b/python/mozbuild/mozbuild/action/process_define_files.py
5c30a2e
@@ -36,7 +36,7 @@ def process_define_file(output, input):
5c30a2e
             not config.substs.get('JS_STANDALONE'):
5c30a2e
         config = PartialConfigEnvironment(mozpath.join(topobjdir, 'js', 'src'))
5c30a2e
 
5c30a2e
-    with open(path, 'rU') as input:
5c30a2e
+    with open(path, 'r') as input:
5c30a2e
         r = re.compile('^\s*#\s*(?P<cmd>[a-z]+)(?:\s+(?P<name>\S+)(?:\s+(?P<value>\S+))?)?', re.U)
5c30a2e
         for l in input:
5c30a2e
             m = r.match(l)
5c30a2e
diff --git a/python/mozbuild/mozbuild/preprocessor.py b/python/mozbuild/mozbuild/preprocessor.py
5c30a2e
index 0e3a750..66f5cf7 100644
5c30a2e
--- a/python/mozbuild/mozbuild/preprocessor.py
5c30a2e
+++ b/python/mozbuild/mozbuild/preprocessor.py
5c30a2e
@@ -517,7 +517,7 @@ class Preprocessor:
5c30a2e
 
5c30a2e
         if args:
5c30a2e
             for f in args:
5c30a2e
-                with io.open(f, 'rU', encoding='utf-8') as input:
5c30a2e
+                with io.open(f, 'r', encoding='utf-8') as input:
5c30a2e
                     self.processFile(input=input, output=out)
5c30a2e
             if depfile:
5c30a2e
                 mk = Makefile()
5c30a2e
@@ -807,7 +807,7 @@ class Preprocessor:
5c30a2e
                     args = self.applyFilters(args)
5c30a2e
                 if not os.path.isabs(args):
5c30a2e
                     args = os.path.join(self.curdir, args)
5c30a2e
-                args = io.open(args, 'rU', encoding='utf-8')
5c30a2e
+                args = io.open(args, 'r', encoding='utf-8')
5c30a2e
             except Preprocessor.Error:
5c30a2e
                 raise
5c30a2e
             except Exception:
5c30a2e
@@ -862,7 +862,7 @@ def preprocess(includes=[sys.stdin], defines={},
5c30a2e
     pp = Preprocessor(defines=defines,
5c30a2e
                       marker=marker)
5c30a2e
     for f in includes:
5c30a2e
-        with io.open(f, 'rU', encoding='utf-8') as input:
5c30a2e
+        with io.open(f, 'r', encoding='utf-8') as input:
5c30a2e
             pp.processFile(input=input, output=output)
5c30a2e
     return pp.includes
5c30a2e
 
5c30a2e
diff --git a/python/mozbuild/mozbuild/util.py b/python/mozbuild/mozbuild/util.py
5c30a2e
index 044cf64..eb992ce 100644
5c30a2e
--- a/python/mozbuild/mozbuild/util.py
5c30a2e
+++ b/python/mozbuild/mozbuild/util.py
5c30a2e
@@ -54,6 +54,8 @@ def exec_(object, globals=None, locals=None):
5c30a2e
 
5c30a2e
 
5c30a2e
 def _open(path, mode):
5c30a2e
+    if mode == "rU":
5c30a2e
+        mode = "r"
5c30a2e
     if 'b' in mode:
5c30a2e
         return io.open(path, mode)
5c30a2e
     return io.open(path, mode, encoding='utf-8', newline='\n')
5c30a2e
@@ -220,7 +222,7 @@ class FileAvoidWrite(BytesIO):
5c30a2e
     still occur, as well as diff capture if requested.
5c30a2e
     """
5c30a2e
 
5c30a2e
-    def __init__(self, filename, capture_diff=False, dry_run=False, readmode='rU'):
5c30a2e
+    def __init__(self, filename, capture_diff=False, dry_run=False, readmode='r'):
5c30a2e
         BytesIO.__init__(self)
5c30a2e
         self.name = filename
5c30a2e
         assert type(capture_diff) == bool
5c30a2e
-- 
5c30a2e
2.37.1
5c30a2e