Commit 7898c3e6 authored by Fredrik Lundh's avatar Fredrik Lundh

-- reset marks if repeat_one tail doesn't match

   (this should fix Sjoerd's xmllib problem)
-- added skip field to INFO header
-- changed compiler to generate charset INFO header
-- changed trace messages to support post-mortem analysis
parent 6947d0b6
...@@ -47,16 +47,16 @@ def search(pattern, string, flags=0): ...@@ -47,16 +47,16 @@ def search(pattern, string, flags=0):
return _compile(pattern, flags).search(string) return _compile(pattern, flags).search(string)
def sub(pattern, repl, string, count=0): def sub(pattern, repl, string, count=0):
return _compile(pattern).sub(repl, string, count) return _compile(pattern, 0).sub(repl, string, count)
def subn(pattern, repl, string, count=0): def subn(pattern, repl, string, count=0):
return _compile(pattern).subn(repl, string, count) return _compile(pattern, 0).subn(repl, string, count)
def split(pattern, string, maxsplit=0): def split(pattern, string, maxsplit=0):
return _compile(pattern).split(string, maxsplit) return _compile(pattern, 0).split(string, maxsplit)
def findall(pattern, string, maxsplit=0): def findall(pattern, string, maxsplit=0):
return _compile(pattern).findall(string, maxsplit) return _compile(pattern, 0).findall(string, maxsplit)
def compile(pattern, flags=0): def compile(pattern, flags=0):
return _compile(pattern, flags) return _compile(pattern, flags)
...@@ -88,16 +88,14 @@ def _join(seq, sep): ...@@ -88,16 +88,14 @@ def _join(seq, sep):
# internal: join into string having the same type as sep # internal: join into string having the same type as sep
return string.join(seq, sep[:0]) return string.join(seq, sep[:0])
def _compile(pattern, flags=0): def _compile(*key):
# internal: compile pattern # internal: compile pattern
tp = type(pattern) p = _cache.get(key)
if tp not in sre_compile.STRING_TYPES: if p is not None:
return p
pattern, flags = key
if type(pattern) not in sre_compile.STRING_TYPES:
return pattern return pattern
key = (tp, pattern, flags)
try:
return _cache[key]
except KeyError:
pass
try: try:
p = sre_compile.compile(pattern, flags) p = sre_compile.compile(pattern, flags)
except error, v: except error, v:
...@@ -168,7 +166,7 @@ import copy_reg ...@@ -168,7 +166,7 @@ import copy_reg
def _pickle(p): def _pickle(p):
return _compile, (p.pattern, p.flags) return _compile, (p.pattern, p.flags)
copy_reg.pickle(type(_compile("")), _pickle, _compile) copy_reg.pickle(type(_compile("", 0)), _pickle, _compile)
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# experimental stuff (see python-dev discussions for details) # experimental stuff (see python-dev discussions for details)
......
This diff is collapsed.
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
import string, sys import string, sys
import _sre
from sre_constants import * from sre_constants import *
MAXREPEAT = 65535 MAXREPEAT = 65535
...@@ -232,6 +230,7 @@ def _class_escape(source, escape): ...@@ -232,6 +230,7 @@ def _class_escape(source, escape):
return code return code
try: try:
if escape[1:2] == "x": if escape[1:2] == "x":
# FIXME: in 2.0, \xNN must have exactly two digits
while source.next in HEXDIGITS: while source.next in HEXDIGITS:
escape = escape + source.get() escape = escape + source.get()
escape = escape[2:] escape = escape[2:]
...@@ -556,12 +555,13 @@ def _parse(source, state): ...@@ -556,12 +555,13 @@ def _parse(source, state):
return subpattern return subpattern
def parse(str, flags=0): def parse(str, flags=0, pattern=None):
# parse 're' pattern into list of (opcode, argument) tuples # parse 're' pattern into list of (opcode, argument) tuples
source = Tokenizer(str) source = Tokenizer(str)
pattern = Pattern() if pattern is None:
pattern = Pattern()
pattern.flags = flags pattern.flags = flags
p = _parse_sub(source, pattern, 0) p = _parse_sub(source, pattern, 0)
......
This diff is collapsed.
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