bumped SRE version number to 2.1. cleaned up and added 1.5.2

compatibility patches.
This commit is contained in:
Fredrik Lundh 2001-01-16 07:37:30 +00:00
parent dfb673b457
commit 1c5aa6901f
4 changed files with 76 additions and 44 deletions

View file

@ -60,6 +60,12 @@ FLAGS = {
"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 isname(name):
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 @@ def _class_escape(source, escape):
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 @@ def _escape(source, escape, state):
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 @@ def _escape(source, escape, state):
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 @@ def _parse(source, state):
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 @@ def parse_template(source, pattern):
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 @@ def parse_template(source, pattern):
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 @@ def parse_template(source, pattern):
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: