'Perform a CSS selection operation on the current element.'

def select(self, selector):

    tokens = selector.split()
    current_context = [self]
    for (index, token) in enumerate(tokens):
        if (tokens[(index - 1)] == '>'):
            continue
        m = self.attribselect_re.match(token)
        if (m is not None):
            (tag, attribute, operator, value) = m.groups()
            if (not tag):
                tag = True
            checker = self._attribute_checker(operator, attribute, value)
            found = []
            for context in current_context:
                found.extend([el for el in context.find_all(tag) if checker(el)])
            current_context = found
            continue
        if ('#' in token):
            (tag, id) = token.split('#', 1)
            if (tag == ''):
                tag = True
            el = current_context[0].find(tag, {'id': id})
            if (el is None):
                return []
            current_context = [el]
            continue
        if ('.' in token):
            (tag_name, klass) = token.split('.', 1)
            if (not tag_name):
                tag_name = True
            classes = set(klass.split('.'))
            found = []
            def classes_match(tag):
                if ((tag_name is not True) and (tag.name != tag_name)):
                    return False
                if (not tag.has_attr('class')):
                    return False
                return classes.issubset(tag['class'])
            for context in current_context:
                found.extend(context.find_all(classes_match))
            current_context = found
            continue
        if (token == '*'):
            found = []
            for context in current_context:
                found.extend(context.findAll(True))
            current_context = found
            continue
        if (token == '>'):
            tag = tokens[(index + 1)]
            if (not tag):
                tag = True
            found = []
            for context in current_context:
                found.extend(context.find_all(tag, recursive=False))
            current_context = found
            continue
        if (not self.tag_name_re.match(token)):
            return []
        found = []
        for context in current_context:
            found.extend(context.findAll(token))
        current_context = found
    return current_context
