Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bb515b

Browse files
Teach Tools/freeze/makeconfig.py and Tools/freeze/parsesetup.py to use
the re package rather than the obsolete regex.
1 parent 0f33604 commit 1bb515b

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

Tools/freeze/makeconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import regex
1+
import re
22

33

44
# Write the config.c file
55

66
never = ['marshal', '__main__', '__builtin__', 'sys', 'exceptions']
77

88
def makeconfig(infp, outfp, modules, with_ifdef=0):
9-
m1 = regex.compile('-- ADDMODULE MARKER 1 --')
10-
m2 = regex.compile('-- ADDMODULE MARKER 2 --')
9+
m1 = re.compile('-- ADDMODULE MARKER 1 --')
10+
m2 = re.compile('-- ADDMODULE MARKER 2 --')
1111
while 1:
1212
line = infp.readline()
1313
if not line: break

Tools/freeze/parsesetup.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Parse Makefiles and Python Setup(.in) files.
22

3-
import regex
3+
import re
44
import string
55

66

77
# Extract variable definitions from a Makefile.
88
# Return a dictionary mapping names to values.
99
# May raise IOError.
1010

11-
makevardef = regex.compile('^\([a-zA-Z0-9_]+\)[ \t]*=\(.*\)')
11+
makevardef = re.compile('^([a-zA-Z0-9_]+)[ \t]*=(.*)')
1212

1313
def getmakevars(filename):
1414
variables = {}
@@ -18,9 +18,10 @@ def getmakevars(filename):
1818
line = fp.readline()
1919
if not line:
2020
break
21-
if makevardef.match(line) < 0:
21+
matchobj = makevardef.match(line)
22+
if not matchobj:
2223
continue
23-
name, value = makevardef.group(1, 2)
24+
(name, value) = matchobj.group(1, 2)
2425
# Strip trailing comment
2526
i = string.find(value, '#')
2627
if i >= 0:
@@ -37,7 +38,7 @@ def getmakevars(filename):
3738
# definitions, the second mapping variable names to their values.
3839
# May raise IOError.
3940

40-
setupvardef = regex.compile('^\([a-zA-Z0-9_]+\)=\(.*\)')
41+
setupvardef = re.compile('^([a-zA-Z0-9_]+)=(.*)')
4142

4243
def getsetupinfo(filename):
4344
modules = {}
@@ -52,8 +53,9 @@ def getsetupinfo(filename):
5253
i = string.find(line, '#')
5354
if i >= 0:
5455
line = line[:i]
55-
if setupvardef.match(line) >= 0:
56-
name, value = setupvardef.group(1, 2)
56+
matchobj = setupvardef.match(line)
57+
if matchobj:
58+
(name, value) = matchobj.group(1, 2)
5759
variables[name] = string.strip(value)
5860
else:
5961
words = string.split(line)

0 commit comments

Comments
 (0)