This commit was manufactured by cvs2svn to create tag 'cnrisync'.
[python/dscho.git] / Lib / regexp.py
blob4b5db73e03532f1d72ac393542fbd5fe36f74cd4
1 # Provide backward compatibility for module "regexp" using "regex".
3 import regex
4 from regex_syntax import *
6 class Prog:
7 def __init__(self, pat):
8 save_syntax = regex.set_syntax(RE_SYNTAX_AWK)
9 try:
10 self.prog = regex.compile(pat)
11 finally:
12 xxx = regex.set_syntax(save_syntax)
13 def match(self, str, offset = 0):
14 if self.prog.search(str, offset) < 0:
15 return ()
16 regs = self.prog.regs
17 i = len(regs)
18 while i > 0 and regs[i-1] == (-1, -1):
19 i = i-1
20 return regs[:i]
22 def compile(pat):
23 return Prog(pat)
25 cache_pat = None
26 cache_prog = None
28 def match(pat, str):
29 global cache_pat, cache_prog
30 if pat <> cache_pat:
31 cache_pat, cache_prog = pat, compile(pat)
32 return cache_prog.match(str)