summaryrefslogtreecommitdiffstats
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-01-16 07:37:30 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-01-16 07:37:30 (GMT)
commit1c5aa6901fb13f8112ead1786868f0f8ed4c9e2d (patch)
tree52a6a1c66be3f2ea6c8f73e13d87412fe7d8bea7 /Lib/sre_parse.py
parentdfb673b45730635a386ceb3e2405bf2809a2e40c (diff)
downloadcpython-1c5aa6901fb13f8112ead1786868f0f8ed4c9e2d.zip
cpython-1c5aa6901fb13f8112ead1786868f0f8ed4c9e2d.tar.gz
cpython-1c5aa6901fb13f8112ead1786868f0f8ed4c9e2d.tar.bz2
bumped SRE version number to 2.1. cleaned up and added 1.5.2
compatibility patches.
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py28
1 files changed, 17 insertions, 11 deletions
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 @@ 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: