From f3fdac7e5a4d0be848dc84116a4a3ef7bf82495e Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Mon, 28 Jan 2019 11:18:43 +0100 Subject: [PATCH] Use raw strings for all regexps. No exceptions please. --- src/octoprint/filemanager/storage.py | 2 +- src/octoprint/plugins/cura/profile.py | 10 +-- .../plugins/virtual_printer/virtual.py | 70 +++++++++---------- src/octoprint/printer/__init__.py | 4 +- src/octoprint/server/__init__.py | 6 +- src/octoprint/server/api/printer.py | 2 +- src/octoprint/server/util/webassets.py | 6 +- src/octoprint/settings.py | 8 +-- src/octoprint/timelapse.py | 6 +- src/octoprint/util/comm.py | 54 +++++++------- tests/util/test_comm_helpers.py | 7 +- 11 files changed, 88 insertions(+), 87 deletions(-) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index f7ddea77f..d82819465 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -450,7 +450,7 @@ class LocalFileStorage(StorageInterface): This storage type implements :func:`path_on_disk`. """ - _UNICODE_VARIATIONS = re.compile(u"[\uFE00-\uFE0F]") + _UNICODE_VARIATIONS = re.compile(u"[\uFE00-\uFE0F]", re.U) @classmethod def _no_unicode_variations(cls, text): diff --git a/src/octoprint/plugins/cura/profile.py b/src/octoprint/plugins/cura/profile.py index 091972f22..379281beb 100644 --- a/src/octoprint/plugins/cura/profile.py +++ b/src/octoprint/plugins/cura/profile.py @@ -354,12 +354,12 @@ G90 ;absolute positioning class Profile(object): - regex_extruder_offset = re.compile("extruder_offset_([xy])(\d)") - regex_filament_diameter = re.compile("filament_diameter(\d?)") - regex_print_temperature = re.compile("print_temperature(\d?)") - regex_strip_comments = re.compile(";.*$", flags=re.MULTILINE) + regex_extruder_offset = re.compile(r"extruder_offset_([xy])(\d)") + regex_filament_diameter = re.compile(r"filament_diameter(\d?)") + regex_print_temperature = re.compile(r"print_temperature(\d?)") + regex_strip_comments = re.compile(r";.*$", flags=re.MULTILINE) - regex_broken_replacements = re.compile("\?([a-zA-Z0-9_]*)\?") + regex_broken_replacements = re.compile(r"\?([a-zA-Z0-9_]*)\?") @classmethod def from_cura_ini(cls, path): diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 3f27a80c2..899ae1ff5 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -23,16 +23,16 @@ from octoprint.plugin import plugin_manager from octoprint.util import RepeatedTimer class VirtualPrinter(object): - command_regex = re.compile("^([GMTF])(\d+)") - sleep_regex = re.compile("sleep (\d+)") - sleep_after_regex = re.compile("sleep_after ([GMTF]\d+) (\d+)") - sleep_after_next_regex = re.compile("sleep_after_next ([GMTF]\d+) (\d+)") - custom_action_regex = re.compile("action_custom ([a-zA-Z0-9_]+)(\s+.*)?") - prepare_ok_regex = re.compile("prepare_ok (.*)") - send_regex = re.compile("send (.*)") - set_ambient_regex = re.compile("set_ambient ([-+]?[0-9]*\.?[0-9]+)") - start_sd_regex = re.compile("start_sd (.*)") - select_sd_regex = re.compile("select_sd (.*)") + command_regex = re.compile(r"^([GMTF])(\d+)") + sleep_regex = re.compile(r"sleep (\d+)") + sleep_after_regex = re.compile(r"sleep_after ([GMTF]\d+) (\d+)") + sleep_after_next_regex = re.compile(r"sleep_after_next ([GMTF]\d+) (\d+)") + custom_action_regex = re.compile(r"action_custom ([a-zA-Z0-9_]+)(\s+.*)?") + prepare_ok_regex = re.compile(r"prepare_ok (.*)") + send_regex = re.compile(r"send (.*)") + set_ambient_regex = re.compile(r"set_ambient ([-+]?[0-9]*\.?[0-9]+)") + start_sd_regex = re.compile(r"start_sd (.*)") + select_sd_regex = re.compile(r"select_sd (.*)") def __init__(self, seriallog_handler=None, read_timeout=5.0, write_timeout=10.0): import logging @@ -317,7 +317,7 @@ class VirtualPrinter(object): # track N = N + 1 if data.startswith("N") and "M110" in data: - linenumber = int(re.search("N([0-9]+)", data).group(1)) + linenumber = int(re.search(r"N([0-9]+)", data).group(1)) self.lastN = linenumber self.currentLine = linenumber @@ -327,7 +327,7 @@ class VirtualPrinter(object): self._sendOk() continue elif data.startswith("N"): - linenumber = int(re.search("N([0-9]+)", data).group(1)) + linenumber = int(re.search(r"N([0-9]+)", data).group(1)) expected = self.lastN + 1 if linenumber != expected: self._triggerResend(actual=linenumber) @@ -491,7 +491,7 @@ class VirtualPrinter(object): def _gcode_M26(self, data): if self._sdCardReady: - pos = int(re.search("S([0-9]+)", data).group(1)) + pos = int(re.search(r"S([0-9]+)", data).group(1)) self._setSdPos(pos) def _gcode_M27(self, data): @@ -499,7 +499,7 @@ class VirtualPrinter(object): if self._sdCardReady: self._reportSdStatus() - match = re.search("S([0-9]+)", data) + match = re.search(r"S([0-9]+)", data) if match: interval = int(match.group(1)) if self._sdstatus_reporter is not None: @@ -528,7 +528,7 @@ class VirtualPrinter(object): self._deleteSdFile(filename) def _gcode_M113(self, data): - interval = int(re.search("S([0-9]+)", data).group(1)) + interval = int(re.search(r"S([0-9]+)", data).group(1)) if 0 <= interval <= 60: self._busyInterval = interval @@ -564,10 +564,10 @@ class VirtualPrinter(object): def _gcode_M117(self, data): # we'll just use this to echo a message, to allow playing around with pause triggers if self._echoOnM117: - self._send("echo:%s" % re.search("M117\s+(.*)", data).group(1)) + self._send("echo:%s" % re.search(r"M117\s+(.*)", data).group(1)) def _gcode_M155(self, data): - interval = int(re.search("S([0-9]+)", data).group(1)) + interval = int(re.search(r"S([0-9]+)", data).group(1)) if self._temperature_reporter is not None: self._temperature_reporter.cancel() @@ -578,10 +578,10 @@ class VirtualPrinter(object): self._temperature_reporter = None def _gcode_M220(self, data): - self._feedrate_multiplier = float(re.search('S([0-9]+)', data).group(1)) + self._feedrate_multiplier = float(re.search(r'S([0-9]+)', data).group(1)) def _gcode_M221(self, data): - self._flowrate_multiplier = float(re.search('S([0-9]+)', data).group(1)) + self._flowrate_multiplier = float(re.search(r'S([0-9]+)', data).group(1)) def _gcode_M400(self, data): self.buffered.join() @@ -632,8 +632,8 @@ class VirtualPrinter(object): _gcode_G3 = _gcode_G0 def _gcode_G4(self, data): - matchS = re.search('S([0-9]+)', data) - matchP = re.search('P([0-9]+)', data) + matchS = re.search(r'S([0-9]+)', data) + matchP = re.search(r'P([0-9]+)', data) _timeout = 0 if matchP: @@ -961,7 +961,7 @@ class VirtualPrinter(object): def _parseHotendCommand(self, line, wait=False, support_r=False): only_wait_if_higher = True tool = 0 - toolMatch = re.search('T([0-9]+)', line) + toolMatch = re.search(r'T([0-9]+)', line) if toolMatch: try: tool = int(toolMatch.group(1)) @@ -972,11 +972,11 @@ class VirtualPrinter(object): return try: - self.targetTemp[tool] = float(re.search('S([0-9]+)', line).group(1)) + self.targetTemp[tool] = float(re.search(r'S([0-9]+)', line).group(1)) except Exception: if support_r: try: - self.targetTemp[tool] = float(re.search('R([0-9]+)', line).group(1)) + self.targetTemp[tool] = float(re.search(r'R([0-9]+)', line).group(1)) only_wait_if_higher = False except Exception: pass @@ -989,11 +989,11 @@ class VirtualPrinter(object): def _parseBedCommand(self, line, wait=False, support_r=False): only_wait_if_higher = True try: - self.bedTargetTemp = float(re.search('S([0-9]+)', line).group(1)) + self.bedTargetTemp = float(re.search(r'S([0-9]+)', line).group(1)) except Exception: if support_r: try: - self.bedTargetTemp = float(re.search('R([0-9]+)', line).group(1)) + self.bedTargetTemp = float(re.search(r'R([0-9]+)', line).group(1)) only_wait_if_higher = False except Exception: pass @@ -1004,11 +1004,11 @@ class VirtualPrinter(object): self._send("TargetBed:%d" % self.bedTargetTemp) def _performMove(self, line): - matchX = re.search("X([0-9.]+)", line) - matchY = re.search("Y([0-9.]+)", line) - matchZ = re.search("Z([0-9.]+)", line) - matchE = re.search("E([0-9.]+)", line) - matchF = re.search("F([0-9.]+)", line) + matchX = re.search(r"X([0-9.]+)", line) + matchY = re.search(r"Y([0-9.]+)", line) + matchZ = re.search(r"Z([0-9.]+)", line) + matchE = re.search(r"E([0-9.]+)", line) + matchF = re.search(r"F([0-9.]+)", line) duration = 0.0 if matchF is not None: @@ -1089,10 +1089,10 @@ class VirtualPrinter(object): time.sleep(duration) def _setPosition(self, line): - matchX = re.search("X([0-9.]+)", line) - matchY = re.search("Y([0-9.]+)", line) - matchZ = re.search("Z([0-9.]+)", line) - matchE = re.search("E([0-9.]+)", line) + matchX = re.search(r"X([0-9.]+)", line) + matchY = re.search(r"Y([0-9.]+)", line) + matchZ = re.search(r"Z([0-9.]+)", line) + matchE = re.search(r"E([0-9.]+)", line) if matchX is None and matchY is None and matchZ is None and matchE is None: self._lastX = self._lastY = self._lastZ = self._lastE[self.currentExtruder] = 0 diff --git a/src/octoprint/printer/__init__.py b/src/octoprint/printer/__init__.py index 9e91844e5..909603004 100644 --- a/src/octoprint/printer/__init__.py +++ b/src/octoprint/printer/__init__.py @@ -44,10 +44,10 @@ class PrinterInterface(object): valid_axes = ("x", "y", "z", "e") """Valid axes identifiers.""" - valid_tool_regex = re.compile("^(tool\d+)$") + valid_tool_regex = re.compile(r"^(tool\d+)$") """Regex for valid tool identifiers.""" - valid_heater_regex = re.compile("^(tool\d+|bed)$") + valid_heater_regex = re.compile(r"^(tool\d+|bed)$") """Regex for valid heater identifiers.""" @classmethod diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 72b13829c..d34d4a587 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -1014,7 +1014,7 @@ class Server(object): def regex_replace(s, find, replace): return re.sub(find, replace, s) - html_header_regex = re.compile("[1-6])>(?P.*?)") + html_header_regex = re.compile(r"[1-6])>(?P.*?)") def offset_html_headers(s, offset): def repl(match): number = int(match.group("number")) @@ -1026,7 +1026,7 @@ class Server(object): return "{content}".format(number=number, content=match.group("content")) return html_header_regex.sub(repl, s) - markdown_header_regex = re.compile("^(?P#+)\s+(?P.*)$", flags=re.MULTILINE) + markdown_header_regex = re.compile(r"^(?P#+)\s+(?P.*)$", flags=re.MULTILINE) def offset_markdown_headers(s, offset): def repl(match): number = len(match.group("hashs")) @@ -1038,7 +1038,7 @@ class Server(object): return "{hashs} {content}".format(hashs="#" * number, content=match.group("content")) return markdown_header_regex.sub(repl, s) - html_link_regex = re.compile("<(?Pa.*?)>(?P.*?)") + html_link_regex = re.compile(r"<(?Pa.*?)>(?P.*?)") def externalize_links(text): def repl(match): tag = match.group("tag") diff --git a/src/octoprint/server/api/printer.py b/src/octoprint/server/api/printer.py index ef14b54bb..234e2871e 100644 --- a/src/octoprint/server/api/printer.py +++ b/src/octoprint/server/api/printer.py @@ -77,7 +77,7 @@ def printerToolCommand(): if response is not None: return response - validation_regex = re.compile("tool\d+") + validation_regex = re.compile(r"tool\d+") tags = {"source:api", "api:printer.tool"} diff --git a/src/octoprint/server/util/webassets.py b/src/octoprint/server/util/webassets.py index 4387b10ba..1ed20cddb 100644 --- a/src/octoprint/server/util/webassets.py +++ b/src/octoprint/server/util/webassets.py @@ -60,7 +60,7 @@ class LessImportRewrite(UrlRewriter): name = "less_importrewrite" patterns = { - "import_rewrite": re.compile("(@import(\s+\(.*\))?\s+)\"(.*)\";") + "import_rewrite": re.compile(r"(@import(\s+\(.*\))?\s+)\"(.*)\";") } def import_rewrite(self, m): @@ -73,7 +73,7 @@ class SourceMapRewrite(UrlRewriter): name = "sourcemap_urlrewrite" patterns = { - "url_rewrite": re.compile("(//#\s+sourceMappingURL=)(.*)") + "url_rewrite": re.compile(r"(//#\s+sourceMappingURL=)(.*)") } def url_rewrite(self, m): @@ -86,7 +86,7 @@ class SourceMapRemove(PatternRewriter): name = "sourcemap_remove" patterns = { - "sourcemap_remove": re.compile("(//#\s+sourceMappingURL=)(.*)") + "sourcemap_remove": re.compile(r"(//#\s+sourceMappingURL=)(.*)") } def sourcemap_remove(self, m): diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 8b64a854a..e7216a364 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -359,9 +359,9 @@ default_settings = { "apps": {} }, "terminalFilters": [ - { "name": "Suppress temperature messages", "regex": "(Send: (N\d+\s+)?M105)|(Recv:\s+(ok\s+)?.*(B|T\d*):\d+)" }, - { "name": "Suppress SD status messages", "regex": "(Send: (N\d+\s+)?M27)|(Recv: SD printing byte)|(Recv: Not SD printing)" }, - { "name": "Suppress wait responses", "regex": "Recv: wait"} + { "name": "Suppress temperature messages", "regex": r"(Send: (N\d+\s+)?M105)|(Recv:\s+(ok\s+)?.*(B|T\d*):\d+)" }, + { "name": "Suppress SD status messages", "regex": r"(Send: (N\d+\s+)?M27)|(Recv: SD printing byte)|(Recv: Not SD printing)" }, + { "name": "Suppress wait responses", "regex": r"Recv: wait"} ], "plugins": { "_disabled": [] @@ -1103,7 +1103,7 @@ class Settings(object): self._logger.info("Migrating config (event subscriptions)...") # migrate event hooks to new format - placeholderRe = re.compile("%\((.*?)\)s") + placeholderRe = re.compile(r"%\((.*?)\)s") eventNameReplacements = { "ClientOpen": "ClientOpened", diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index dfd1f2a17..2d1839f24 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -51,12 +51,12 @@ _capture_glob = "{prefix}-*.jpg" _output_format = "{prefix}{postfix}.{extension}" # ffmpeg progress regexes -_ffmpeg_duration_regex = re.compile("Duration: (\d{2}):(\d{2}):(\d{2})\.\d{2}") -_ffmpeg_current_regex = re.compile("time=(\d{2}):(\d{2}):(\d{2})\.\d{2}") +_ffmpeg_duration_regex = re.compile(r"Duration: (\d{2}):(\d{2}):(\d{2})\.\d{2}") +_ffmpeg_current_regex = re.compile(r"time=(\d{2}):(\d{2}):(\d{2})\.\d{2}") # old capture format, needed to delete old left-overs from # versions <1.2.9 -_old_capture_format_re = re.compile("^tmp_\d{5}.jpg$") +_old_capture_format_re = re.compile(r"^tmp_\d{5}.jpg$") # valid timelapses _valid_timelapse_types = ["off", "timed", "zchange"] diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 3e534cf85..b778cc619 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -52,38 +52,38 @@ _logger = logging.getLogger(__name__) # a bunch of regexes we'll need for the communication parsing... -regex_float_pattern = "[-+]?[0-9]*\.?[0-9]+" -regex_positive_float_pattern = "[+]?[0-9]*\.?[0-9]+" -regex_int_pattern = "\d+" +regex_float_pattern = r"[-+]?[0-9]*\.?[0-9]+" +regex_positive_float_pattern = r"[+]?[0-9]*\.?[0-9]+" +regex_int_pattern = r"\d+" -regex_command = re.compile("^\s*((?P[GM]\d+)(\\.(?P\d+))?|(?PT)\d+|(?PF)\d+)") +regex_command = re.compile(r"^\s*((?P[GM]\d+)(\\.(?P\d+))?|(?PT)\d+|(?PF)\d+)") """Regex for a GCODE command.""" regex_float = re.compile(regex_float_pattern) """Regex for a float value.""" regexes_parameters = dict( - floatE=re.compile("(^|[^A-Za-z])[Ee](?P%s)" % regex_float_pattern), - floatF=re.compile("(^|[^A-Za-z])[Ff](?P%s)" % regex_float_pattern), - floatP=re.compile("(^|[^A-Za-z])[Pp](?P%s)" % regex_float_pattern), - floatR=re.compile("(^|[^A-Za-z])[Rr](?P%s)" % regex_float_pattern), - floatS=re.compile("(^|[^A-Za-z])[Ss](?P%s)" % regex_float_pattern), - floatX=re.compile("(^|[^A-Za-z])[Xx](?P%s)" % regex_float_pattern), - floatY=re.compile("(^|[^A-Za-z])[Yy](?P%s)" % regex_float_pattern), - floatZ=re.compile("(^|[^A-Za-z])[Zz](?P%s)" % regex_float_pattern), - intN=re.compile("(^|[^A-Za-z])[Nn](?P%s)" % regex_int_pattern), - intS=re.compile("(^|[^A-Za-z])[Ss](?P%s)" % regex_int_pattern), - intT=re.compile("(^|[^A-Za-z])[Tt](?P%s)" % regex_int_pattern) + floatE=re.compile(r"(^|[^A-Za-z])[Ee](?P%s)" % regex_float_pattern), + floatF=re.compile(r"(^|[^A-Za-z])[Ff](?P%s)" % regex_float_pattern), + floatP=re.compile(r"(^|[^A-Za-z])[Pp](?P%s)" % regex_float_pattern), + floatR=re.compile(r"(^|[^A-Za-z])[Rr](?P%s)" % regex_float_pattern), + floatS=re.compile(r"(^|[^A-Za-z])[Ss](?P%s)" % regex_float_pattern), + floatX=re.compile(r"(^|[^A-Za-z])[Xx](?P%s)" % regex_float_pattern), + floatY=re.compile(r"(^|[^A-Za-z])[Yy](?P%s)" % regex_float_pattern), + floatZ=re.compile(r"(^|[^A-Za-z])[Zz](?P%s)" % regex_float_pattern), + intN=re.compile(r"(^|[^A-Za-z])[Nn](?P%s)" % regex_int_pattern), + intS=re.compile(r"(^|[^A-Za-z])[Ss](?P%s)" % regex_int_pattern), + intT=re.compile(r"(^|[^A-Za-z])[Tt](?P%s)" % regex_int_pattern) ) """Regexes for parsing various GCODE command parameters.""" -regex_minMaxError = re.compile("Error:[0-9]\n") +regex_minMaxError = re.compile(r"Error:[0-9]\n") """Regex matching first line of min/max errors from the firmware.""" -regex_marlinKillError = re.compile("Heating failed|Thermal Runaway|MAXTEMP triggered|MINTEMP triggered|Invalid extruder number|Watchdog barked|KILL caused") +regex_marlinKillError = re.compile(r"Heating failed|Thermal Runaway|MAXTEMP triggered|MINTEMP triggered|Invalid extruder number|Watchdog barked|KILL caused") """Regex matching first line of kill causing errors from Marlin.""" -regex_sdPrintingByte = re.compile("(?P[0-9]*)/(?P[0-9]*)") +regex_sdPrintingByte = re.compile(r"(?P[0-9]*)/(?P[0-9]*)") """Regex matching SD printing status reports. Groups will be as follows: @@ -92,7 +92,7 @@ Groups will be as follows: * ``total``: total size of file being printed """ -regex_sdFileOpened = re.compile("File opened:\s*(?P.*?)\s+Size:\s*(?P%s)" % regex_int_pattern) +regex_sdFileOpened = re.compile(r"File opened:\s*(?P.*?)\s+Size:\s*(?P%s)" % regex_int_pattern) """Regex matching "File opened" messages from the firmware. Groups will be as follows: @@ -101,7 +101,7 @@ Groups will be as follows: * ``size``: size of the file in bytes (int) """ -regex_temp = re.compile("(?PB|T(?P\d*)):\s*(?P%s)(\s*\/?\s*(?P%s))?" % (regex_float_pattern, regex_float_pattern)) +regex_temp = re.compile(r"(?PB|T(?P\d*)):\s*(?P%s)(\s*\/?\s*(?P%s))?" % (regex_float_pattern, regex_float_pattern)) """Regex matching temperature entries in line. Groups will be as follows: @@ -112,7 +112,7 @@ Groups will be as follows: * ``target``: target temperature, if provided (float) """ -regex_repetierTempExtr = re.compile("TargetExtr(?P\d+):(?P%s)" % regex_float_pattern) +regex_repetierTempExtr = re.compile(r"TargetExtr(?P\d+):(?P%s)" % regex_float_pattern) """Regex for matching target temp reporting from Repetier. Groups will be as follows: @@ -122,7 +122,7 @@ Groups will be as follows: * ``target``: new target temperature (float) """ -regex_repetierTempBed = re.compile("TargetBed:(?P%s)" % regex_float_pattern) +regex_repetierTempBed = re.compile(r"TargetBed:(?P%s)" % regex_float_pattern) """Regex for matching target temp reporting from Repetier for beds. Groups will be as follows: @@ -130,7 +130,7 @@ Groups will be as follows: * ``target``: new target temperature (float) """ -regex_position = re.compile("X:\s*(?P{float})\s*Y:\s*(?P{float})\s*Z:\s*(?P{float})\s*((E:\s*(?P{float}))|(?P(E\d+:\s*{float}\s*)+))".format(float=regex_float_pattern)) +regex_position = re.compile(r"X:\s*(?P{float})\s*Y:\s*(?P{float})\s*Z:\s*(?P{float})\s*((E:\s*(?P{float}))|(?P(E\d+:\s*{float}\s*)+))".format(float=regex_float_pattern)) """Regex for matching position reporting. Groups will be as follows: @@ -142,7 +142,7 @@ Groups will be as follows: * ``es``: multiple E coordinates if present, to be parsed further with regex_e_positions """ -regex_e_positions = re.compile("E(?P\d+):\s*(?P{float})".format(float=regex_float_pattern)) +regex_e_positions = re.compile(r"E(?P\d+):\s*(?P{float})".format(float=regex_float_pattern)) """Regex for matching multiple E coordinates in a position report. Groups will be as follows: @@ -151,10 +151,10 @@ Groups will be as follows: * ``value``: reported position value """ -regex_firmware_splitter = re.compile("\s*([A-Z0-9_]+):\s*") +regex_firmware_splitter = re.compile(r"\s*([A-Z0-9_]+):\s*") """Regex to use for splitting M115 responses.""" -regex_resend_linenumber = re.compile("(N|N:)?(?P%s)" % regex_int_pattern) +regex_resend_linenumber = re.compile(r"(N|N:)?(?P%s)" % regex_int_pattern) """Regex to use for request line numbers in resend requests""" def serialList(): @@ -4155,7 +4155,7 @@ class SendQueue(PrependableQueue): return self._resend_queue.qsize() + self._send_queue.qsize() -_temp_command_regex = re.compile("^M(?P104|109|140|190)(\s+T(?P\d+)|\s+S(?P[-+]?\d*\.?\d*))+") +_temp_command_regex = re.compile(r"^M(?P104|109|140|190)(\s+T(?P\d+)|\s+S(?P[-+]?\d*\.?\d*))+") def apply_temperature_offsets(line, offsets, current_tool=None): if offsets is None: diff --git a/tests/util/test_comm_helpers.py b/tests/util/test_comm_helpers.py index d96baf31f..0d92f5971 100644 --- a/tests/util/test_comm_helpers.py +++ b/tests/util/test_comm_helpers.py @@ -61,7 +61,7 @@ class TestCommHelpers(unittest.TestCase): self.assertEqual(input, actual) else: import re - match = re.search("S(\d+(\.\d+)?)", actual) + match = re.search(r"S(\d+(\.\d+)?)", actual) if not match: self.fail("No temperature found") temperature = float(match.group(1)) @@ -103,14 +103,15 @@ class TestCommHelpers(unittest.TestCase): m.update(input) return m.hexdigest() - temp_regex = b'T:((\d*\.)\d+)' + # rb'' doesn't exist in Python2 + temp_regex = r'T:((\d*\.)\d+)'.encode('utf-8') temp_template = b"Temp: {}" temp2_template = b"Temperature: {}" temp_key = md5sum(temp_regex) temp_template_key = md5sum(temp_template) temp2_template_key = md5sum(temp2_template) - x_regex = b"X:(?P\d+)" + x_regex = r"X:(?P\d+)".encode('utf-8') x_template = b"X: {x}" x_key = md5sum(x_regex) x_template_key = md5sum(x_template)