def construct_selector(self, el, attr=''):
        """Construct an selector for context."""

        selector = deque()

        ancestor = el
        while ancestor and ancestor.parent:
            if ancestor is not el:
                selector.appendleft(ancestor.name)
            else:
                tag = ancestor.name
                prefix = ancestor.prefix
                sel = ''
                if prefix:
                    sel += prefix + '|'
                sel = tag
                if attr:
                    sel += '[%s]' % attr
                selector.appendleft(sel)
            ancestor = ancestor.parent
        return '>'.join(selector)
def construct_selector ( self , el , attr = '' ) : selector = deque ( ) ancestor = el while ancestor and ancestor . parent : if ancestor is not el : selector . appendleft ( ancestor . name ) else : tag = ancestor . name prefix = ancestor . prefix sel = '' if prefix : sel += prefix + '|' sel = tag if attr : sel += '[%s]' % attr selector . appendleft ( sel ) ancestor = ancestor . parent return '>' . join ( selector )
Construct an selector for context.