From ac80d6e4df7db2ef382049af8100d97f5c1c844d Mon Sep 17 00:00:00 2001 From: jalapenopuzzle <8386278+jalapenopuzzle@users.noreply.github.com> Date: Sat, 29 Mar 2025 17:58:17 +1100 Subject: [PATCH] CAM: snapmaker fix invalid escape sequences in regular expressions --- src/Mod/CAM/CAMTests/TestSnapmakerPost.py | 2 +- src/Mod/CAM/Path/Post/scripts/snapmaker_post.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Mod/CAM/CAMTests/TestSnapmakerPost.py b/src/Mod/CAM/CAMTests/TestSnapmakerPost.py index bfa832a438..8cfdae2669 100644 --- a/src/Mod/CAM/CAMTests/TestSnapmakerPost.py +++ b/src/Mod/CAM/CAMTests/TestSnapmakerPost.py @@ -78,7 +78,7 @@ class TestSnapmakerPost(PathTestUtils.PathTestBase): ;machine: Snapmaker 2 A350(T) ;Post Processor: Snapmaker_post ;Cam File: boxtest.fcstd -;Output Time: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{0,6} +;Output Time: \\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{0,6} ;thumbnail: deactivated.""" expected_body = """\ diff --git a/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py b/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py index 49acf4c846..59dfb7b4ff 100644 --- a/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py +++ b/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py @@ -65,7 +65,7 @@ class CoordinatesAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): match = re.match( - "^\s*(?P-?\d+\.?\d*),?\s*(?P-?\d+\.?\d*),?\s*(?P-?\d+\.?\d*)\s*$", values + r"^\s*(?P-?\d+\.?\d*),?\s*(?P-?\d+\.?\d*),?\s*(?P-?\d+\.?\d*)\s*$", values ) if match: # setattr(namespace, self.dest, 'G0 X{0} Y{1} Z{2}'.format(*match.groups())) @@ -79,7 +79,7 @@ class ExtremaAction(argparse.Action): """argparse Action to handle integer extrema (min,max)""" def __call__(self, parser, namespace, values, option_string=None): - if match := re.match("^ *(\d+),? *(\d+) *$", values): + if match := re.match(r"^ *(\d+),? *(\d+) *$", values): # setattr(namespace, self.dest, 'G0 X{0} Y{1} Z{2}'.format(*match.groups())) params = { key: int(value) @@ -507,7 +507,7 @@ class Snapmaker(Path.Post.Processor.PostProcessor): for index, commandline in enumerate( gcode ): # .split(self.values["END_OF_LINE_CHARACTERS"]): - if match := re.match("(?PM0?[34])\D.*(?PS\d+.?\d*)", commandline): + if match := re.match(r"(?PM0?[34])\D.*(?PS\d+.?\d*)", commandline): percent = ( float(match.group("spindle")[1:]) * 100 / self.values["SPINDLE_SPEEDS"]["max"] ) @@ -528,13 +528,13 @@ class Snapmaker(Path.Post.Processor.PostProcessor): relative = False for index, commandline in enumerate(gcode): - if re.match("G90(?:\D|$)", commandline): + if re.match(r"G90(?:\D|$)", commandline): relative = False - elif re.match("G91(?:\D|$)", commandline): + elif re.match(r"G91(?:\D|$)", commandline): relative = True - elif re.match("G0?[12](?:\D|$)", commandline): + elif re.match(r"G0?[12](?:\D|$)", commandline): for axis, value in re.findall( - "(?P[XYZ])(?P-?\d+\.?\d*)(?:\D|$)", commandline + r"(?P[XYZ])(?P-?\d+\.?\d*)(?:\D|$)", commandline ): if relative: position[axis] += float(value)