Teach Tools/freeze/makeconfig.py and Tools/freeze/parsesetup.py to use

the re package rather than the obsolete regex.
This commit is contained in:
Eric S. Raymond 2001-03-18 11:27:58 +00:00
parent 0f33604e17
commit 1bb515b0e5
2 changed files with 12 additions and 10 deletions

View file

@ -1,4 +1,4 @@
import regex import re
# Write the config.c file # Write the config.c file
@ -6,8 +6,8 @@ import regex
never = ['marshal', '__main__', '__builtin__', 'sys', 'exceptions'] never = ['marshal', '__main__', '__builtin__', 'sys', 'exceptions']
def makeconfig(infp, outfp, modules, with_ifdef=0): def makeconfig(infp, outfp, modules, with_ifdef=0):
m1 = regex.compile('-- ADDMODULE MARKER 1 --') m1 = re.compile('-- ADDMODULE MARKER 1 --')
m2 = regex.compile('-- ADDMODULE MARKER 2 --') m2 = re.compile('-- ADDMODULE MARKER 2 --')
while 1: while 1:
line = infp.readline() line = infp.readline()
if not line: break if not line: break

View file

@ -1,6 +1,6 @@
# Parse Makefiles and Python Setup(.in) files. # Parse Makefiles and Python Setup(.in) files.
import regex import re
import string import string
@ -8,7 +8,7 @@ import string
# Return a dictionary mapping names to values. # Return a dictionary mapping names to values.
# May raise IOError. # May raise IOError.
makevardef = regex.compile('^\([a-zA-Z0-9_]+\)[ \t]*=\(.*\)') makevardef = re.compile('^([a-zA-Z0-9_]+)[ \t]*=(.*)')
def getmakevars(filename): def getmakevars(filename):
variables = {} variables = {}
@ -18,9 +18,10 @@ def getmakevars(filename):
line = fp.readline() line = fp.readline()
if not line: if not line:
break break
if makevardef.match(line) < 0: matchobj = makevardef.match(line)
if not matchobj:
continue continue
name, value = makevardef.group(1, 2) (name, value) = matchobj.group(1, 2)
# Strip trailing comment # Strip trailing comment
i = string.find(value, '#') i = string.find(value, '#')
if i >= 0: if i >= 0:
@ -37,7 +38,7 @@ def getmakevars(filename):
# definitions, the second mapping variable names to their values. # definitions, the second mapping variable names to their values.
# May raise IOError. # May raise IOError.
setupvardef = regex.compile('^\([a-zA-Z0-9_]+\)=\(.*\)') setupvardef = re.compile('^([a-zA-Z0-9_]+)=(.*)')
def getsetupinfo(filename): def getsetupinfo(filename):
modules = {} modules = {}
@ -52,8 +53,9 @@ def getsetupinfo(filename):
i = string.find(line, '#') i = string.find(line, '#')
if i >= 0: if i >= 0:
line = line[:i] line = line[:i]
if setupvardef.match(line) >= 0: matchobj = setupvardef.match(line)
name, value = setupvardef.group(1, 2) if matchobj:
(name, value) = matchobj.group(1, 2)
variables[name] = string.strip(value) variables[name] = string.strip(value)
else: else:
words = string.split(line) words = string.split(line)