@@ -234,7 +234,7 @@ def isname(name):
234234 return False
235235 return True
236236
237- def _class_escape (source , escape ):
237+ def _class_escape (source , escape , nested ):
238238 # handle escape code inside character class
239239 code = ESCAPES .get (escape )
240240 if code :
@@ -266,16 +266,16 @@ def _class_escape(source, escape):
266266 if c in 'Uu' :
267267 warnings .warn ('bad escape %s; Unicode escapes are '
268268 'supported only since Python 3.3' % escape ,
269- FutureWarning , stacklevel = 8 )
269+ FutureWarning , stacklevel = nested + 6 )
270270 else :
271271 warnings .warnpy3k ('bad escape %s' % escape ,
272- DeprecationWarning , stacklevel = 8 )
272+ DeprecationWarning , stacklevel = nested + 6 )
273273 return LITERAL , ord (escape [1 ])
274274 except ValueError :
275275 pass
276276 raise error , "bogus escape: %s" % repr (escape )
277277
278- def _escape (source , escape , state ):
278+ def _escape (source , escape , state , nested ):
279279 # handle escape code in expression
280280 code = CATEGORIES .get (escape )
281281 if code :
@@ -315,7 +315,7 @@ def _escape(source, escape, state):
315315 import warnings
316316 warnings .warn ('group references in lookbehind '
317317 'assertions are not supported' ,
318- RuntimeWarning )
318+ RuntimeWarning , stacklevel = nested + 6 )
319319 return GROUPREF , group
320320 raise ValueError
321321 if len (escape ) == 2 :
@@ -324,23 +324,23 @@ def _escape(source, escape, state):
324324 if c in 'Uu' :
325325 warnings .warn ('bad escape %s; Unicode escapes are '
326326 'supported only since Python 3.3' % escape ,
327- FutureWarning , stacklevel = 8 )
327+ FutureWarning , stacklevel = nested + 6 )
328328 else :
329329 warnings .warnpy3k ('bad escape %s' % escape ,
330- DeprecationWarning , stacklevel = 8 )
330+ DeprecationWarning , stacklevel = nested + 6 )
331331 return LITERAL , ord (escape [1 ])
332332 except ValueError :
333333 pass
334334 raise error , "bogus escape: %s" % repr (escape )
335335
336- def _parse_sub (source , state , nested = 1 ):
336+ def _parse_sub (source , state , nested ):
337337 # parse an alternation: a|b|c
338338
339339 items = []
340340 itemsappend = items .append
341341 sourcematch = source .match
342342 while 1 :
343- itemsappend (_parse (source , state ))
343+ itemsappend (_parse (source , state , nested + 1 ))
344344 if sourcematch ("|" ):
345345 continue
346346 if not nested :
@@ -392,10 +392,10 @@ def _parse_sub(source, state, nested=1):
392392 subpattern .append ((BRANCH , (None , items )))
393393 return subpattern
394394
395- def _parse_sub_cond (source , state , condgroup ):
396- item_yes = _parse (source , state )
395+ def _parse_sub_cond (source , state , condgroup , nested ):
396+ item_yes = _parse (source , state , nested + 1 )
397397 if source .match ("|" ):
398- item_no = _parse (source , state )
398+ item_no = _parse (source , state , nested + 1 )
399399 if source .match ("|" ):
400400 raise error , "conditional backref with more than two branches"
401401 else :
@@ -411,7 +411,7 @@ def _parse_sub_cond(source, state, condgroup):
411411_LOOKBEHINDASSERTCHARS = set ("=!" )
412412_REPEATCODES = set ([MIN_REPEAT , MAX_REPEAT ])
413413
414- def _parse (source , state ):
414+ def _parse (source , state , nested ):
415415 # parse a simple pattern
416416 subpattern = SubPattern (state )
417417
@@ -462,7 +462,7 @@ def _parse(source, state):
462462 if this == "]" and set != start :
463463 break
464464 elif this and this [0 ] == "\\ " :
465- code1 = _class_escape (source , this )
465+ code1 = _class_escape (source , this , nested + 1 )
466466 elif this :
467467 code1 = LITERAL , ord (this )
468468 else :
@@ -478,7 +478,7 @@ def _parse(source, state):
478478 break
479479 elif this :
480480 if this [0 ] == "\\ " :
481- code2 = _class_escape (source , this )
481+ code2 = _class_escape (source , this , nested + 1 )
482482 else :
483483 code2 = LITERAL , ord (this )
484484 if code1 [0 ] != LITERAL or code2 [0 ] != LITERAL :
@@ -608,7 +608,7 @@ def _parse(source, state):
608608 import warnings
609609 warnings .warn ('group references in lookbehind '
610610 'assertions are not supported' ,
611- RuntimeWarning )
611+ RuntimeWarning , stacklevel = nested + 6 )
612612 subpatternappend ((GROUPREF , gid ))
613613 continue
614614 else :
@@ -638,7 +638,7 @@ def _parse(source, state):
638638 dir = - 1 # lookbehind
639639 char = sourceget ()
640640 state .lookbehind += 1
641- p = _parse_sub (source , state )
641+ p = _parse_sub (source , state , nested + 1 )
642642 if dir < 0 :
643643 state .lookbehind -= 1
644644 if not sourcematch (")" ):
@@ -675,7 +675,7 @@ def _parse(source, state):
675675 import warnings
676676 warnings .warn ('group references in lookbehind '
677677 'assertions are not supported' ,
678- RuntimeWarning )
678+ RuntimeWarning , stacklevel = nested + 6 )
679679 else :
680680 # flags
681681 if not source .next in FLAGS :
@@ -690,9 +690,9 @@ def _parse(source, state):
690690 else :
691691 group = state .opengroup (name )
692692 if condgroup :
693- p = _parse_sub_cond (source , state , condgroup )
693+ p = _parse_sub_cond (source , state , condgroup , nested + 1 )
694694 else :
695- p = _parse_sub (source , state )
695+ p = _parse_sub (source , state , nested + 1 )
696696 if not sourcematch (")" ):
697697 raise error , "unbalanced parenthesis"
698698 if group is not None :
@@ -714,7 +714,7 @@ def _parse(source, state):
714714 subpattern .append ((AT , AT_END ))
715715
716716 elif this and this [0 ] == "\\ " :
717- code = _escape (source , this , state )
717+ code = _escape (source , this , state , nested + 1 )
718718 subpatternappend (code )
719719
720720 else :
0 commit comments