1
1
from __future__ import unicode_literals
2
2
import re
3
3
import warnings
4
+ from numbers import Integral
4
5
5
6
from rure import Rure
6
7
from rure import DEFAULT_FLAGS
@@ -76,7 +77,7 @@ def search(self, string, pos=0, endpos=None):
76
77
else :
77
78
match = self ._rure .find (haystack , pos )
78
79
if match :
79
- return MatchObject (pos , endpos , self , haystack , None )
80
+ return MatchObject (pos , endpos , self , haystack , 0 )
80
81
81
82
@accepts_string
82
83
def match (self , string , pos = 0 , endpos = None ):
@@ -95,12 +96,11 @@ def findall(self, string, pos=0, endpos=None):
95
96
def finditer (self , string , pos = 0 , endpos = None ):
96
97
haystack = string [:endpos ].encode ('utf8' )
97
98
if self .submatches :
98
- captures = self ._rure .captures (haystack , pos )
99
99
for captures in self ._rure .captures_iter (haystack , pos ):
100
100
yield MatchObject (pos , endpos , self , haystack , captures )
101
101
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 )
104
104
105
105
@accepts_string
106
106
def sub (self , repl , string , count = 0 ):
@@ -164,8 +164,10 @@ def lastgroup(self, decode=True):
164
164
165
165
@property
166
166
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 ]
169
171
return self ._captures
170
172
171
173
def expand (self , template ):
0 commit comments