bumped SRE version number to 2.1. cleaned up and added 1.5.2
compatibility patches.
diff --git a/Lib/sre.py b/Lib/sre.py
index 8d03e92..859ff9e 100644
--- a/Lib/sre.py
+++ b/Lib/sre.py
@@ -181,7 +181,7 @@
continue
append(string[i:b])
if g and b != e:
- extend(m.groups())
+ extend(list(m.groups()))
i = e
n = n + 1
append(string[i:])
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 454e477..7c6eb9f 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -60,6 +60,12 @@
"u": SRE_FLAG_UNICODE,
}
+try:
+ int("10", 8)
+ atoi = int
+except TypeError:
+ atoi = string.atoi
+
class Pattern:
# master pattern object. keeps track of global attributes
def __init__(self):
@@ -216,7 +222,7 @@
def _group(escape, groups):
# check if the escape string represents a valid group
try:
- gid = int(escape[1:])
+ gid = atoi(escape[1:])
if gid and gid < groups:
return gid
except ValueError:
@@ -239,13 +245,13 @@
escape = escape[2:]
if len(escape) != 2:
raise error, "bogus escape: %s" % repr("\\" + escape)
- return LITERAL, int(escape, 16) & 0xff
+ return LITERAL, atoi(escape, 16) & 0xff
elif str(escape[1:2]) in OCTDIGITS:
# octal escape (up to three digits)
while source.next in OCTDIGITS and len(escape) < 5:
escape = escape + source.get()
escape = escape[1:]
- return LITERAL, int(escape, 8) & 0xff
+ return LITERAL, atoi(escape, 8) & 0xff
if len(escape) == 2:
return LITERAL, ord(escape[1])
except ValueError:
@@ -267,12 +273,12 @@
escape = escape + source.get()
if len(escape) != 4:
raise ValueError
- return LITERAL, int(escape[2:], 16) & 0xff
+ return LITERAL, atoi(escape[2:], 16) & 0xff
elif escape[1:2] == "0":
# octal escape
while source.next in OCTDIGITS and len(escape) < 4:
escape = escape + source.get()
- return LITERAL, int(escape[1:], 8) & 0xff
+ return LITERAL, atoi(escape[1:], 8) & 0xff
elif escape[1:2] in DIGITS:
# octal escape *or* decimal group reference (sigh)
here = source.tell()
@@ -282,7 +288,7 @@
source.next in OCTDIGITS):
# got three octal digits; this is an octal escape
escape = escape + source.get()
- return LITERAL, int(escape[1:], 8) & 0xff
+ return LITERAL, atoi(escape[1:], 8) & 0xff
# got at least one decimal digit; this is a group reference
group = _group(escape, state.groups)
if group:
@@ -456,9 +462,9 @@
source.seek(here)
continue
if lo:
- min = int(lo)
+ min = atoi(lo)
if hi:
- max = int(hi)
+ max = atoi(hi)
if max < min:
raise error, "bad repeat interval"
else:
@@ -646,7 +652,7 @@
if not name:
raise error, "bad group name"
try:
- index = int(name)
+ index = atoi(name)
except ValueError:
if not isname(name):
raise error, "bad character in group name"
@@ -662,7 +668,7 @@
if group:
if (s.next not in DIGITS or
not _group(this + s.next, pattern.groups+1)):
- code = MARK, int(group)
+ code = MARK, group
break
elif s.next in OCTDIGITS:
this = this + s.get()
@@ -670,7 +676,7 @@
break
if not code:
this = this[1:]
- code = LITERAL, int(this[-6:], 8) & 0xff
+ code = LITERAL, atoi(this[-6:], 8) & 0xff
a(code)
else:
try:
diff --git a/Lib/test/test_sre.py b/Lib/test/test_sre.py
index 5d19d40..88c0d62 100644
--- a/Lib/test/test_sre.py
+++ b/Lib/test/test_sre.py
@@ -325,16 +325,26 @@
# Try the match on a unicode string, and check that it
# still succeeds.
- result=obj.search(unicode(s, "latin-1"))
- if result==None:
- print '=== Fails on unicode match', t
+ try:
+ u = unicode(s, "latin-1")
+ except NameError:
+ pass
+ else:
+ result=obj.search(u)
+ if result==None:
+ print '=== Fails on unicode match', t
# Try the match on a unicode pattern, and check that it
# still succeeds.
- obj=sre.compile(unicode(pattern, "latin-1"))
- result=obj.search(s)
- if result==None:
- print '=== Fails on unicode pattern match', t
+ try:
+ u = unicode(pattern, "latin-1")
+ except NameError:
+ pass
+ else:
+ obj=sre.compile(u)
+ result=obj.search(s)
+ if result==None:
+ print '=== Fails on unicode pattern match', t
# Try the match with the search area limited to the extent
# of the match and see if it still succeeds. \B will