@@ -180,6 +180,10 @@ cdef class Match:
180
180
return self ._groups[1 :]
181
181
182
182
def group (self , *args ):
183
+ try :
184
+ string = basestring
185
+ except NameError as e:
186
+ string = (str , bytes)
183
187
if len (args) > 1 :
184
188
return tuple ([self .group(i) for i in args])
185
189
elif len (args) > 0 :
@@ -191,22 +195,22 @@ cdef class Match:
191
195
192
196
self .init_groups()
193
197
194
- if isinstance (groupnum, basestring ):
198
+ if isinstance (groupnum, string ):
195
199
return self .groupdict()[groupnum]
196
200
197
201
idx = groupnum
198
202
199
203
if idx > self .nmatches - 1 :
200
204
raise IndexError (" no such group" )
201
205
return self ._groups[idx]
202
-
206
+
203
207
cdef object _convert_positions(self , positions):
204
208
cdef char * s = self .match_string
205
209
cdef int cpos = 0
206
210
cdef int upos = 0
207
211
cdef int size = len (self .match_string)
208
- cdef int c
209
-
212
+ cdef int c
213
+
210
214
new_positions = []
211
215
i = 0
212
216
num_positions = len (positions)
@@ -253,7 +257,7 @@ cdef class Match:
253
257
posdict = dict (zip (positions, self ._convert_positions(positions)))
254
258
255
259
return [(posdict[x], posdict[y]) for x,y in spans]
256
-
260
+
257
261
258
262
cdef _make_spans(self ):
259
263
if self ._spans is not None :
@@ -274,7 +278,7 @@ cdef class Match:
274
278
start = piece.data() - s
275
279
end = start + piece.length()
276
280
spans.append((start, end))
277
-
281
+
278
282
if self .encoded:
279
283
spans = self ._convert_spans(spans)
280
284
@@ -361,13 +365,13 @@ cdef class Match:
361
365
362
366
if self ._lastindex < 1 :
363
367
return None
364
-
368
+
365
369
it = self .named_groups.begin()
366
370
while it != self .named_groups.end():
367
371
if deref(it).second == self ._lastindex:
368
372
return cpp_to_pystring(deref(it).first)
369
373
inc(it)
370
-
374
+
371
375
return None
372
376
373
377
@@ -655,7 +659,7 @@ cdef class Pattern:
655
659
if fixed_repl == NULL :
656
660
fixed_repl = new _re2.cpp_string(cstring, s - cstring - 1 )
657
661
if c == ' n' :
658
- fixed_repl.push_back(' \n ' )
662
+ fixed_repl.push_back(' \n ' )
659
663
else :
660
664
fixed_repl.push_back(' \\ ' )
661
665
fixed_repl.push_back(' \\ ' )
@@ -853,14 +857,14 @@ def prepare_pattern(pattern, int flags):
853
857
elif this[1 ] == ' D' :
854
858
new_pattern.append(r ' \P {Nd}' )
855
859
elif this[1 ] == ' W' :
856
- # Since \w and \s are made out of several character groups,
860
+ # Since \w and \s are made out of several character groups,
857
861
# I don't see a way to convert their complements into a group
858
862
# without rewriting the whole expression, which seems too complicated.
859
863
860
864
raise CharClassProblemException()
861
865
elif this[1 ] == ' S' :
862
866
raise CharClassProblemException()
863
- else :
867
+ else :
864
868
new_pattern.append(this)
865
869
else :
866
870
new_pattern.append(this)
@@ -899,7 +903,7 @@ def prepare_pattern(pattern, int flags):
899
903
900
904
return ' ' .join(new_pattern)
901
905
902
-
906
+
903
907
904
908
def _compile (pattern , int flags = 0 , int max_mem = 8388608 ):
905
909
"""
@@ -936,7 +940,7 @@ def _compile(pattern, int flags=0, int max_mem=8388608):
936
940
elif current_notification == < int > FALLBACK_WARNING:
937
941
warnings.warn(" WARNING: Using re module. Reason: %s " % error_msg)
938
942
return re.compile(original_pattern, flags)
939
-
943
+
940
944
# Set the options given the flags above.
941
945
if flags & _I:
942
946
opts.set_case_sensitive(0 );
@@ -968,7 +972,7 @@ def _compile(pattern, int flags=0, int max_mem=8388608):
968
972
raise RegexError(error_msg)
969
973
elif error_code not in (_re2.ErrorBadPerlOp, _re2.ErrorRepeatSize,
970
974
_re2.ErrorBadEscape):
971
- # Raise an error because these will not be fixed by using the
975
+ # Raise an error because these will not be fixed by using the
972
976
# ``re`` module.
973
977
raise RegexError(error_msg)
974
978
elif current_notification == < int > FALLBACK_WARNING:
0 commit comments