Kaydet (Commit) c08cb04c authored tarafından Guido van Rossum's avatar Guido van Rossum

the usual

üst 880066a9
...@@ -39,7 +39,7 @@ def _compile(code, pattern, flags): ...@@ -39,7 +39,7 @@ def _compile(code, pattern, flags):
return _sre.getlower(literal, flags) return _sre.getlower(literal, flags)
else: else:
emit(OPCODES[op]) emit(OPCODES[op])
fixup = lambda x: x fixup = lambda x: x
skip = len(code); emit(0) skip = len(code); emit(0)
for op, av in av: for op, av in av:
emit(OPCODES[op]) emit(OPCODES[op])
...@@ -118,7 +118,7 @@ def _compile(code, pattern, flags): ...@@ -118,7 +118,7 @@ def _compile(code, pattern, flags):
elif op is AT: elif op is AT:
emit(OPCODES[op]) emit(OPCODES[op])
if flags & SRE_FLAG_MULTILINE: if flags & SRE_FLAG_MULTILINE:
emit(ATCODES[AT_MULTILINE[av]]) emit(ATCODES[AT_MULTILINE.get(av, av)])
else: else:
emit(ATCODES[av]) emit(ATCODES[av])
elif op is BRANCH: elif op is BRANCH:
...@@ -203,7 +203,7 @@ def compile(p, flags=0): ...@@ -203,7 +203,7 @@ def compile(p, flags=0):
if type(p) in (type(""), type(u"")): if type(p) in (type(""), type(u"")):
import sre_parse import sre_parse
pattern = p pattern = p
p = sre_parse.parse(p) p = sre_parse.parse(p, flags)
else: else:
pattern = None pattern = None
......
...@@ -19,8 +19,9 @@ from sre_constants import * ...@@ -19,8 +19,9 @@ from sre_constants import *
# FIXME: should be 65535, but the arraymodule is still broken # FIXME: should be 65535, but the arraymodule is still broken
MAXREPEAT = 32767 MAXREPEAT = 32767
# FIXME: same here # FIXME: might change in 2.0 final. but for now, this seems
CHARMASK = 0x7fff # to be the best way to be compatible with 1.5.2
CHARMASK = 0xff
SPECIAL_CHARS = ".\\[{()*+?^$|" SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{" REPEAT_CHARS = "*+?{"
...@@ -30,7 +31,7 @@ DIGITS = tuple(string.digits) ...@@ -30,7 +31,7 @@ DIGITS = tuple(string.digits)
OCTDIGITS = tuple("01234567") OCTDIGITS = tuple("01234567")
HEXDIGITS = tuple("0123456789abcdefABCDEF") HEXDIGITS = tuple("0123456789abcdefABCDEF")
WHITESPACE = string.whitespace WHITESPACE = tuple(string.whitespace)
ESCAPES = { ESCAPES = {
r"\a": (LITERAL, 7), r"\a": (LITERAL, 7),
...@@ -295,7 +296,7 @@ def _branch(pattern, items): ...@@ -295,7 +296,7 @@ def _branch(pattern, items):
subpattern.append((BRANCH, (None, items))) subpattern.append((BRANCH, (None, items)))
return subpattern return subpattern
def _parse(source, state, flags=0): def _parse(source, state):
# parse regular expression pattern into an operator list. # parse regular expression pattern into an operator list.
...@@ -467,7 +468,7 @@ def _parse(source, state, flags=0): ...@@ -467,7 +468,7 @@ def _parse(source, state, flags=0):
char = source.get() char = source.get()
b = [] b = []
while 1: while 1:
p = _parse(source, state, flags) p = _parse(source, state)
if source.next == ")": if source.next == ")":
if b: if b:
b.append(p) b.append(p)
...@@ -494,7 +495,7 @@ def _parse(source, state, flags=0): ...@@ -494,7 +495,7 @@ def _parse(source, state, flags=0):
else: else:
group = state.getgroup(name) group = state.getgroup(name)
while 1: while 1:
p = _parse(source, state, flags) p = _parse(source, state)
if source.match(")"): if source.match(")"):
if b: if b:
b.append(p) b.append(p)
...@@ -531,9 +532,10 @@ def parse(pattern, flags=0): ...@@ -531,9 +532,10 @@ def parse(pattern, flags=0):
# parse 're' pattern into list of (opcode, argument) tuples # parse 're' pattern into list of (opcode, argument) tuples
source = Tokenizer(pattern) source = Tokenizer(pattern)
state = State() state = State()
state.flags = flags
b = [] b = []
while 1: while 1:
p = _parse(source, state, flags) p = _parse(source, state)
tail = source.get() tail = source.get()
if tail == "|": if tail == "|":
b.append(p) b.append(p)
...@@ -616,9 +618,9 @@ def expand_template(template, match): ...@@ -616,9 +618,9 @@ def expand_template(template, match):
a = p.append a = p.append
sep = match.string[:0] sep = match.string[:0]
if type(sep) is type(""): if type(sep) is type(""):
char = chr char = chr
else: else:
char = unichr char = unichr
for c, s in template: for c, s in template:
if c is LITERAL: if c is LITERAL:
a(char(s)) a(char(s))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment