summaryrefslogtreecommitdiff
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-01-16 07:37:30 +0000
committerFredrik Lundh <fredrik@pythonware.com>2001-01-16 07:37:30 +0000
commitd0f46e380d3d154c187bcfe14bbde43a32865afb (patch)
treeabcfaece30bb6f49ceeaf6bc5fd7d90cdddc696d /Lib/sre_parse.py
parentb127817e1b3fee5cd20971f43347110d0483abe0 (diff)
downloadcpython-d0f46e380d3d154c187bcfe14bbde43a32865afb.tar.gz
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 454e4779f8..7c6eb9f764 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: