From 64ecfe7a0e427fcafa3ac4f970f83ff05c1f85d0 Mon Sep 17 00:00:00 2001
From: bgbsww
Date: Thu, 26 Sep 2024 18:12:20 -0400
Subject: [PATCH] Make python Regex Strings raw to avoid py3.12 SyntaxError
---
.../addonmanager_widget_readme_browser.py | 6 +++---
src/Mod/AddonManager/addonmanager_macro.py | 4 ++--
.../AddonManager/addonmanager_macro_parser.py | 2 +-
.../addonmanager_workers_startup.py | 2 +-
src/Mod/BIM/ArchAxis.py | 2 +-
src/Mod/BIM/ArchBuildingPart.py | 4 ++--
src/Mod/BIM/ArchRebar.py | 2 +-
src/Mod/BIM/ArchReference.py | 14 +++++++-------
src/Mod/BIM/ArchSectionPlane.py | 16 ++++++++--------
src/Mod/BIM/ArchSite.py | 2 +-
src/Mod/BIM/bimcommands/BimClassification.py | 10 +++++-----
src/Mod/BIM/bimcommands/BimLibrary.py | 8 ++++----
src/Mod/BIM/bimcommands/BimPreflight.py | 2 +-
src/Mod/BIM/bimcommands/BimSetup.py | 2 +-
src/Mod/BIM/bimcommands/BimTutorial.py | 16 ++++++++--------
src/Mod/BIM/importers/importIFClegacy.py | 2 +-
src/Mod/BIM/nativeifc/ifc_psets.py | 2 +-
src/Mod/BIM/utils/buildPsets.py | 2 +-
src/Mod/CAM/Path/Post/Utils.py | 8 ++++----
src/Mod/CAM/Path/Post/scripts/gcode_pre.py | 2 +-
src/Mod/CAM/Path/Tool/Gui/BitEdit.py | 2 +-
src/Mod/Draft/draftguitools/gui_trackers.py | 6 +++---
src/Mod/Draft/importDXF.py | 18 +++++++++---------
src/Mod/Draft/importSVG.py | 2 +-
src/Mod/Import/App/SCL/Part21.py | 2 +-
src/Tools/generateBase/generateTools.py | 12 ++++++------
26 files changed, 75 insertions(+), 75 deletions(-)
diff --git a/src/Mod/AddonManager/Widgets/addonmanager_widget_readme_browser.py b/src/Mod/AddonManager/Widgets/addonmanager_widget_readme_browser.py
index ae452af344..fade43283d 100644
--- a/src/Mod/AddonManager/Widgets/addonmanager_widget_readme_browser.py
+++ b/src/Mod/AddonManager/Widgets/addonmanager_widget_readme_browser.py
@@ -83,12 +83,12 @@ class WidgetReadmeBrowser(QtWidgets.QTextBrowser):
self.setGeometry(geometry)
def _clean_markdown(self, md: str):
- # Remove some HTML tags (for now just img and br, which are the most common offenders that break rendering)
+ # Remove some HTML tags ( for now just img and br, which are the most common offenders that break rendering )
br_re = re.compile(r"
")
img_re = re.compile(r"
]+)(?:'|\").*?\/?>")
- cleaned = br_re.sub("\n", md)
- cleaned = img_re.sub("[html tag removed]", cleaned)
+ cleaned = br_re.sub(r"\n", md)
+ cleaned = img_re.sub(r"[html tag removed]", cleaned)
return cleaned
diff --git a/src/Mod/AddonManager/addonmanager_macro.py b/src/Mod/AddonManager/addonmanager_macro.py
index 93e59f6b0e..2af34c7b2c 100644
--- a/src/Mod/AddonManager/addonmanager_macro.py
+++ b/src/Mod/AddonManager/addonmanager_macro.py
@@ -183,7 +183,7 @@ class Macro:
desc = "No description available"
self.desc = desc
self.comment, _, _ = desc.partition("
", "", self.comment) # Strip any tags
+ self.comment = re.sub(r"<.*?>", "", self.comment) # Strip any tags
self.url = url
if isinstance(code, list):
code = "".join(code)
@@ -201,7 +201,7 @@ class Macro:
def _fetch_raw_code(self, page_data) -> Optional[str]:
"""Fetch code from the raw code URL specified on the wiki page."""
code = None
- self.raw_code_url = re.findall('rawcodeurl.*?href="(http.*?)">', page_data)
+ self.raw_code_url = re.findall(r'rawcodeurl.*?href="(http.*?)">', page_data)
if self.raw_code_url:
self.raw_code_url = self.raw_code_url[0]
u2 = Macro.blocking_get(self.raw_code_url)
diff --git a/src/Mod/AddonManager/addonmanager_macro_parser.py b/src/Mod/AddonManager/addonmanager_macro_parser.py
index 26dc41bc26..8a560c79ae 100644
--- a/src/Mod/AddonManager/addonmanager_macro_parser.py
+++ b/src/Mod/AddonManager/addonmanager_macro_parser.py
@@ -201,7 +201,7 @@ class MacroParser:
def _cleanup_comment(self):
"""Remove HTML from the comment line, and truncate it at 512 characters."""
- self.parse_results["comment"] = re.sub("<.*?>", "", self.parse_results["comment"])
+ self.parse_results["comment"] = re.sub(r"<.*?>", "", self.parse_results["comment"])
if len(self.parse_results["comment"]) > 512:
self.parse_results["comment"] = self.parse_results["comment"][:511] + "…"
diff --git a/src/Mod/AddonManager/addonmanager_workers_startup.py b/src/Mod/AddonManager/addonmanager_workers_startup.py
index 5b6e68d8ab..6fd6fee5ae 100644
--- a/src/Mod/AddonManager/addonmanager_workers_startup.py
+++ b/src/Mod/AddonManager/addonmanager_workers_startup.py
@@ -399,7 +399,7 @@ class CreateAddonListWorker(QtCore.QThread):
)
return
p = p.data().decode("utf8")
- macros = re.findall('title="(Macro.*?)"', p)
+ macros = re.findall(r'title="(Macro.*?)"', p)
macros = [mac for mac in macros if "translated" not in mac]
macro_names = []
for _, mac in enumerate(macros):
diff --git a/src/Mod/BIM/ArchAxis.py b/src/Mod/BIM/ArchAxis.py
index 2c1e97daa7..289d915fb0 100644
--- a/src/Mod/BIM/ArchAxis.py
+++ b/src/Mod/BIM/ArchAxis.py
@@ -398,7 +398,7 @@ class _ViewProviderAxis:
except Exception:
# workaround for pivy SoInput.setBuffer() bug
buf = buf.replace("\n","")
- pts = re.findall("point \[(.*?)\]",buf)[0]
+ pts = re.findall(r"point \[(.*?)\]",buf)[0]
pts = pts.split(",")
pc = []
for point in pts:
diff --git a/src/Mod/BIM/ArchBuildingPart.py b/src/Mod/BIM/ArchBuildingPart.py
index 82ffa756e2..0b128b9685 100644
--- a/src/Mod/BIM/ArchBuildingPart.py
+++ b/src/Mod/BIM/ArchBuildingPart.py
@@ -971,12 +971,12 @@ class ViewProviderBuildingPart:
iv = self.Object.Shape.writeInventor()
import re
if colors:
- if len(re.findall("IndexedFaceSet",iv)) == len(obj.Shape.Faces):
+ if len(re.findall(r"IndexedFaceSet",iv)) == len(obj.Shape.Faces):
# convert colors to iv representations
colors = ["Material { diffuseColor "+str(color[0])+" "+str(color[1])+" "+str(color[2])+"}\n IndexedFaceSet" for color in colors]
# replace
callback.v=iter(colors)
- iv = re.sub("IndexedFaceSet",callback,iv)
+ iv = re.sub(r"IndexedFaceSet",callback,iv)
else:
print("Debug: IndexedFaceSet mismatch in",obj.Label)
# save embedded file
diff --git a/src/Mod/BIM/ArchRebar.py b/src/Mod/BIM/ArchRebar.py
index 414445232e..f672994bd8 100644
--- a/src/Mod/BIM/ArchRebar.py
+++ b/src/Mod/BIM/ArchRebar.py
@@ -450,7 +450,7 @@ class _ViewProviderRebar(ArchComponent.ViewProviderComponent):
import re
self.centerline = coin.SoSeparator()
comp = Part.makeCompound(obj.Proxy.wires)
- buf = re.findall("point \[(.*?)\]",comp.writeInventor().replace("\n",""))
+ buf = re.findall(r"point \[(.*?)\]",comp.writeInventor().replace("\n",""))
pts = [zip(*[iter( c.split() )]*3) for c in buf]
for pt in pts:
vlist = [ [float(v[0]),float(v[1]),float(v[2])] for v in pt ]
diff --git a/src/Mod/BIM/ArchReference.py b/src/Mod/BIM/ArchReference.py
index 92ac62f05f..ef51cc933a 100644
--- a/src/Mod/BIM/ArchReference.py
+++ b/src/Mod/BIM/ArchReference.py
@@ -390,28 +390,28 @@ class ArchReference:
for line in docf:
line = line.decode("utf8")
if "
", "\n\n")
- tooltip = re.sub("<.*?>", "", tooltip) # strip html tags
+ tooltip = re.sub(r"<.*?>", "", tooltip) # strip html tags
return tooltip
def testAll(self):
diff --git a/src/Mod/BIM/bimcommands/BimSetup.py b/src/Mod/BIM/bimcommands/BimSetup.py
index 5a8692ef6e..eb111f3539 100644
--- a/src/Mod/BIM/bimcommands/BimSetup.py
+++ b/src/Mod/BIM/bimcommands/BimSetup.py
@@ -689,7 +689,7 @@ class BIM_Setup:
u.close()
d = json.loads(r)
l = d[-1]["body"]
- links = re.findall("http.*?zip", l)
+ links = re.findall(r"http.*?zip", l)
pyv = (
"python-"
+ str(sys.version_info.major)
diff --git a/src/Mod/BIM/bimcommands/BimTutorial.py b/src/Mod/BIM/bimcommands/BimTutorial.py
index c52c88e891..51d82f049e 100644
--- a/src/Mod/BIM/bimcommands/BimTutorial.py
+++ b/src/Mod/BIM/bimcommands/BimTutorial.py
@@ -141,16 +141,16 @@ class BIM_Tutorial:
f.close()
# setup title and progress bar
- self.steps = len(re.findall("infotext", html)) - 1
+ self.steps = len(re.findall(r"infotext", html)) - 1
# setup description texts and goals
self.descriptions = [""] + re.findall(
"
(.*?)Tutorial step", html
)
- self.goal1 = re.findall('goal1">(.*?)(.*?)(.*?)(.*?)(.*?)(.*?)(.*?)(.*?)") for t in self.test1]
@@ -162,14 +162,14 @@ class BIM_Tutorial:
)
nd = []
for descr in self.descriptions:
- imagepaths = re.findall('Pset_(.*?)", p)
+psets = re.findall(r">Pset_(.*?)", p)
# retrieve xml data from each Pset type
psetdefs = ""
diff --git a/src/Mod/CAM/Path/Post/Utils.py b/src/Mod/CAM/Path/Post/Utils.py
index bd6740fac8..9cde8c0613 100644
--- a/src/Mod/CAM/Path/Post/Utils.py
+++ b/src/Mod/CAM/Path/Post/Utils.py
@@ -97,7 +97,7 @@ class FilenameGenerator:
ext = ".nc"
# Check for invalid matches
- for match in re.findall("%(.)", outputpath):
+ for match in re.findall(r"%(.)", outputpath):
Path.Log.debug(f"match: {match}")
if match not in validPathSubstitutions:
outputpath = outputpath.replace(f"%{match}", "")
@@ -105,7 +105,7 @@ class FilenameGenerator:
"Invalid substitution strings will be ignored in output path: %s\n" % match
)
- for match in re.findall("%(.)", filename):
+ for match in re.findall(r"%(.)", filename):
Path.Log.debug(f"match: {match}")
if match not in validFilenameSubstitutions:
filename = filename.replace(f"%{match}", "")
@@ -156,10 +156,10 @@ class FilenameGenerator:
temp_filename = self.qualified_filename
Path.Log.debug(f"temp_filename: {temp_filename}")
explicit_sequence = False
- matches = re.findall("%S", temp_filename)
+ matches = re.findall(r"%S", temp_filename)
if matches:
Path.Log.debug(f"matches: {matches}")
- temp_filename = re.sub("%S", str(self.sequencenumber), temp_filename)
+ temp_filename = re.sub(r"%S", str(self.sequencenumber), temp_filename)
explicit_sequence = True
subpart = f"-{self.subpartname}" if self.subpartname else ""
diff --git a/src/Mod/CAM/Path/Post/scripts/gcode_pre.py b/src/Mod/CAM/Path/Post/scripts/gcode_pre.py
index 714298b7d5..36341d7176 100644
--- a/src/Mod/CAM/Path/Post/scripts/gcode_pre.py
+++ b/src/Mod/CAM/Path/Post/scripts/gcode_pre.py
@@ -188,7 +188,7 @@ def _identifygcodeByToolNumberList(filename):
gfile.close()
# Regular expression to match tool changes in the format 'M6 Tn'
- p = re.compile("[mM]+?\s?0?6\s?T\d*\s")
+ p = re.compile(r"[mM]+?\s?0?6\s?T\d*\s")
# split the gcode on tool changes
paths = re.split("([mM]+?\s?0?6\s?T\d*\s)", gcode)
diff --git a/src/Mod/CAM/Path/Tool/Gui/BitEdit.py b/src/Mod/CAM/Path/Tool/Gui/BitEdit.py
index 9b18fe7f4f..dda820393b 100644
--- a/src/Mod/CAM/Path/Tool/Gui/BitEdit.py
+++ b/src/Mod/CAM/Path/Tool/Gui/BitEdit.py
@@ -108,7 +108,7 @@ class ToolBitEditor(object):
# which aren't being needed anymore.
def labelText(name):
- return re.sub("([A-Z][a-z]+)", r" \1", re.sub("([A-Z]+)", r" \1", name))
+ return re.sub(r"([A-Z][a-z]+)", r" \1", re.sub(r"([A-Z]+)", r" \1", name))
layout = self.form.bitParams.layout()
ui = FreeCADGui.UiLoader()
diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py
index 6da39c00be..2389bc8240 100644
--- a/src/Mod/Draft/draftguitools/gui_trackers.py
+++ b/src/Mod/Draft/draftguitools/gui_trackers.py
@@ -462,7 +462,7 @@ class bsplineTracker(Tracker):
except Exception:
# workaround for pivy SoInput.setBuffer() bug
buf = buf.replace("\n", "")
- pts = re.findall("point \\[(.*?)\\]", buf)[0]
+ pts = re.findall(r"point \\[(.*?)\\]", buf)[0]
pts = pts.split(",")
pc = []
for p in pts:
@@ -540,7 +540,7 @@ class bezcurveTracker(Tracker):
except Exception:
# workaround for pivy SoInput.setBuffer() bug
buf = buf.replace("\n","")
- pts = re.findall("point \\[(.*?)\\]", buf)[0]
+ pts = re.findall(r"point \\[(.*?)\\]", buf)[0]
pts = pts.split(",")
pc = []
for p in pts:
@@ -669,7 +669,7 @@ class arcTracker(Tracker):
except Exception:
# workaround for pivy SoInput.setBuffer() bug
buf = buf.replace("\n", "")
- pts = re.findall("point \\[(.*?)\\]", buf)[0]
+ pts = re.findall(r"point \\[(.*?)\\]", buf)[0]
pts = pts.split(",")
pc = []
for p in pts:
diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py
index 9868aa1077..d908465c54 100644
--- a/src/Mod/Draft/importDXF.py
+++ b/src/Mod/Draft/importDXF.py
@@ -221,18 +221,18 @@ def deformat(text):
The deformatted string.
"""
# remove ACAD string formatation
- # t = re.sub('{([^!}]([^}]|\n)*)}', '', text)
+ # t = re.sub(r'{([^!}]([^}]|\n)*)}', '', text)
# print("input text: ",text)
t = text.strip("{}")
- t = re.sub("\\\\.*?;", "", t)
+ t = re.sub(r"\\\\.*?;", "", t)
# replace UTF codes by utf chars
sts = re.split("\\\\(U\\+....)", t)
t = u"".join(sts)
# replace degrees, diameters chars
- t = re.sub('%%d', u'°', t)
- t = re.sub('%%c', u'Ø', t)
- t = re.sub('%%D', u'°', t)
- t = re.sub('%%C', u'Ø', t)
+ t = re.sub(r'%%d', u'°', t)
+ t = re.sub(r'%%c', u'Ø', t)
+ t = re.sub(r'%%D', u'°', t)
+ t = re.sub(r'%%C', u'Ø', t)
# print("output text: ", t)
return t
@@ -3934,7 +3934,7 @@ def exportPage(page, filename):
f = pyopen(page.Template, "rb")
svgtemplate = f.read()
f.close()
- editables = re.findall("freecad:editable=\"(.*?)\"", svgtemplate)
+ editables = re.findall(r"freecad:editable=\"(.*?)\"", svgtemplate)
values = page.EditableTexts
for i in range(len(editables)):
if len(values) > i:
@@ -3953,7 +3953,7 @@ def exportPage(page, filename):
blocks = ""
entities = ""
r12 = False
- ver = re.findall("\\$ACADVER\n.*?\n(.*?)\n", template)
+ ver = re.findall(r"\\$ACADVER\n.*?\n(.*?)\n", template)
if ver:
# at the moment this is not used.
# TODO: if r12, do not print ellipses or splines
@@ -3969,7 +3969,7 @@ def exportPage(page, filename):
if entities:
template = template.replace("999\n$entities", entities[:-1])
c = dxfcounter()
- pat = re.compile("(_handle_)")
+ pat = re.compile(r"(_handle_)")
template = pat.sub(c.incr, template)
f = pyopen(filename, "w")
f.write(template)
diff --git a/src/Mod/Draft/importSVG.py b/src/Mod/Draft/importSVG.py
index dda9191981..5bd0ed08e0 100644
--- a/src/Mod/Draft/importSVG.py
+++ b/src/Mod/Draft/importSVG.py
@@ -1712,7 +1712,7 @@ def getContents(filename, tag, stringmode=False):
searchpat = '<' + tag + '.*?' + tag + '>'
tags = re.findall(searchpat, contents)
for t in tags:
- tagid = re.findall('id="(.*?)"', t)
+ tagid = re.findall(r'id="(.*?)"', t)
if tagid:
tagid = tagid[0]
else:
diff --git a/src/Mod/Import/App/SCL/Part21.py b/src/Mod/Import/App/SCL/Part21.py
index e76ce3eb6d..62ec1dda22 100644
--- a/src/Mod/Import/App/SCL/Part21.py
+++ b/src/Mod/Import/App/SCL/Part21.py
@@ -34,7 +34,7 @@ from . import Utils
import time
-INSTANCE_DEFINITION_RE = re.compile("#(\d+)[^\S\n]?=[^\S\n]?(.*?)\((.*)\)[^\S\n]?;[\\r]?$")
+INSTANCE_DEFINITION_RE = re.compile(r"#(\d+)[^\S\n]?=[^\S\n]?(.*?)\((.*)\)[^\S\n]?;[\\r]?$")
def map_string_to_num(stri):
diff --git a/src/Tools/generateBase/generateTools.py b/src/Tools/generateBase/generateTools.py
index 0c1c34a088..234e883d2d 100644
--- a/src/Tools/generateBase/generateTools.py
+++ b/src/Tools/generateBase/generateTools.py
@@ -141,10 +141,10 @@ def replace(template, dict, file):
"Test: copy a block of lines, with full processing"
import re
- rex = re.compile("@([^@]+)@")
+ rex = re.compile(r"@([^@]+)@")
rbe = re.compile(r"\+")
- ren = re.compile("-")
- rco = re.compile("= ")
+ ren = re.compile(r"-")
+ rco = re.compile(r"= ")
x = 23 # just a variable to try substitution
cop = copier(rex, dict, rbe, ren, rco)
lines_block = [line + "\n" for line in template.split("\n")]
@@ -156,10 +156,10 @@ if __name__ == "__main__":
"Test: copy a block of lines, with full processing"
import re
- rex = re.compile("@([^@]+)@")
+ rex = re.compile(r"@([^@]+)@")
rbe = re.compile(r"\+")
- ren = re.compile("-")
- rco = re.compile("= ")
+ ren = re.compile(r"-")
+ rco = re.compile(r"= ")
x = 23 # just a variable to try substitution
cop = copier(rex, globals(), rbe, ren, rco)
lines_block = [