From 63e18195b8b7a064488d106537703861f08aa415 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 11 Jul 1997 11:08:38 +0000 Subject: New version from Jeffrey after I complained about some glaring bugs. --- Lib/re.py | 12 ++++++------ Modules/reopmodule.c | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/re.py b/Lib/re.py index 016cd68..60dcb8b 100644 --- a/Lib/re.py +++ b/Lib/re.py @@ -137,7 +137,7 @@ class MatchObject: except (KeyError, TypeError): raise IndexError return self.regs[i] - def group(i): + def group(self, i): if type(i) == type(''): try: i = self.re.groupindex[i] @@ -188,12 +188,13 @@ class Set(Instruction): name = 'set' def __init__(self, set): self.set = set + print set Instruction.__init__(self, chr(3), 33) - def assemble_set(self, position, labels): + def assemble(self, position, labels): result = self.opcode temp = 0 for i, c in map(lambda x: (x, chr(x)), range(256)): - if c in self.set[2]: + if c in self.set: temp = temp | (1 << (i & 7)) if (i % 8) == 7: result = result + chr(temp) @@ -203,7 +204,7 @@ class Set(Instruction): result = '%-15s' % (self.name) self.set.sort() for char in self.set: - result = result + `char` + result = result + char return result class Exact(Instruction): @@ -768,7 +769,7 @@ def compile(pattern, flags=0): expr.append(Label(label)) label = label + 1 - if stack[-1][0][1] > 0: + if stack[-1][0].register > 0: expr = [StartMemory(stack[-1][0].register)] + \ expr + \ [EndMemory(stack[-1][0].register)] @@ -1075,7 +1076,6 @@ def compile(pattern, flags=0): if next not in set: set.append(next) last = next - if pattern[index] != ']': raise error, 'incomplete set' diff --git a/Modules/reopmodule.c b/Modules/reopmodule.c index 0d12210..2ac467f 100644 --- a/Modules/reopmodule.c +++ b/Modules/reopmodule.c @@ -119,6 +119,10 @@ reop_match(self, args) PyErr_SetString(ReopError, "match failure"); return NULL; } + if (result == -1) { + Py_INCREF(Py_None); + return Py_None; + } return makeresult(&re_regs, num_regs); } @@ -162,6 +166,10 @@ reop_search(self, args) PyErr_SetString(ReopError, "match failure"); return NULL; } + if (result == -1) { + Py_INCREF(Py_None); + return Py_None; + } return makeresult(&re_regs, num_regs); } -- cgit v0.12