#NEWLINE# def next_unbalanced_tag( view , search = None , search_args = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , restart_at = None , tags = [ ] ) : #NEWLINE# #INDENT# assert ( search and restart_at ) , 'wrong call' #NEWLINE# ( region , tag , is_end_tag ) = search ( view , ** search_args ) #NEWLINE# if ( not region ) : #NEWLINE# #INDENT# return ( None , None ) #NEWLINE# #UNINDENT# if ( not is_end_tag ) : #NEWLINE# #INDENT# tags . append ( tag ) #NEWLINE# search_args . update ( restart_at ( region ) ) #NEWLINE# return next_unbalanced_tag ( view , search , search_args , restart_at , tags ) #NEWLINE# #UNINDENT# if ( ( not tags ) or ( tag not in tags ) ) : #NEWLINE# #INDENT# return ( region , tag ) #NEWLINE# #UNINDENT# while ( tag != tags . pop ( ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# search_args . update ( restart_at ( region ) ) #NEWLINE# return next_unbalanced_tag ( view , search , search_args , restart_at , tags )