blob: 71da8225abbaffcdf5807e6246d1e7ce111cd45c [file] [log] [blame]
Andrew Geissler87f5cff2022-09-30 13:13:31 -05001
2# HG changeset patch
3# User ahochheiden <ahochheiden@mozilla.com>
4# Date 1654151264 0
5# Node ID f54162b2c1f2fe52c6137ab2c3469a1944f58b27
6# Parent 6e7776492240c27732840d65a33dcc440fa1aba0
7Bug 1769631 - Remove 'U' from 'mode' parameters for various 'open' calls to ensure Python3.11 compatibility r=firefox-build-system-reviewers,glandium
8
9The 'U' flag represents "universal newline". It has been deprecated
10since Python3.3. Since then "universal newline" is the default when a
11file is opened in text mode (not bytes). In Python3.11 using the 'U'
12flag throws errors. There should be no harm in removing 'U' from 'open'
13everywhere it is used, and doing allows the use of Python3.11.
14
15For more reading see: https://docs.python.org/3.11/whatsnew/3.11.html#changes-in-the-python-api
16
17Differential Revision: https://phabricator.services.mozilla.com/D147721
18
19Upstream-Status: Backport [https://hg.mozilla.org/mozilla-central/rev/f54162b2c1f2fe52c6137ab2c3469a1944f58b27]
20Signed-off-by: Alexander Kanavin <alex@linutronix.de>
21
22diff --git a/dom/base/usecounters.py b/dom/base/usecounters.py
23--- a/dom/base/usecounters.py
24+++ b/dom/base/usecounters.py
25@@ -3,17 +3,17 @@
26 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
27
28 import collections
29 import re
30
31
32 def read_conf(conf_filename):
33 # Can't read/write from a single StringIO, so make a new one for reading.
34- stream = open(conf_filename, "rU")
35+ stream = open(conf_filename, "r")
36
37 def parse_counters(stream):
38 for line_num, line in enumerate(stream):
39 line = line.rstrip("\n")
40 if not line or line.startswith("//"):
41 # empty line or comment
42 continue
43 m = re.match(r"method ([A-Za-z0-9]+)\.([A-Za-z0-9]+)$", line)
44diff --git a/python/mozbuild/mozbuild/action/process_define_files.py b/python/mozbuild/mozbuild/action/process_define_files.py
45--- a/python/mozbuild/mozbuild/action/process_define_files.py
46+++ b/python/mozbuild/mozbuild/action/process_define_files.py
47@@ -31,17 +31,17 @@ def process_define_file(output, input):
48
49 config = PartialConfigEnvironment(topobjdir)
50
51 if mozpath.basedir(
52 path, [mozpath.join(topsrcdir, "js/src")]
53 ) and not config.substs.get("JS_STANDALONE"):
54 config = PartialConfigEnvironment(mozpath.join(topobjdir, "js", "src"))
55
56- with open(path, "rU") as input:
57+ with open(path, "r") as input:
58 r = re.compile(
59 "^\s*#\s*(?P<cmd>[a-z]+)(?:\s+(?P<name>\S+)(?:\s+(?P<value>\S+))?)?", re.U
60 )
61 for l in input:
62 m = r.match(l)
63 if m:
64 cmd = m.group("cmd")
65 name = m.group("name")
66diff --git a/python/mozbuild/mozbuild/backend/base.py b/python/mozbuild/mozbuild/backend/base.py
67--- a/python/mozbuild/mozbuild/backend/base.py
68+++ b/python/mozbuild/mozbuild/backend/base.py
69@@ -267,17 +267,17 @@ class BuildBackend(LoggingMixin):
70 If an exception is raised, |mach build| will fail with a
71 non-zero exit code.
72 """
73 self._write_purgecaches(config)
74
75 return status
76
77 @contextmanager
78- def _write_file(self, path=None, fh=None, readmode="rU"):
79+ def _write_file(self, path=None, fh=None, readmode="r"):
80 """Context manager to write a file.
81
82 This is a glorified wrapper around FileAvoidWrite with integration to
83 update the summary data on this instance.
84
85 Example usage:
86
87 with self._write_file('foo.txt') as fh:
88diff --git a/python/mozbuild/mozbuild/preprocessor.py b/python/mozbuild/mozbuild/preprocessor.py
89--- a/python/mozbuild/mozbuild/preprocessor.py
90+++ b/python/mozbuild/mozbuild/preprocessor.py
91@@ -526,17 +526,17 @@ class Preprocessor:
92 if not options.output:
93 raise Preprocessor.Error(
94 self, "--depend doesn't work with stdout", None
95 )
96 depfile = get_output_file(options.depend)
97
98 if args:
99 for f in args:
100- with io.open(f, "rU", encoding="utf-8") as input:
101+ with io.open(f, "r", encoding="utf-8") as input:
102 self.processFile(input=input, output=out)
103 if depfile:
104 mk = Makefile()
105 mk.create_rule([six.ensure_text(options.output)]).add_dependencies(
106 self.includes
107 )
108 mk.dump(depfile)
109 depfile.close()
110@@ -855,17 +855,17 @@ class Preprocessor:
111 self.checkLineNumbers = False
112 if isName:
113 try:
114 args = _to_text(args)
115 if filters:
116 args = self.applyFilters(args)
117 if not os.path.isabs(args):
118 args = os.path.join(self.curdir, args)
119- args = io.open(args, "rU", encoding="utf-8")
120+ args = io.open(args, "r", encoding="utf-8")
121 except Preprocessor.Error:
122 raise
123 except Exception:
124 raise Preprocessor.Error(self, "FILE_NOT_FOUND", _to_text(args))
125 self.checkLineNumbers = bool(
126 re.search("\.(js|jsm|java|webidl)(?:\.in)?$", args.name)
127 )
128 oldFile = self.context["FILE"]
129@@ -909,17 +909,17 @@ class Preprocessor:
130
131 def do_error(self, args):
132 raise Preprocessor.Error(self, "Error: ", _to_text(args))
133
134
135 def preprocess(includes=[sys.stdin], defines={}, output=sys.stdout, marker="#"):
136 pp = Preprocessor(defines=defines, marker=marker)
137 for f in includes:
138- with io.open(f, "rU", encoding="utf-8") as input:
139+ with io.open(f, "r", encoding="utf-8") as input:
140 pp.processFile(input=input, output=output)
141 return pp.includes
142
143
144 # Keep this module independently executable.
145 if __name__ == "__main__":
146 pp = Preprocessor()
147 pp.handleCommandLine(None, True)
148diff --git a/python/mozbuild/mozbuild/util.py b/python/mozbuild/mozbuild/util.py
149--- a/python/mozbuild/mozbuild/util.py
150+++ b/python/mozbuild/mozbuild/util.py
151@@ -231,17 +231,17 @@ class FileAvoidWrite(BytesIO):
152 enabled by default because it a) doesn't make sense for binary files b)
153 could add unwanted overhead to calls.
154
155 Additionally, there is dry run mode where the file is not actually written
156 out, but reports whether the file was existing and would have been updated
157 still occur, as well as diff capture if requested.
158 """
159
160- def __init__(self, filename, capture_diff=False, dry_run=False, readmode="rU"):
161+ def __init__(self, filename, capture_diff=False, dry_run=False, readmode="r"):
162 BytesIO.__init__(self)
163 self.name = filename
164 assert type(capture_diff) == bool
165 assert type(dry_run) == bool
166 assert "r" in readmode
167 self._capture_diff = capture_diff
168 self._write_to_file = not dry_run
169 self.diff = None
170diff --git a/python/mozbuild/mozpack/files.py b/python/mozbuild/mozpack/files.py
171--- a/python/mozbuild/mozpack/files.py
172+++ b/python/mozbuild/mozpack/files.py
173@@ -549,17 +549,17 @@ class PreprocessedFile(BaseFile):
174 self.defines = defines
175 self.extra_depends = list(extra_depends or [])
176 self.silence_missing_directive_warnings = silence_missing_directive_warnings
177
178 def inputs(self):
179 pp = Preprocessor(defines=self.defines, marker=self.marker)
180 pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings)
181
182- with _open(self.path, "rU") as input:
183+ with _open(self.path, "r") as input:
184 with _open(os.devnull, "w") as output:
185 pp.processFile(input=input, output=output)
186
187 # This always yields at least self.path.
188 return pp.includes
189
190 def copy(self, dest, skip_if_older=True):
191 """
192@@ -606,17 +606,17 @@ class PreprocessedFile(BaseFile):
193 return False
194
195 deps_out = None
196 if self.depfile:
197 deps_out = FileAvoidWrite(self.depfile)
198 pp = Preprocessor(defines=self.defines, marker=self.marker)
199 pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings)
200
201- with _open(self.path, "rU") as input:
202+ with _open(self.path, "r") as input:
203 pp.processFile(input=input, output=dest, depfile=deps_out)
204
205 dest.close()
206 if self.depfile:
207 deps_out.close()
208
209 return True
210
211