8000 Pass in the correct capture item index, so we can retrieve it later. · davidblewett/rure-python@954b9de · GitHub
[go: up one dir, main page]

Skip to content

Commit 954b9de

Browse files
committed
Pass in the correct capture item index, so we can retrieve it later.
1 parent 0cc4d3e commit 954b9de

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

rure/regex.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import unicode_literals
22
import re
33
import warnings
4+
from numbers import Integral
45

56
from rure import Rure
67
from rure import DEFAULT_FLAGS
@@ -76,7 +77,7 @@ def search(self, string, pos=0, endpos=None):
7677
else:
7778
match = self._rure.find(haystack, pos)
7879
if match:
79-
return MatchObject(pos, endpos, self, haystack, None)
80+
return MatchObject(pos, endpos, self, haystack, 0)
8081

8182
@accepts_string
8283
def match(self, string, pos=0, endpos=None):
@@ -95,12 +96,11 @@ def findall(self, string, pos=0, endpos=None):
9596
def finditer(self, string, pos=0, endpos=None):
9697
haystack = string[:endpos].encode('utf8')
9798
if self.submatches:
98-
captures = self._rure.captures(haystack, pos)
9999
for captures in self._rure.captures_iter(haystack, pos):
100100
yield MatchObject(pos, endpos, self, haystack, captures)
101101
else:
102-
for match in self._rure.find_iter(haystack, pos):
103-
yield MatchObject(pos, endpos, self, haystack, None)
102+
for i, match in enumerate(self._rure.find_iter(haystack, pos)):
103+
yield MatchObject(pos, endpos, self, haystack, i)
104104

105105
@accepts_string
106106
def sub(self, repl, string, count=0):
@@ -164,8 +164,10 @@ def lastgroup(self, decode=True):
164164

165165
@property
166166
def captures(self):
167-
if self._captures is None:
168-
self._captures = self.re._rure.captures(self.string, self.pos)
167+
if isinstance(self._captures, Integral):
168+
all_captures = list(self.re._rure.captures_iter(self.string,
169+
self.pos))
170+
self._captures = all_captures[self._captures]
169171
return self._captures
170172

171173
def expand(self, template):

0 commit comments

Comments
 (0)
0