'Remove nodes and attributes from the soup that aren\'t specifically allowed.'

def strip_disallowed(self, soup):

    toremove = []
    for node in soup.recursiveChildGenerator():
        if (self.remove_comments and isinstance(node, Comment)):
            toremove.append((False, node))
            continue
        if isinstance(node, basestring):
            continue
        if (node.name not in self.allowed_tags):
            toremove.append(((node.name in self.disallowed_tags_save_content), node))
            continue
        attrs = []
        for (k, v) in node.attrs:
            if (not v):
                continue
            if (k.lower() not in self.allowed_attributes):
                continue
            v2 = v.lower()
            if any(((x in v2) for x in ('javascript:', 'vbscript:', 'expression('))):
                continue
            attrs.append((k, v))
        node.attrs = attrs
    self._remove_nodes(toremove)
