Mercurial > cpython-lru_cache-weakref
annotate Lib/regexp.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 1940892d2fe3 |
| children |
| rev | line source |
|---|---|
| 540 | 1 # Provide backward compatibility for module "regexp" using "regex". |
| 2 | |
| 3 import regex | |
| 4 from regex_syntax import * | |
| 5 | |
| 6 class Prog: | |
|
1435
560ec7030817
* Mass change: get rid of all init() methods, in favor of __init__()
Guido van Rossum <guido@python.org>
parents:
1178
diff
changeset
|
7 def __init__(self, pat): |
| 540 | 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) | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
13 def match(self, str, offset = 0): |
| 540 | 14 if self.prog.search(str, offset) < 0: |
| 15 return () | |
|
557
1ef63adf4fc5
New == syntax; regs is no longer a method.
Guido van Rossum <guido@python.org>
parents:
540
diff
changeset
|
16 regs = self.prog.regs |
| 540 | 17 i = len(regs) |
|
557
1ef63adf4fc5
New == syntax; regs is no longer a method.
Guido van Rossum <guido@python.org>
parents:
540
diff
changeset
|
18 while i > 0 and regs[i-1] == (-1, -1): |
| 540 | 19 i = i-1 |
| 20 return regs[:i] | |
| 21 | |
| 22 def compile(pat): | |
|
1435
560ec7030817
* Mass change: get rid of all init() methods, in favor of __init__()
Guido van Rossum <guido@python.org>
parents:
1178
diff
changeset
|
23 return Prog(pat) |
| 540 | 24 |
| 25 cache_pat = None | |
| 26 cache_prog = None | |
| 27 | |
| 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) |
