def _smartPop(self, name):
nestingResetTriggers = self.NESTABLE_TAGS.get(name)<EOL>isNestable = nestingResetTriggers != None<EOL>isResetNesting = name in self.RESET_NESTING_TAGS<EOL>popTo = None<EOL>inclusive = True<EOL>for i in range(len(self.tagStack)-<NUM_LIT:1>, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>p = self.tagStack[i]<EOL>if (not p or p.name == name) and not isNestable:<EOL><INDENT>popTo = name<EOL>break<EOL><DEDENT>if (nestingResetTriggers != None<EOL>and p.name in nestingResetTriggers)or (nestingResetTriggers == None and isResetNesting<EOL>and p.name in self.RESET_NESTING_TAGS):<EOL><INDENT>popTo = p.name<EOL>inclusive = False<EOL>break<EOL><DEDENT>p = p.parent<EOL><DEDENT>if popTo:<EOL><INDENT>self._popToTag(popTo, inclusive)<EOL><DEDENT>
We need to pop up to the previous tag of this type, unless
        one of this tag's nesting reset triggers comes between this
        tag and the previous tag of this type, OR unless this tag is a
        generic nesting trigger and another generic nesting trigger
        comes between this tag and the previous tag of this type.

        Examples:
         <p>Foo<b>Bar *<p>* should pop to 'p', not 'b'.
         <p>Foo<table>Bar *<p>* should pop to 'table', not 'p'.
         <p>Foo<table><tr>Bar *<p>* should pop to 'tr', not 'p'.

         <li><ul><li> *<li>* should pop to 'ul', not the first 'li'.
         <tr><table><tr> *<tr>* should pop to 'table', not the first 'tr'
         <td><tr><td> *<td>* should pop to 'tr', not the first 'td'