[Python-checkins] CVS: python/dist/src/Lib sre.py,1.29,1.30 sre_compile.py,1.35,1.36 sre_parse.py,1.43,1.44 sre_constants.py,1.26,1.27
Fredrik Lundh
effbot@users.sourceforge.net
Sun, 18 Feb 2001 04:05:18 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv15548/Lib
Modified Files:
sre.py sre_compile.py sre_parse.py sre_constants.py
Log Message:
- restored 1.5.2 compatibility (sorry, eric)
- removed __all__ cruft from internal modules (sorry, skip)
- don't assume ASCII for string escapes (sorry, per)
Index: sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** sre.py 2001/02/15 22:15:13 1.29
--- sre.py 2001/02/18 12:05:16 1.30
***************
*** 18,25 ****
import sre_parse
! __all__ = ["match","search","sub","subn","split","findall","compile",
! "purge","template","escape","I","L","M","S","X","U","IGNORECASE",
! "LOCALE","MULTILINE","DOTALL","VERBOSE","UNICODE","error"]
# flags
I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
--- 18,30 ----
import sre_parse
! # public symbols
! __all__ = [ "match", "search", "sub", "subn", "split", "findall",
! "compile", "purge", "template", "escape", "I", "L", "M", "S", "X",
! "U", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
! "UNICODE", "error" ]
+ # this module works under 1.5.2 and later. don't use string methods
+ import string
+
# flags
I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
***************
*** 89,93 ****
def template(pattern, flags=0):
"Compile a template pattern, returning a pattern object"
-
return _compile(pattern, flags|T)
--- 94,97 ----
***************
*** 112,116 ****
def _join(seq, sep):
# internal: join into string having the same type as sep
! return sep[:0].join(seq)
def _compile(*key):
--- 116,120 ----
def _join(seq, sep):
# internal: join into string having the same type as sep
! return string.join(seq, sep[:0])
def _compile(*key):
Index: sre_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_compile.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -r1.35 -r1.36
*** sre_compile.py 2001/02/15 22:15:13 1.35
--- sre_compile.py 2001/02/18 12:05:16 1.36
***************
*** 13,18 ****
from sre_constants import *
- __all__ = ["compile"]
-
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
--- 13,16 ----
Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -r1.43 -r1.44
*** sre_parse.py 2001/02/15 22:15:13 1.43
--- sre_parse.py 2001/02/18 12:05:16 1.44
***************
*** 11,21 ****
# XXX: show string offset and offending character for all errors
! import sys
from sre_constants import *
- __all__ = ["Pattern","SubPattern","Tokenizer","parse","parse_template",
- "expand_template"]
-
SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{"
--- 11,19 ----
# XXX: show string offset and offending character for all errors
! # this module works under 1.5.2 and later. don't use string methods
! import string, sys
from sre_constants import *
SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{"
***************
*** 29,39 ****
ESCAPES = {
! r"\a": (LITERAL, 7),
! r"\b": (LITERAL, 8),
! r"\f": (LITERAL, 12),
! r"\n": (LITERAL, 10),
! r"\r": (LITERAL, 13),
! r"\t": (LITERAL, 9),
! r"\v": (LITERAL, 11),
r"\\": (LITERAL, ord("\\"))
}
--- 27,37 ----
ESCAPES = {
! r"\a": (LITERAL, ord("\a")),
! r"\b": (LITERAL, ord("\b")),
! r"\f": (LITERAL, ord("\f")),
! r"\n": (LITERAL, ord("\n")),
! r"\r": (LITERAL, ord("\r")),
! r"\t": (LITERAL, ord("\t")),
! r"\v": (LITERAL, ord("\v")),
r"\\": (LITERAL, ord("\\"))
}
***************
*** 64,67 ****
--- 62,72 ----
}
+ # figure out best way to convert hex/octal numbers to integers
+ try:
+ int("10", 8)
+ atoi = int # 2.0 and later
+ except TypeError:
+ atoi = string.atoi # 1.5.2
+
class Pattern:
# master pattern object. keeps track of global attributes
***************
*** 220,224 ****
# check if the escape string represents a valid group
try:
! gid = int(escape[1:])
if gid and gid < groups:
return gid
--- 225,229 ----
# check if the escape string represents a valid group
try:
! gid = atoi(escape[1:])
if gid and gid < groups:
return gid
***************
*** 243,247 ****
if len(escape) != 2:
raise error, "bogus escape: %s" % repr("\\" + escape)
! return LITERAL, int(escape, 16) & 0xff
elif str(escape[1:2]) in OCTDIGITS:
# octal escape (up to three digits)
--- 248,252 ----
if len(escape) != 2:
raise error, "bogus escape: %s" % repr("\\" + escape)
! return LITERAL, atoi(escape, 16) & 0xff
elif str(escape[1:2]) in OCTDIGITS:
# octal escape (up to three digits)
***************
*** 249,253 ****
escape = escape + source.get()
escape = escape[1:]
! return LITERAL, int(escape, 8) & 0xff
if len(escape) == 2:
return LITERAL, ord(escape[1])
--- 254,258 ----
escape = escape + source.get()
escape = escape[1:]
! return LITERAL, atoi(escape, 8) & 0xff
if len(escape) == 2:
return LITERAL, ord(escape[1])
***************
*** 271,280 ****
if len(escape) != 4:
raise ValueError
! return LITERAL, int(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
elif escape[1:2] in DIGITS:
# octal escape *or* decimal group reference (sigh)
--- 276,285 ----
if len(escape) != 4:
raise ValueError
! 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, atoi(escape[1:], 8) & 0xff
elif escape[1:2] in DIGITS:
# octal escape *or* decimal group reference (sigh)
***************
*** 286,290 ****
# got three octal digits; this is an octal escape
escape = escape + source.get()
! return LITERAL, int(escape[1:], 8) & 0xff
# got at least one decimal digit; this is a group reference
group = _group(escape, state.groups)
--- 291,295 ----
# got three octal digits; this is an octal escape
escape = escape + source.get()
! return LITERAL, atoi(escape[1:], 8) & 0xff
# got at least one decimal digit; this is a group reference
group = _group(escape, state.groups)
***************
*** 460,466 ****
continue
if lo:
! min = int(lo)
if hi:
! max = int(hi)
if max < min:
raise error, "bad repeat interval"
--- 465,471 ----
continue
if lo:
! min = atoi(lo)
if hi:
! max = atoi(hi)
if max < min:
raise error, "bad repeat interval"
***************
*** 650,654 ****
raise error, "bad group name"
try:
! index = int(name)
except ValueError:
if not isname(name):
--- 655,659 ----
raise error, "bad group name"
try:
! index = atoi(name)
except ValueError:
if not isname(name):
***************
*** 674,678 ****
if not code:
this = this[1:]
! code = LITERAL, int(this[-6:], 8) & 0xff
a(code)
else:
--- 679,683 ----
if not code:
this = this[1:]
! code = LITERAL, atoi(this[-6:], 8) & 0xff
a(code)
else:
***************
*** 703,705 ****
raise error, "empty group"
a(s)
! return sep.join(p)
--- 708,710 ----
raise error, "empty group"
a(s)
! return string.join(p, sep)
Index: sre_constants.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_constants.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -r1.26 -r1.27
*** sre_constants.py 2001/02/18 03:13:08 1.26
--- sre_constants.py 2001/02/18 12:05:16 1.27
***************
*** 196,204 ****
if __name__ == "__main__":
def dump(f, d, prefix):
items = d.items()
items.sort(lambda a, b: cmp(a[1], b[1]))
for k, v in items:
! f.write("#define %s_%s %s\n" % (prefix, k.upper(), v))
f = open("sre_constants.h", "w")
f.write("""\
--- 196,205 ----
if __name__ == "__main__":
+ import string
def dump(f, d, prefix):
items = d.items()
items.sort(lambda a, b: cmp(a[1], b[1]))
for k, v in items:
! f.write("#define %s_%s %s\n" % (prefix, string.upper(k), v))
f = open("sre_constants.h", "w")
f.write("""\