From ddff29cb5db3095145526fc581e50c240512377d Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 1 Apr 2019 13:53:59 -0700 Subject: [PATCH] Fix DeprecationWarning: invalid escape sequence --- Lib/fontTools/afmLib.py | 64 +++++++++++++------------- Lib/fontTools/cffLib/specializer.py | 2 +- Lib/fontTools/misc/cliTools.py | 2 +- Lib/fontTools/misc/filenames.py | 2 +- Lib/fontTools/misc/sstruct.py | 18 ++++---- Lib/fontTools/svgLib/path/parser.py | 2 +- Lib/fontTools/ttLib/tables/S__i_l_f.py | 4 +- Lib/fontTools/ttLib/tables/otTables.py | 2 +- Lib/fontTools/ufoLib/filenames.py | 2 +- Tests/feaLib/parser_test.py | 2 +- Tests/misc/loggingTools_test.py | 6 +-- 11 files changed, 53 insertions(+), 53 deletions(-) diff --git a/Lib/fontTools/afmLib.py b/Lib/fontTools/afmLib.py index e0ccafee0..db01d3461 100644 --- a/Lib/fontTools/afmLib.py +++ b/Lib/fontTools/afmLib.py @@ -9,52 +9,52 @@ from fontTools.misc.py23 import * import re # every single line starts with a "word" -identifierRE = re.compile("^([A-Za-z]+).*") +identifierRE = re.compile(r"^([A-Za-z]+).*") # regular expression to parse char lines charRE = re.compile( - "(-?\d+)" # charnum - "\s*;\s*WX\s+" # ; WX - "(-?\d+)" # width - "\s*;\s*N\s+" # ; N - "([.A-Za-z0-9_]+)" # charname - "\s*;\s*B\s+" # ; B - "(-?\d+)" # left - "\s+" - "(-?\d+)" # bottom - "\s+" - "(-?\d+)" # right - "\s+" - "(-?\d+)" # top - "\s*;\s*" # ; + r"(-?\d+)" # charnum + r"\s*;\s*WX\s+" # ; WX + r"(-?\d+)" # width + r"\s*;\s*N\s+" # ; N + r"([.A-Za-z0-9_]+)" # charname + r"\s*;\s*B\s+" # ; B + r"(-?\d+)" # left + r"\s+" + r"(-?\d+)" # bottom + r"\s+" + r"(-?\d+)" # right + r"\s+" + r"(-?\d+)" # top + r"\s*;\s*" # ; ) # regular expression to parse kerning lines kernRE = re.compile( - "([.A-Za-z0-9_]+)" # leftchar - "\s+" - "([.A-Za-z0-9_]+)" # rightchar - "\s+" - "(-?\d+)" # value - "\s*" + r"([.A-Za-z0-9_]+)" # leftchar + r"\s+" + r"([.A-Za-z0-9_]+)" # rightchar + r"\s+" + r"(-?\d+)" # value + r"\s*" ) # regular expressions to parse composite info lines of the form: # Aacute 2 ; PCC A 0 0 ; PCC acute 182 211 ; compositeRE = re.compile( - "([.A-Za-z0-9_]+)" # char name - "\s+" - "(\d+)" # number of parts - "\s*;\s*" + r"([.A-Za-z0-9_]+)" # char name + r"\s+" + r"(\d+)" # number of parts + r"\s*;\s*" ) componentRE = re.compile( - "PCC\s+" # PPC - "([.A-Za-z0-9_]+)" # base char name - "\s+" - "(-?\d+)" # x offset - "\s+" - "(-?\d+)" # y offset - "\s*;\s*" + r"PCC\s+" # PPC + r"([.A-Za-z0-9_]+)" # base char name + r"\s+" + r"(-?\d+)" # x offset + r"\s+" + r"(-?\d+)" # y offset + r"\s*;\s*" ) preferredAttributeOrder = [ diff --git a/Lib/fontTools/cffLib/specializer.py b/Lib/fontTools/cffLib/specializer.py index caf8c3b32..02e092003 100644 --- a/Lib/fontTools/cffLib/specializer.py +++ b/Lib/fontTools/cffLib/specializer.py @@ -27,7 +27,7 @@ def programToString(program): def programToCommands(program): - """Takes a T2CharString program list and returns list of commands. + r"""Takes a T2CharString program list and returns list of commands. Each command is a two-tuple of commandname,arg-list. The commandname might be empty string if no commandname shall be emitted (used for glyph width, hintmask/cntrmask argument, as well as stray arguments at the end of the diff --git a/Lib/fontTools/misc/cliTools.py b/Lib/fontTools/misc/cliTools.py index 59ac3be17..8420e3e7c 100644 --- a/Lib/fontTools/misc/cliTools.py +++ b/Lib/fontTools/misc/cliTools.py @@ -5,7 +5,7 @@ import os import re -numberAddedRE = re.compile("#\d+$") +numberAddedRE = re.compile(r"#\d+$") def makeOutputFileName(input, outputDir=None, extension=None, overWrite=False): diff --git a/Lib/fontTools/misc/filenames.py b/Lib/fontTools/misc/filenames.py index 6cf02e361..260ace4c5 100644 --- a/Lib/fontTools/misc/filenames.py +++ b/Lib/fontTools/misc/filenames.py @@ -15,7 +15,7 @@ from __future__ import unicode_literals from fontTools.misc.py23 import basestring, unicode -illegalCharacters = "\" * + / : < > ? [ \ ] | \0".split(" ") +illegalCharacters = r"\" * + / : < > ? [ \ ] | \0".split(" ") illegalCharacters += [chr(i) for i in range(1, 32)] illegalCharacters += [chr(0x7F)] reservedFileNames = "CON PRN AUX CLOCK$ NUL A:-Z: COM1".lower().split(" ") diff --git a/Lib/fontTools/misc/sstruct.py b/Lib/fontTools/misc/sstruct.py index 528b5e029..6b7e783ed 100644 --- a/Lib/fontTools/misc/sstruct.py +++ b/Lib/fontTools/misc/sstruct.py @@ -110,20 +110,20 @@ def calcsize(fmt): # matches "name:formatchar" (whitespace is allowed) _elementRE = re.compile( - "\s*" # whitespace - "([A-Za-z_][A-Za-z_0-9]*)" # name (python identifier) - "\s*:\s*" # whitespace : whitespace - "([cbBhHiIlLqQfd]|[0-9]+[ps]|" # formatchar... - "([0-9]+)\.([0-9]+)(F))" # ...formatchar - "\s*" # whitespace - "(#.*)?$" # [comment] + end of string + r"\s*" # whitespace + r"([A-Za-z_][A-Za-z_0-9]*)" # name (python identifier) + r"\s*:\s*" # whitespace : whitespace + r"([cbBhHiIlLqQfd]|[0-9]+[ps]|" # formatchar... + r"([0-9]+)\.([0-9]+)(F))" # ...formatchar + r"\s*" # whitespace + r"(#.*)?$" # [comment] + end of string ) # matches the special struct fmt chars and 'x' (pad byte) -_extraRE = re.compile("\s*([x@=<>!])\s*(#.*)?$") +_extraRE = re.compile(r"\s*([x@=<>!])\s*(#.*)?$") # matches an "empty" string, possibly containing whitespace and/or a comment -_emptyRE = re.compile("\s*(#.*)?$") +_emptyRE = re.compile(r"\s*(#.*)?$") _fixedpointmappings = { 8: "b", diff --git a/Lib/fontTools/svgLib/path/parser.py b/Lib/fontTools/svgLib/path/parser.py index ae0aba396..bdf3de0c6 100644 --- a/Lib/fontTools/svgLib/path/parser.py +++ b/Lib/fontTools/svgLib/path/parser.py @@ -18,7 +18,7 @@ COMMANDS = set('MmZzLlHhVvCcSsQqTtAa') UPPERCASE = set('MZLHVCSQTA') COMMAND_RE = re.compile("([MmZzLlHhVvCcSsQqTtAa])") -FLOAT_RE = re.compile("[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?") +FLOAT_RE = re.compile(r"[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?") def _tokenize_path(pathdef): diff --git a/Lib/fontTools/ttLib/tables/S__i_l_f.py b/Lib/fontTools/ttLib/tables/S__i_l_f.py index e68b9b2e0..67afd754b 100644 --- a/Lib/fontTools/ttLib/tables/S__i_l_f.py +++ b/Lib/fontTools/ttLib/tables/S__i_l_f.py @@ -219,7 +219,7 @@ def disassemble(aCode): pc += struct.calcsize(fmt) return res -instre = re.compile("^\s*([^(]+)\s*(?:\(([^)]+)\))?") +instre = re.compile(r"^\s*([^(]+)\s*(?:\(([^)]+)\))?") def assemble(instrs): res = b"" for inst in instrs: @@ -231,7 +231,7 @@ def assemble(instrs): if m.group(2): if parmfmt == 0: continue - parms = [int(x) for x in re.split(",\s*", m.group(2))] + parms = [int(x) for x in re.split(r",\s*", m.group(2))] if parmfmt == -1: l = len(parms) res += struct.pack(("%dB" % (l+1)), l, *parms) diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index af2a7c6cd..5735ee9e8 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -1495,7 +1495,7 @@ def _buildClasses(): import re from .otData import otData - formatPat = re.compile("([A-Za-z0-9]+)Format(\d+)$") + formatPat = re.compile(r"([A-Za-z0-9]+)Format(\d+)$") namespace = globals() # populate module with classes diff --git a/Lib/fontTools/ufoLib/filenames.py b/Lib/fontTools/ufoLib/filenames.py index 98f53b1f2..1c5630f0d 100644 --- a/Lib/fontTools/ufoLib/filenames.py +++ b/Lib/fontTools/ufoLib/filenames.py @@ -6,7 +6,7 @@ from __future__ import absolute_import, unicode_literals from fontTools.misc.py23 import basestring, unicode -illegalCharacters = "\" * + / : < > ? [ \ ] | \0".split(" ") +illegalCharacters = r"\" * + / : < > ? [ \ ] | \0".split(" ") illegalCharacters += [chr(i) for i in range(1, 32)] illegalCharacters += [chr(0x7F)] reservedFileNames = "CON PRN AUX CLOCK$ NUL A:-Z: COM1".lower().split(" ") diff --git a/Tests/feaLib/parser_test.py b/Tests/feaLib/parser_test.py index 98ac1014c..9343495a0 100644 --- a/Tests/feaLib/parser_test.py +++ b/Tests/feaLib/parser_test.py @@ -1185,7 +1185,7 @@ class ParserTest(unittest.TestCase): self.assertRaisesRegex( FeatureLibError, 'In reverse chaining single substitutions, the replacement ' - '\(after "by"\) must be a single glyph or glyph class', + r'\(after "by"\) must be a single glyph or glyph class', self.parse, "feature test {rsub f_i by f i;} test;") def test_script(self): diff --git a/Tests/misc/loggingTools_test.py b/Tests/misc/loggingTools_test.py index b402efa5a..18b71b192 100644 --- a/Tests/misc/loggingTools_test.py +++ b/Tests/misc/loggingTools_test.py @@ -89,7 +89,7 @@ class TimerTest(object): time.sleep(0.01) assert re.match( - "Took [0-9]\.[0-9]{3}s to do something", + r"Took [0-9]\.[0-9]{3}s to do something", logger.handlers[0].stream.getvalue()) def test_using_logger_calling_instance(self, logger): @@ -98,7 +98,7 @@ class TimerTest(object): time.sleep(0.01) assert re.match( - "elapsed time: [0-9]\.[0-9]{3}s", + r"elapsed time: [0-9]\.[0-9]{3}s", logger.handlers[0].stream.getvalue()) # do it again but with custom level @@ -106,7 +106,7 @@ class TimerTest(object): time.sleep(0.02) assert re.search( - "WARNING: Took [0-9]\.[0-9]{3}s to redo it", + r"WARNING: Took [0-9]\.[0-9]{3}s to redo it", logger.handlers[0].stream.getvalue()) def test_function_decorator(self, logger):