Skip to content

Commit 44b548d

Browse files
committed
#27364: fix "incorrect" uses of escape character in the stdlib.
And most of the tools. Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and Martin Panter.
1 parent 513d747 commit 44b548d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+328
-328
lines changed

Lib/_osx_support.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def _remove_universal_flags(_config_vars):
210210
# Do not alter a config var explicitly overridden by env var
211211
if cv in _config_vars and cv not in os.environ:
212212
flags = _config_vars[cv]
213-
flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
213+
flags = re.sub(r'-arch\s+\w+\s', ' ', flags, re.ASCII)
214214
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
215215
_save_modified_value(_config_vars, cv, flags)
216216

@@ -232,7 +232,7 @@ def _remove_unsupported_archs(_config_vars):
232232
if 'CC' in os.environ:
233233
return _config_vars
234234

235-
if re.search('-arch\s+ppc', _config_vars['CFLAGS']) is not None:
235+
if re.search(r'-arch\s+ppc', _config_vars['CFLAGS']) is not None:
236236
# NOTE: Cannot use subprocess here because of bootstrap
237237
# issues when building Python itself
238238
status = os.system(
@@ -251,7 +251,7 @@ def _remove_unsupported_archs(_config_vars):
251251
for cv in _UNIVERSAL_CONFIG_VARS:
252252
if cv in _config_vars and cv not in os.environ:
253253
flags = _config_vars[cv]
254-
flags = re.sub('-arch\s+ppc\w*\s', ' ', flags)
254+
flags = re.sub(r'-arch\s+ppc\w*\s', ' ', flags)
255255
_save_modified_value(_config_vars, cv, flags)
256256

257257
return _config_vars
@@ -267,7 +267,7 @@ def _override_all_archs(_config_vars):
267267
for cv in _UNIVERSAL_CONFIG_VARS:
268268
if cv in _config_vars and '-arch' in _config_vars[cv]:
269269
flags = _config_vars[cv]
270-
flags = re.sub('-arch\s+\w+\s', ' ', flags)
270+
flags = re.sub(r'-arch\s+\w+\s', ' ', flags)
271271
flags = flags + ' ' + arch
272272
_save_modified_value(_config_vars, cv, flags)
273273

@@ -465,7 +465,7 @@ def get_platform_osx(_config_vars, osname, release, machine):
465465

466466
machine = 'fat'
467467

468-
archs = re.findall('-arch\s+(\S+)', cflags)
468+
archs = re.findall(r'-arch\s+(\S+)', cflags)
469469
archs = tuple(sorted(set(archs)))
470470

471471
if len(archs) == 1:

Lib/csv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ def _guess_quote_and_delimiter(self, data, delimiters):
215215
"""
216216

217217
matches = []
218-
for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
219-
'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
220-
'(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
221-
'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
218+
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
219+
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
220+
r'(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
221+
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
222222
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
223223
matches = regexp.findall(data)
224224
if matches:

Lib/difflib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
14151415
import re
14161416

14171417
# regular expression for finding intraline change indices
1418-
change_re = re.compile('(\++|\-+|\^+)')
1418+
change_re = re.compile(r'(\++|\-+|\^+)')
14191419

14201420
# create the difference iterator to generate the differences
14211421
diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)

Lib/distutils/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def ensure_string(self, option, default=None):
221221
self._ensure_stringlike(option, "string", default)
222222

223223
def ensure_string_list(self, option):
224-
"""Ensure that 'option' is a list of strings. If 'option' is
224+
r"""Ensure that 'option' is a list of strings. If 'option' is
225225
currently a string, we split it either on /,\s*/ or /\s+/, so
226226
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
227227
["foo", "bar", "baz"].

Lib/distutils/command/bdist_msi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ def add_ui(self):
623623
cost = PyDialog(db, "DiskCostDlg", x, y, w, h, modal, title,
624624
"OK", "OK", "OK", bitmap=False)
625625
cost.text("Title", 15, 6, 200, 15, 0x30003,
626-
"{\DlgFontBold8}Disk Space Requirements")
626+
r"{\DlgFontBold8}Disk Space Requirements")
627627
cost.text("Description", 20, 20, 280, 20, 0x30003,
628628
"The disk space required for the installation of the selected features.")
629629
cost.text("Text", 20, 53, 330, 60, 3,
@@ -670,7 +670,7 @@ def add_ui(self):
670670
progress = PyDialog(db, "ProgressDlg", x, y, w, h, modeless, title,
671671
"Cancel", "Cancel", "Cancel", bitmap=False)
672672
progress.text("Title", 20, 15, 200, 15, 0x30003,
673-
"{\DlgFontBold8}[Progress1] [ProductName]")
673+
r"{\DlgFontBold8}[Progress1] [ProductName]")
674674
progress.text("Text", 35, 65, 300, 30, 3,
675675
"Please wait while the Installer [Progress2] [ProductName]. "
676676
"This may take several minutes.")

Lib/distutils/command/build_scripts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run(self):
5151

5252

5353
def copy_scripts(self):
54-
"""Copy each script listed in 'self.scripts'; if it's marked as a
54+
r"""Copy each script listed in 'self.scripts'; if it's marked as a
5555
Python script in the Unix way (first line matches 'first_line_re',
5656
ie. starts with "\#!" and contains "python"), then adjust the first
5757
line to refer to the current Python interpreter as we copy.

Lib/distutils/cygwinccompiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def check_config_h():
368368
return (CONFIG_H_UNCERTAIN,
369369
"couldn't read '%s': %s" % (fn, exc.strerror))
370370

371-
RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
371+
RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
372372

373373
def _find_exe_version(cmd):
374374
"""Find the version of an executable by running `cmd` in the shell.

Lib/distutils/msvc9compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ def _remove_visual_c_ref(self, manifest_file):
716716
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
717717
re.DOTALL)
718718
manifest_buf = re.sub(pattern, "", manifest_buf)
719-
pattern = "<dependentAssembly>\s*</dependentAssembly>"
719+
pattern = r"<dependentAssembly>\s*</dependentAssembly>"
720720
manifest_buf = re.sub(pattern, "", manifest_buf)
721721
# Now see if any other assemblies are referenced - if not, we
722722
# don't want a manifest embedded.

Lib/distutils/sysconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def parse_config_h(fp, g=None):
278278

279279
# Regexes needed for parsing Makefile (and similar syntaxes,
280280
# like old-style Setup files).
281-
_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
281+
_variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
282282
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
283283
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
284284

Lib/distutils/versionpredicate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def split_provision(value):
154154
global _provision_rx
155155
if _provision_rx is None:
156156
_provision_rx = re.compile(
157-
"([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$",
157+
r"([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$",
158158
re.ASCII)
159159
value = value.strip()
160160
m = _provision_rx.match(value)

0 commit comments

Comments
 (0)