Fix DeprecationWarning: invalid escape sequence

This commit is contained in:
Miguel Sousa 2019-04-01 13:53:59 -07:00
parent c6006a7f8c
commit ddff29cb5d
11 changed files with 53 additions and 53 deletions

View File

@ -9,52 +9,52 @@ from fontTools.misc.py23 import *
import re import re
# every single line starts with a "word" # 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 # regular expression to parse char lines
charRE = re.compile( charRE = re.compile(
"(-?\d+)" # charnum r"(-?\d+)" # charnum
"\s*;\s*WX\s+" # ; WX r"\s*;\s*WX\s+" # ; WX
"(-?\d+)" # width r"(-?\d+)" # width
"\s*;\s*N\s+" # ; N r"\s*;\s*N\s+" # ; N
"([.A-Za-z0-9_]+)" # charname r"([.A-Za-z0-9_]+)" # charname
"\s*;\s*B\s+" # ; B r"\s*;\s*B\s+" # ; B
"(-?\d+)" # left r"(-?\d+)" # left
"\s+" r"\s+"
"(-?\d+)" # bottom r"(-?\d+)" # bottom
"\s+" r"\s+"
"(-?\d+)" # right r"(-?\d+)" # right
"\s+" r"\s+"
"(-?\d+)" # top r"(-?\d+)" # top
"\s*;\s*" # ; r"\s*;\s*" # ;
) )
# regular expression to parse kerning lines # regular expression to parse kerning lines
kernRE = re.compile( kernRE = re.compile(
"([.A-Za-z0-9_]+)" # leftchar r"([.A-Za-z0-9_]+)" # leftchar
"\s+" r"\s+"
"([.A-Za-z0-9_]+)" # rightchar r"([.A-Za-z0-9_]+)" # rightchar
"\s+" r"\s+"
"(-?\d+)" # value r"(-?\d+)" # value
"\s*" r"\s*"
) )
# regular expressions to parse composite info lines of the form: # regular expressions to parse composite info lines of the form:
# Aacute 2 ; PCC A 0 0 ; PCC acute 182 211 ; # Aacute 2 ; PCC A 0 0 ; PCC acute 182 211 ;
compositeRE = re.compile( compositeRE = re.compile(
"([.A-Za-z0-9_]+)" # char name r"([.A-Za-z0-9_]+)" # char name
"\s+" r"\s+"
"(\d+)" # number of parts r"(\d+)" # number of parts
"\s*;\s*" r"\s*;\s*"
) )
componentRE = re.compile( componentRE = re.compile(
"PCC\s+" # PPC r"PCC\s+" # PPC
"([.A-Za-z0-9_]+)" # base char name r"([.A-Za-z0-9_]+)" # base char name
"\s+" r"\s+"
"(-?\d+)" # x offset r"(-?\d+)" # x offset
"\s+" r"\s+"
"(-?\d+)" # y offset r"(-?\d+)" # y offset
"\s*;\s*" r"\s*;\s*"
) )
preferredAttributeOrder = [ preferredAttributeOrder = [

View File

@ -27,7 +27,7 @@ def programToString(program):
def programToCommands(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 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, 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 hintmask/cntrmask argument, as well as stray arguments at the end of the

View File

@ -5,7 +5,7 @@ import os
import re import re
numberAddedRE = re.compile("#\d+$") numberAddedRE = re.compile(r"#\d+$")
def makeOutputFileName(input, outputDir=None, extension=None, overWrite=False): def makeOutputFileName(input, outputDir=None, extension=None, overWrite=False):

View File

@ -15,7 +15,7 @@ from __future__ import unicode_literals
from fontTools.misc.py23 import basestring, unicode 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(i) for i in range(1, 32)]
illegalCharacters += [chr(0x7F)] illegalCharacters += [chr(0x7F)]
reservedFileNames = "CON PRN AUX CLOCK$ NUL A:-Z: COM1".lower().split(" ") reservedFileNames = "CON PRN AUX CLOCK$ NUL A:-Z: COM1".lower().split(" ")

View File

@ -110,20 +110,20 @@ def calcsize(fmt):
# matches "name:formatchar" (whitespace is allowed) # matches "name:formatchar" (whitespace is allowed)
_elementRE = re.compile( _elementRE = re.compile(
"\s*" # whitespace r"\s*" # whitespace
"([A-Za-z_][A-Za-z_0-9]*)" # name (python identifier) r"([A-Za-z_][A-Za-z_0-9]*)" # name (python identifier)
"\s*:\s*" # whitespace : whitespace r"\s*:\s*" # whitespace : whitespace
"([cbBhHiIlLqQfd]|[0-9]+[ps]|" # formatchar... r"([cbBhHiIlLqQfd]|[0-9]+[ps]|" # formatchar...
"([0-9]+)\.([0-9]+)(F))" # ...formatchar r"([0-9]+)\.([0-9]+)(F))" # ...formatchar
"\s*" # whitespace r"\s*" # whitespace
"(#.*)?$" # [comment] + end of string r"(#.*)?$" # [comment] + end of string
) )
# matches the special struct fmt chars and 'x' (pad byte) # 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 # matches an "empty" string, possibly containing whitespace and/or a comment
_emptyRE = re.compile("\s*(#.*)?$") _emptyRE = re.compile(r"\s*(#.*)?$")
_fixedpointmappings = { _fixedpointmappings = {
8: "b", 8: "b",

View File

@ -18,7 +18,7 @@ COMMANDS = set('MmZzLlHhVvCcSsQqTtAa')
UPPERCASE = set('MZLHVCSQTA') UPPERCASE = set('MZLHVCSQTA')
COMMAND_RE = re.compile("([MmZzLlHhVvCcSsQqTtAa])") 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): def _tokenize_path(pathdef):

View File

@ -219,7 +219,7 @@ def disassemble(aCode):
pc += struct.calcsize(fmt) pc += struct.calcsize(fmt)
return res return res
instre = re.compile("^\s*([^(]+)\s*(?:\(([^)]+)\))?") instre = re.compile(r"^\s*([^(]+)\s*(?:\(([^)]+)\))?")
def assemble(instrs): def assemble(instrs):
res = b"" res = b""
for inst in instrs: for inst in instrs:
@ -231,7 +231,7 @@ def assemble(instrs):
if m.group(2): if m.group(2):
if parmfmt == 0: if parmfmt == 0:
continue 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: if parmfmt == -1:
l = len(parms) l = len(parms)
res += struct.pack(("%dB" % (l+1)), l, *parms) res += struct.pack(("%dB" % (l+1)), l, *parms)

View File

@ -1495,7 +1495,7 @@ def _buildClasses():
import re import re
from .otData import otData 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() namespace = globals()
# populate module with classes # populate module with classes

View File

@ -6,7 +6,7 @@ from __future__ import absolute_import, unicode_literals
from fontTools.misc.py23 import basestring, unicode 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(i) for i in range(1, 32)]
illegalCharacters += [chr(0x7F)] illegalCharacters += [chr(0x7F)]
reservedFileNames = "CON PRN AUX CLOCK$ NUL A:-Z: COM1".lower().split(" ") reservedFileNames = "CON PRN AUX CLOCK$ NUL A:-Z: COM1".lower().split(" ")

View File

@ -1185,7 +1185,7 @@ class ParserTest(unittest.TestCase):
self.assertRaisesRegex( self.assertRaisesRegex(
FeatureLibError, FeatureLibError,
'In reverse chaining single substitutions, the replacement ' '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;") self.parse, "feature test {rsub f_i by f i;} test;")
def test_script(self): def test_script(self):

View File

@ -89,7 +89,7 @@ class TimerTest(object):
time.sleep(0.01) time.sleep(0.01)
assert re.match( 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()) logger.handlers[0].stream.getvalue())
def test_using_logger_calling_instance(self, logger): def test_using_logger_calling_instance(self, logger):
@ -98,7 +98,7 @@ class TimerTest(object):
time.sleep(0.01) time.sleep(0.01)
assert re.match( 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()) logger.handlers[0].stream.getvalue())
# do it again but with custom level # do it again but with custom level
@ -106,7 +106,7 @@ class TimerTest(object):
time.sleep(0.02) time.sleep(0.02)
assert re.search( 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()) logger.handlers[0].stream.getvalue())
def test_function_decorator(self, logger): def test_function_decorator(self, logger):