filters Package

base Module

alphabeticalattributes Module

class html5lib.filters.alphabeticalattributes.Filter(source)

Bases: html5lib.filters.base.Filter

Alphabetizes attributes for elements

inject_meta_charset Module

class html5lib.filters.inject_meta_charset.Filter(source, encoding)

Bases: html5lib.filters.base.Filter

Injects <meta charset=ENCODING> tag into head of document

__init__(source, encoding)

Creates a Filter

Parameters:
  • source – the source token stream
  • encoding – the encoding to set

lint Module

class html5lib.filters.lint.Filter(source, require_matching_tags=True)

Bases: html5lib.filters.base.Filter

Lints the token stream for errors

If it finds any errors, it’ll raise an AssertionError.

__init__(source, require_matching_tags=True)

Creates a Filter

Parameters:
  • source – the source token stream
  • require_matching_tags – whether or not to require matching tags

optionaltags Module

class html5lib.filters.optionaltags.Filter(source)

Bases: html5lib.filters.base.Filter

Removes optional tags from the token stream

sanitizer Module

class html5lib.filters.sanitizer.Filter(source, allowed_elements=frozenset({('http://www.w3.org/1999/xhtml', 'dir'), ('http://www.w3.org/1999/xhtml', 'del'), ('http://www.w3.org/1999/xhtml', 'meter'), ('http://www.w3.org/1999/xhtml', 'nextid'), ('http://www.w3.org/1999/xhtml', 'abbr'), ('http://www.w3.org/1999/xhtml', 'code'), ('http://www.w3.org/2000/svg', 'path'), ('http://www.w3.org/1999/xhtml', 'canvas'), ('http://www.w3.org/1999/xhtml', 'option'), ('http://www.w3.org/2000/svg', 'set'), ('http://www.w3.org/2000/svg', 'title'), ('http://www.w3.org/1998/Math/MathML', 'mtd'), ('http://www.w3.org/2000/svg', 'rect'), ('http://www.w3.org/1999/xhtml', 'datagrid'), ('http://www.w3.org/1999/xhtml', 'table'), ('http://www.w3.org/2000/svg', 'animateTransform'), ('http://www.w3.org/1999/xhtml', 'audio'), ('http://www.w3.org/2000/svg', 'stop'), ('http://www.w3.org/2000/svg', 'line'), ('http://www.w3.org/1999/xhtml', 'nav'), ('http://www.w3.org/1999/xhtml', 'p'), ('http://www.w3.org/1999/xhtml', 'h3'), ('http://www.w3.org/2000/svg', 'glyph'), ('http://www.w3.org/1998/Math/MathML', 'merror'), ('http://www.w3.org/2000/svg', 'polyline'), ('http://www.w3.org/1999/xhtml', 'sound'), ('http://www.w3.org/2000/svg', 'a'), ('http://www.w3.org/1999/xhtml', 'tt'), ('http://www.w3.org/1999/xhtml', 'b'), ('http://www.w3.org/1999/xhtml', 'dialog'), ('http://www.w3.org/1999/xhtml', 'ins'), ('http://www.w3.org/1998/Math/MathML', 'mrow'), ('http://www.w3.org/2000/svg', 'ellipse'), ('http://www.w3.org/1999/xhtml', 'button'), ('http://www.w3.org/1998/Math/MathML', 'mn'), ('http://www.w3.org/1999/xhtml', 'colgroup'), ('http://www.w3.org/2000/svg', 'animateMotion'), ('http://www.w3.org/2000/svg', 'circle'), ('http://www.w3.org/2000/svg', 'text'), ('http://www.w3.org/1999/xhtml', 'col'), ('http://www.w3.org/1999/xhtml', 'aside'), ('http://www.w3.org/1998/Math/MathML', 'mprescripts'), ('http://www.w3.org/2000/svg', 'linearGradient'), ('http://www.w3.org/1999/xhtml', 'input'), ('http://www.w3.org/2000/svg', 'polygon'), ('http://www.w3.org/1999/xhtml', 'keygen'), ('http://www.w3.org/1999/xhtml', 'blockquote'), ('http://www.w3.org/2000/svg', 'metadata'), ('http://www.w3.org/1999/xhtml', 'fieldset'), ('http://www.w3.org/1999/xhtml', 'h4'), ('http://www.w3.org/2000/svg', 'font-face'), ('http://www.w3.org/1998/Math/MathML', 'mtable'), ('http://www.w3.org/1999/xhtml', 'output'), ('http://www.w3.org/1998/Math/MathML', 'math'), ('http://www.w3.org/1998/Math/MathML', 'mover'), ('http://www.w3.org/1999/xhtml', 'kbd'), ('http://www.w3.org/1999/xhtml', 'div'), ('http://www.w3.org/1999/xhtml', 'form'), ('http://www.w3.org/1999/xhtml', 'strong'), ('http://www.w3.org/1998/Math/MathML', 'mspace'), ('http://www.w3.org/1998/Math/MathML', 'mmultiscripts'), ('http://www.w3.org/1998/Math/MathML', 'mphantom'), ('http://www.w3.org/2000/svg', 'clipPath'), ('http://www.w3.org/1999/xhtml', 'sup'), ('http://www.w3.org/1999/xhtml', 'tr'), ('http://www.w3.org/2000/svg', 'svg'), ('http://www.w3.org/1999/xhtml', 'optgroup'), ('http://www.w3.org/2000/svg', 'desc'), ('http://www.w3.org/1999/xhtml', 'h2'), ('http://www.w3.org/1999/xhtml', 'details'), ('http://www.w3.org/1999/xhtml', 'td'), ('http://www.w3.org/1999/xhtml', 'pre'), ('http://www.w3.org/1999/xhtml', 'figure'), ('http://www.w3.org/1999/xhtml', 'u'), ('http://www.w3.org/1999/xhtml', 'datalist'), ('http://www.w3.org/1998/Math/MathML', 'mstyle'), ('http://www.w3.org/1999/xhtml', 'dfn'), ('http://www.w3.org/2000/svg', 'g'), ('http://www.w3.org/1999/xhtml', 'h6'), ('http://www.w3.org/1999/xhtml', 's'), ('http://www.w3.org/1999/xhtml', 'a'), ('http://www.w3.org/1999/xhtml', 'section'), ('http://www.w3.org/1998/Math/MathML', 'mpadded'), ('http://www.w3.org/1999/xhtml', 'br'), ('http://www.w3.org/1999/xhtml', 'label'), ('http://www.w3.org/1999/xhtml', 'select'), ('http://www.w3.org/1999/xhtml', 'span'), ('http://www.w3.org/1999/xhtml', 'img'), ('http://www.w3.org/1999/xhtml', 'sub'), ('http://www.w3.org/1999/xhtml', 'var'), ('http://www.w3.org/1999/xhtml', 'tfoot'), ('http://www.w3.org/1999/xhtml', 'event-source'), ('http://www.w3.org/1999/xhtml', 'small'), ('http://www.w3.org/1998/Math/MathML', 'munderover'), ('http://www.w3.org/2000/svg', 'switch'), ('http://www.w3.org/1999/xhtml', 'footer'), ('http://www.w3.org/1999/xhtml', 'acronym'), ('http://www.w3.org/1999/xhtml', 'command'), ('http://www.w3.org/1999/xhtml', 'address'), ('http://www.w3.org/1999/xhtml', 'dd'), ('http://www.w3.org/2000/svg', 'hkern'), ('http://www.w3.org/1998/Math/MathML', 'none'), ('http://www.w3.org/1998/Math/MathML', 'msubsup'), ('http://www.w3.org/1999/xhtml', 'hr'), ('http://www.w3.org/2000/svg', 'font-face-name'), ('http://www.w3.org/1999/xhtml', 'big'), ('http://www.w3.org/1998/Math/MathML', 'msub'), ('http://www.w3.org/1999/xhtml', 'header'), ('http://www.w3.org/1999/xhtml', 'ul'), ('http://www.w3.org/1999/xhtml', 'tbody'), ('http://www.w3.org/1998/Math/MathML', 'msup'), ('http://www.w3.org/1999/xhtml', 'h1'), ('http://www.w3.org/1999/xhtml', 'spacer'), ('http://www.w3.org/1999/xhtml', 'th'), ('http://www.w3.org/1999/xhtml', 'video'), ('http://www.w3.org/2000/svg', 'font-face-src'), ('http://www.w3.org/1998/Math/MathML', 'munder'), ('http://www.w3.org/2000/svg', 'radialGradient'), ('http://www.w3.org/1999/xhtml', 'strike'), ('http://www.w3.org/1998/Math/MathML', 'mroot'), ('http://www.w3.org/1999/xhtml', 'figcaption'), ('http://www.w3.org/1999/xhtml', 'em'), ('http://www.w3.org/1999/xhtml', 'samp'), ('http://www.w3.org/2000/svg', 'animate'), ('http://www.w3.org/1999/xhtml', 'legend'), ('http://www.w3.org/1999/xhtml', 'article'), ('http://www.w3.org/2000/svg', 'mpath'), ('http://www.w3.org/1998/Math/MathML', 'mi'), ('http://www.w3.org/2000/svg', 'animateColor'), ('http://www.w3.org/1999/xhtml', 'textarea'), ('http://www.w3.org/1999/xhtml', 'h5'), ('http://www.w3.org/1998/Math/MathML', 'maction'), ('http://www.w3.org/1998/Math/MathML', 'mo'), ('http://www.w3.org/1999/xhtml', 'center'), ('http://www.w3.org/1999/xhtml', 'map'), ('http://www.w3.org/1999/xhtml', 'multicol'), ('http://www.w3.org/1999/xhtml', 'i'), ('http://www.w3.org/1999/xhtml', 'ol'), ('http://www.w3.org/1999/xhtml', 'font'), ('http://www.w3.org/1999/xhtml', 'time'), ('http://www.w3.org/1999/xhtml', 'thead'), ('http://www.w3.org/1999/xhtml', 'area'), ('http://www.w3.org/2000/svg', 'defs'), ('http://www.w3.org/1998/Math/MathML', 'mtext'), ('http://www.w3.org/2000/svg', 'use'), ('http://www.w3.org/1999/xhtml', 'q'), ('http://www.w3.org/1998/Math/MathML', 'mfrac'), ('http://www.w3.org/1999/xhtml', 'source'), ('http://www.w3.org/2000/svg', 'tspan'), ('http://www.w3.org/1999/xhtml', 'm'), ('http://www.w3.org/1999/xhtml', 'li'), ('http://www.w3.org/1999/xhtml', 'caption'), ('http://www.w3.org/1998/Math/MathML', 'msqrt'), ('http://www.w3.org/2000/svg', 'missing-glyph'), ('http://www.w3.org/1999/xhtml', 'dl'), ('http://www.w3.org/2000/svg', 'marker'), ('http://www.w3.org/1999/xhtml', 'menu'), ('http://www.w3.org/1999/xhtml', 'dt'), ('http://www.w3.org/1999/xhtml', 'cite'), ('http://www.w3.org/1999/xhtml', 'progress'), ('http://www.w3.org/1998/Math/MathML', 'mtr')}), allowed_attributes=frozenset({(None, 'accept-charset'), (None, 'datafld'), (None, 'd'), (None, 'stroke-miterlimit'), (None, 'checked'), (None, 'display'), (None, 'values'), (None, 'bordercolordark'), (None, 'clear'), (None, 'bbox'), (None, 'fill'), (None, 'nowrap'), (None, 'refY'), (None, 'markerWidth'), (None, 'u1'), (None, 'x2'), (None, 'minsize'), (None, 'underline-position'), (None, 'slope'), (None, 'span'), (None, 'hanging'), (None, 'repeatDur'), (None, 'dynsrc'), (None, 'keyPoints'), (None, 'autocomplete'), (None, 'coords'), (None, 'width'), (None, 'fontstyle'), (None, 'cellpadding'), (None, 'datapagesize'), ('http://www.w3.org/1999/xlink', 'title'), (None, 'open'), (None, 'fill-rule'), (None, 'stemh'), (None, 'challenge'), (None, 'gutter'), (None, 'min'), (None, 'rowspacing'), (None, 'from'), (None, 'method'), (None, 'enctype'), (None, 'attributeType'), ('http://www.w3.org/1999/xlink', 'actuate'), (None, 'widths'), (None, 'form'), (None, 'x-height'), (None, 'vspace'), (None, 'overline-thickness'), (None, 'template'), (None, 'glyph-name'), (None, 'height'), (None, 'lspace'), (None, 'abbr'), (None, 'panose-1'), (None, 'orient'), (None, 'axis'), (None, 'keySplines'), (None, 'hidden'), (None, 'class'), (None, 'size'), (None, 'cite'), (None, 'r'), (None, 'border'), (None, 'compact'), (None, 'rows'), (None, 'rules'), (None, 'align'), (None, 'mathvariant'), (None, 'stop-color'), (None, 'value'), (None, 'rowlines'), (None, 'additive'), (None, 'name'), (None, 'color-rendering'), (None, 'mathcolor'), (None, 'by'), (None, 'fx'), (None, 'marker-start'), (None, 'rx'), (None, 'y1'), (None, 'ping'), (None, 'noshade'), (None, 'g2'), (None, 'fontweight'), (None, 'horiz-adv-x'), (None, 'charset'), (None, 'font-size'), (None, 'accent-height'), (None, 'attributeName'), (None, 'unicode-range'), (None, 'visibility'), (None, 'type'), (None, 'to'), (None, 'datasrc'), ('http://www.w3.org/1999/xlink', 'show'), (None, 'stroke'), (None, 'other'), (None, 'alt'), (None, 'colspan'), (None, 'loop'), (None, 'maxlength'), (None, 'delay'), (None, 'end'), (None, 'optimum'), (None, 'id'), (None, 'poster'), (None, 'stretchy'), (None, 'unselectable'), (None, 'begin'), (None, 'path'), (None, 'icon'), (None, 'repeat-max'), (None, 'rowalign'), (None, 'scriptlevel'), (None, 'depth'), (None, 'color'), (None, 'low'), (None, 'lowsrc'), (None, 'background'), (None, 'strikethrough-thickness'), (None, 'version'), (None, 'equalcolumns'), (None, 'linethickness'), (None, 'ascent'), (None, 'readonly'), (None, 'required'), (None, 'repeat-min'), (None, 'k'), (None, 'media'), (None, 'pqg'), (None, 'draggable'), (None, 'prompt'), ('http://www.w3.org/XML/1998/namespace', 'lang'), (None, 'selection'), (None, 'dur'), (None, 'href'), (None, 'lang'), (None, 'data'), (None, 'suppress'), (None, 'dy'), (None, 'markerUnits'), (None, 'clip-path'), (None, 'overline-position'), (None, 'rotate'), (None, 'dir'), (None, 'stroke-opacity'), (None, 'rowspan'), (None, 'summary'), (None, 'systemLanguage'), (None, 'transform'), (None, 'g1'), (None, 'list'), (None, 'zoomAndPan'), (None, 'points'), (None, 'action'), (None, 'columnlines'), (None, 'stemv'), (None, 'face'), (None, 'fy'), (None, 'offset'), (None, 'balance'), (None, 'strikethrough-position'), (None, 'ch'), (None, 'replace'), (None, 'units-per-em'), ('http://www.w3.org/1999/xlink', 'arcrole'), (None, 'requiredExtensions'), (None, 'selected'), (None, 'loopcount'), (None, 'repeatCount'), (None, 'font-family'), (None, 'urn'), (None, 'keytype'), (None, 'hspace'), (None, 'autofocus'), (None, 'scope'), (None, 'alphabetic'), ('http://www.w3.org/XML/1998/namespace', 'base'), (None, 'rel'), (None, 'hidefocus'), (None, 'y2'), (None, 'bgproperties'), (None, 'rev'), (None, 'requiredFeatures'), (None, 'ry'), (None, 'rightspacing'), (None, 'for'), (None, 'accesskey'), (None, 'stroke-dashoffset'), (None, 'headers'), (None, 'frame'), (None, 'gradientUnits'), (None, 'radiogroup'), (None, 'calcMode'), (None, 'opacity'), (None, 'ismap'), (None, 'font-variant'), (None, 'choff'), (None, 'font-style'), (None, 'ideographic'), (None, 'stop-opacity'), (None, 'cellspacing'), (None, 'charoff'), (None, 'x1'), (None, 'nohref'), (None, 'mathematical'), (None, 'start'), (None, 'descent'), (None, 'wrap'), (None, 'viewBox'), (None, 'max'), (None, 'bordercolor'), (None, 'stroke-linecap'), (None, 'toppadding'), ('http://www.w3.org/XML/1998/namespace', 'space'), (None, 'tabindex'), (None, 'rspace'), (None, 'marker-end'), (None, 'inputmode'), (None, 'src'), (None, 'stroke-dasharray'), (None, 'columnalign'), (None, 'point-size'), (None, 'bottompadding'), (None, 'galleryimg'), (None, 'cols'), (None, 'font-stretch'), (None, 'keyTimes'), (None, 'cy'), (None, 'shape'), (None, 'hreflang'), (None, 'separator'), (None, 'accumulate'), (None, 'target'), (None, 'fence'), (None, 'leftspacing'), (None, 'bgcolor'), (None, 'char'), (None, 'label'), ('http://www.w3.org/1999/xlink', 'role'), (None, 'contenteditable'), (None, 'underline-thickness'), (None, 'variable'), (None, 'preserveAspectRatio'), (None, 'accept'), (None, 'actiontype'), (None, 'longdesc'), (None, 'style'), (None, 'dx'), (None, 'high'), (None, 'origin'), (None, 'datetime'), (None, 'refX'), (None, 'stroke-linejoin'), (None, 'vrml'), (None, 'equalrows'), (None, 'preload'), (None, 'content'), (None, 'horiz-origin-x'), (None, 'default'), ('http://www.w3.org/1999/xlink', 'type'), (None, 'unicode'), (None, 'disabled'), ('http://www.w3.org/1999/xlink', 'href'), (None, 'cap-height'), (None, 'controls'), (None, 'markerHeight'), (None, 'text-anchor'), (None, 'mathbackground'), (None, 'baseProfile'), (None, 'arabic-form'), (None, 'marker-mid'), (None, 'y'), (None, 'fill-opacity'), (None, 'loopstart'), (None, 'x'), (None, 'multiple'), (None, 'valign'), (None, 'pattern'), (None, 'maxsize'), (None, 'usemap'), (None, 'pathLength'), (None, 'restart'), (None, 'u2'), (None, 'columnspacing'), (None, 'loopend'), (None, 'displaystyle'), (None, 'title'), (None, 'bordercolorlight'), (None, 'volume'), (None, 'font-weight'), (None, 'columnspan'), (None, 'stroke-width'), (None, 'step'), (None, 'cx')}), allowed_css_properties=frozenset({'text-decoration', 'font-size', 'border-bottom-color', 'border-right-color', 'border-collapse', 'float', 'volume', 'vertical-align', 'speak-punctuation', 'background-color', 'clear', 'cursor', 'text-align', 'font', 'font-family', 'line-height', 'stress', 'pause-before', 'voice-family', 'speech-rate', 'text-indent', 'pitch', 'border-top-color', 'height', 'white-space', 'unicode-bidi', 'width', 'speak-header', 'pause-after', 'letter-spacing', 'direction', 'pitch-range', 'richness', 'display', 'font-style', 'overflow', 'border-left-color', 'speak', 'border-color', 'speak-numeral', 'color', 'pause', 'elevation', 'font-variant', 'font-weight', 'azimuth'}), allowed_css_keywords=frozenset({'fuchsia', 'dotted', 'nowrap', 'left', 'center', 'teal', 'yellow', 'none', 'brown', 'dashed', 'red', 'lime', 'right', 'bottom', 'bold', 'italic', 'medium', 'block', 'solid', 'black', 'auto', 'aqua', 'normal', 'green', 'gray', 'transparent', 'blue', 'navy', 'collapse', 'olive', 'pointer', 'top', 'underline', 'both', 'maroon', 'white', 'purple', 'silver', '!important'}), allowed_svg_properties=frozenset({'stroke-opacity', 'stroke-linejoin', 'stroke-linecap', 'fill-rule', 'fill', 'fill-opacity', 'stroke-width', 'stroke'}), allowed_protocols=frozenset({'feed', 'sftp', 'gopher', 'ssh', 'mailto', 'ftp', 'xmpp', 'http', 'rsync', 'irc', 'callto', 'urn', 'rtsp', 'nntp', 'webcal', 'data', 'ed2k', 'news', 'https', 'afs', 'telnet', 'tag', 'aim'}), allowed_content_types=frozenset({'image/gif', 'image/bmp', 'image/webp', 'text/plain', 'image/jpeg', 'image/png'}), attr_val_is_uri=frozenset({(None, 'src'), (None, 'action'), ('http://www.w3.org/XML/1998/namespace', 'base'), (None, 'poster'), (None, 'datasrc'), ('http://www.w3.org/1999/xlink', 'href'), (None, 'dynsrc'), (None, 'href'), (None, 'longdesc'), (None, 'lowsrc'), (None, 'ping'), (None, 'background'), (None, 'cite')}), svg_attr_val_allows_ref=frozenset({(None, 'marker-start'), (None, 'mask'), (None, 'stroke'), (None, 'filter'), (None, 'cursor'), (None, 'color-profile'), (None, 'clip-path'), (None, 'fill'), (None, 'marker-mid'), (None, 'marker'), (None, 'marker-end')}), svg_allow_local_href=frozenset({(None, 'pattern'), (None, 'use'), (None, 'textpath'), (None, 'tref'), (None, 'animateMotion'), (None, 'animateTransform'), (None, 'animate'), (None, 'filter'), (None, 'altGlyph'), (None, 'cursor'), (None, 'animateColor'), (None, 'radialGradient'), (None, 'set'), (None, 'linearGradient'), (None, 'feImage')}))

Bases: html5lib.filters.base.Filter

Sanitizes token stream of XHTML+MathML+SVG and of inline style attributes

__init__(source, allowed_elements=frozenset({('http://www.w3.org/1999/xhtml', 'dir'), ('http://www.w3.org/1999/xhtml', 'del'), ('http://www.w3.org/1999/xhtml', 'meter'), ('http://www.w3.org/1999/xhtml', 'nextid'), ('http://www.w3.org/1999/xhtml', 'abbr'), ('http://www.w3.org/1999/xhtml', 'code'), ('http://www.w3.org/2000/svg', 'path'), ('http://www.w3.org/1999/xhtml', 'canvas'), ('http://www.w3.org/1999/xhtml', 'option'), ('http://www.w3.org/2000/svg', 'set'), ('http://www.w3.org/2000/svg', 'title'), ('http://www.w3.org/1998/Math/MathML', 'mtd'), ('http://www.w3.org/2000/svg', 'rect'), ('http://www.w3.org/1999/xhtml', 'datagrid'), ('http://www.w3.org/1999/xhtml', 'table'), ('http://www.w3.org/2000/svg', 'animateTransform'), ('http://www.w3.org/1999/xhtml', 'audio'), ('http://www.w3.org/2000/svg', 'stop'), ('http://www.w3.org/2000/svg', 'line'), ('http://www.w3.org/1999/xhtml', 'nav'), ('http://www.w3.org/1999/xhtml', 'p'), ('http://www.w3.org/1999/xhtml', 'h3'), ('http://www.w3.org/2000/svg', 'glyph'), ('http://www.w3.org/1998/Math/MathML', 'merror'), ('http://www.w3.org/2000/svg', 'polyline'), ('http://www.w3.org/1999/xhtml', 'sound'), ('http://www.w3.org/2000/svg', 'a'), ('http://www.w3.org/1999/xhtml', 'tt'), ('http://www.w3.org/1999/xhtml', 'b'), ('http://www.w3.org/1999/xhtml', 'dialog'), ('http://www.w3.org/1999/xhtml', 'ins'), ('http://www.w3.org/1998/Math/MathML', 'mrow'), ('http://www.w3.org/2000/svg', 'ellipse'), ('http://www.w3.org/1999/xhtml', 'button'), ('http://www.w3.org/1998/Math/MathML', 'mn'), ('http://www.w3.org/1999/xhtml', 'colgroup'), ('http://www.w3.org/2000/svg', 'animateMotion'), ('http://www.w3.org/2000/svg', 'circle'), ('http://www.w3.org/2000/svg', 'text'), ('http://www.w3.org/1999/xhtml', 'col'), ('http://www.w3.org/1999/xhtml', 'aside'), ('http://www.w3.org/1998/Math/MathML', 'mprescripts'), ('http://www.w3.org/2000/svg', 'linearGradient'), ('http://www.w3.org/1999/xhtml', 'input'), ('http://www.w3.org/2000/svg', 'polygon'), ('http://www.w3.org/1999/xhtml', 'keygen'), ('http://www.w3.org/1999/xhtml', 'blockquote'), ('http://www.w3.org/2000/svg', 'metadata'), ('http://www.w3.org/1999/xhtml', 'fieldset'), ('http://www.w3.org/1999/xhtml', 'h4'), ('http://www.w3.org/2000/svg', 'font-face'), ('http://www.w3.org/1998/Math/MathML', 'mtable'), ('http://www.w3.org/1999/xhtml', 'output'), ('http://www.w3.org/1998/Math/MathML', 'math'), ('http://www.w3.org/1998/Math/MathML', 'mover'), ('http://www.w3.org/1999/xhtml', 'kbd'), ('http://www.w3.org/1999/xhtml', 'div'), ('http://www.w3.org/1999/xhtml', 'form'), ('http://www.w3.org/1999/xhtml', 'strong'), ('http://www.w3.org/1998/Math/MathML', 'mspace'), ('http://www.w3.org/1998/Math/MathML', 'mmultiscripts'), ('http://www.w3.org/1998/Math/MathML', 'mphantom'), ('http://www.w3.org/2000/svg', 'clipPath'), ('http://www.w3.org/1999/xhtml', 'sup'), ('http://www.w3.org/1999/xhtml', 'tr'), ('http://www.w3.org/2000/svg', 'svg'), ('http://www.w3.org/1999/xhtml', 'optgroup'), ('http://www.w3.org/2000/svg', 'desc'), ('http://www.w3.org/1999/xhtml', 'h2'), ('http://www.w3.org/1999/xhtml', 'details'), ('http://www.w3.org/1999/xhtml', 'td'), ('http://www.w3.org/1999/xhtml', 'pre'), ('http://www.w3.org/1999/xhtml', 'figure'), ('http://www.w3.org/1999/xhtml', 'u'), ('http://www.w3.org/1999/xhtml', 'datalist'), ('http://www.w3.org/1998/Math/MathML', 'mstyle'), ('http://www.w3.org/1999/xhtml', 'dfn'), ('http://www.w3.org/2000/svg', 'g'), ('http://www.w3.org/1999/xhtml', 'h6'), ('http://www.w3.org/1999/xhtml', 's'), ('http://www.w3.org/1999/xhtml', 'a'), ('http://www.w3.org/1999/xhtml', 'section'), ('http://www.w3.org/1998/Math/MathML', 'mpadded'), ('http://www.w3.org/1999/xhtml', 'br'), ('http://www.w3.org/1999/xhtml', 'label'), ('http://www.w3.org/1999/xhtml', 'select'), ('http://www.w3.org/1999/xhtml', 'span'), ('http://www.w3.org/1999/xhtml', 'img'), ('http://www.w3.org/1999/xhtml', 'sub'), ('http://www.w3.org/1999/xhtml', 'var'), ('http://www.w3.org/1999/xhtml', 'tfoot'), ('http://www.w3.org/1999/xhtml', 'event-source'), ('http://www.w3.org/1999/xhtml', 'small'), ('http://www.w3.org/1998/Math/MathML', 'munderover'), ('http://www.w3.org/2000/svg', 'switch'), ('http://www.w3.org/1999/xhtml', 'footer'), ('http://www.w3.org/1999/xhtml', 'acronym'), ('http://www.w3.org/1999/xhtml', 'command'), ('http://www.w3.org/1999/xhtml', 'address'), ('http://www.w3.org/1999/xhtml', 'dd'), ('http://www.w3.org/2000/svg', 'hkern'), ('http://www.w3.org/1998/Math/MathML', 'none'), ('http://www.w3.org/1998/Math/MathML', 'msubsup'), ('http://www.w3.org/1999/xhtml', 'hr'), ('http://www.w3.org/2000/svg', 'font-face-name'), ('http://www.w3.org/1999/xhtml', 'big'), ('http://www.w3.org/1998/Math/MathML', 'msub'), ('http://www.w3.org/1999/xhtml', 'header'), ('http://www.w3.org/1999/xhtml', 'ul'), ('http://www.w3.org/1999/xhtml', 'tbody'), ('http://www.w3.org/1998/Math/MathML', 'msup'), ('http://www.w3.org/1999/xhtml', 'h1'), ('http://www.w3.org/1999/xhtml', 'spacer'), ('http://www.w3.org/1999/xhtml', 'th'), ('http://www.w3.org/1999/xhtml', 'video'), ('http://www.w3.org/2000/svg', 'font-face-src'), ('http://www.w3.org/1998/Math/MathML', 'munder'), ('http://www.w3.org/2000/svg', 'radialGradient'), ('http://www.w3.org/1999/xhtml', 'strike'), ('http://www.w3.org/1998/Math/MathML', 'mroot'), ('http://www.w3.org/1999/xhtml', 'figcaption'), ('http://www.w3.org/1999/xhtml', 'em'), ('http://www.w3.org/1999/xhtml', 'samp'), ('http://www.w3.org/2000/svg', 'animate'), ('http://www.w3.org/1999/xhtml', 'legend'), ('http://www.w3.org/1999/xhtml', 'article'), ('http://www.w3.org/2000/svg', 'mpath'), ('http://www.w3.org/1998/Math/MathML', 'mi'), ('http://www.w3.org/2000/svg', 'animateColor'), ('http://www.w3.org/1999/xhtml', 'textarea'), ('http://www.w3.org/1999/xhtml', 'h5'), ('http://www.w3.org/1998/Math/MathML', 'maction'), ('http://www.w3.org/1998/Math/MathML', 'mo'), ('http://www.w3.org/1999/xhtml', 'center'), ('http://www.w3.org/1999/xhtml', 'map'), ('http://www.w3.org/1999/xhtml', 'multicol'), ('http://www.w3.org/1999/xhtml', 'i'), ('http://www.w3.org/1999/xhtml', 'ol'), ('http://www.w3.org/1999/xhtml', 'font'), ('http://www.w3.org/1999/xhtml', 'time'), ('http://www.w3.org/1999/xhtml', 'thead'), ('http://www.w3.org/1999/xhtml', 'area'), ('http://www.w3.org/2000/svg', 'defs'), ('http://www.w3.org/1998/Math/MathML', 'mtext'), ('http://www.w3.org/2000/svg', 'use'), ('http://www.w3.org/1999/xhtml', 'q'), ('http://www.w3.org/1998/Math/MathML', 'mfrac'), ('http://www.w3.org/1999/xhtml', 'source'), ('http://www.w3.org/2000/svg', 'tspan'), ('http://www.w3.org/1999/xhtml', 'm'), ('http://www.w3.org/1999/xhtml', 'li'), ('http://www.w3.org/1999/xhtml', 'caption'), ('http://www.w3.org/1998/Math/MathML', 'msqrt'), ('http://www.w3.org/2000/svg', 'missing-glyph'), ('http://www.w3.org/1999/xhtml', 'dl'), ('http://www.w3.org/2000/svg', 'marker'), ('http://www.w3.org/1999/xhtml', 'menu'), ('http://www.w3.org/1999/xhtml', 'dt'), ('http://www.w3.org/1999/xhtml', 'cite'), ('http://www.w3.org/1999/xhtml', 'progress'), ('http://www.w3.org/1998/Math/MathML', 'mtr')}), allowed_attributes=frozenset({(None, 'accept-charset'), (None, 'datafld'), (None, 'd'), (None, 'stroke-miterlimit'), (None, 'checked'), (None, 'display'), (None, 'values'), (None, 'bordercolordark'), (None, 'clear'), (None, 'bbox'), (None, 'fill'), (None, 'nowrap'), (None, 'refY'), (None, 'markerWidth'), (None, 'u1'), (None, 'x2'), (None, 'minsize'), (None, 'underline-position'), (None, 'slope'), (None, 'span'), (None, 'hanging'), (None, 'repeatDur'), (None, 'dynsrc'), (None, 'keyPoints'), (None, 'autocomplete'), (None, 'coords'), (None, 'width'), (None, 'fontstyle'), (None, 'cellpadding'), (None, 'datapagesize'), ('http://www.w3.org/1999/xlink', 'title'), (None, 'open'), (None, 'fill-rule'), (None, 'stemh'), (None, 'challenge'), (None, 'gutter'), (None, 'min'), (None, 'rowspacing'), (None, 'from'), (None, 'method'), (None, 'enctype'), (None, 'attributeType'), ('http://www.w3.org/1999/xlink', 'actuate'), (None, 'widths'), (None, 'form'), (None, 'x-height'), (None, 'vspace'), (None, 'overline-thickness'), (None, 'template'), (None, 'glyph-name'), (None, 'height'), (None, 'lspace'), (None, 'abbr'), (None, 'panose-1'), (None, 'orient'), (None, 'axis'), (None, 'keySplines'), (None, 'hidden'), (None, 'class'), (None, 'size'), (None, 'cite'), (None, 'r'), (None, 'border'), (None, 'compact'), (None, 'rows'), (None, 'rules'), (None, 'align'), (None, 'mathvariant'), (None, 'stop-color'), (None, 'value'), (None, 'rowlines'), (None, 'additive'), (None, 'name'), (None, 'color-rendering'), (None, 'mathcolor'), (None, 'by'), (None, 'fx'), (None, 'marker-start'), (None, 'rx'), (None, 'y1'), (None, 'ping'), (None, 'noshade'), (None, 'g2'), (None, 'fontweight'), (None, 'horiz-adv-x'), (None, 'charset'), (None, 'font-size'), (None, 'accent-height'), (None, 'attributeName'), (None, 'unicode-range'), (None, 'visibility'), (None, 'type'), (None, 'to'), (None, 'datasrc'), ('http://www.w3.org/1999/xlink', 'show'), (None, 'stroke'), (None, 'other'), (None, 'alt'), (None, 'colspan'), (None, 'loop'), (None, 'maxlength'), (None, 'delay'), (None, 'end'), (None, 'optimum'), (None, 'id'), (None, 'poster'), (None, 'stretchy'), (None, 'unselectable'), (None, 'begin'), (None, 'path'), (None, 'icon'), (None, 'repeat-max'), (None, 'rowalign'), (None, 'scriptlevel'), (None, 'depth'), (None, 'color'), (None, 'low'), (None, 'lowsrc'), (None, 'background'), (None, 'strikethrough-thickness'), (None, 'version'), (None, 'equalcolumns'), (None, 'linethickness'), (None, 'ascent'), (None, 'readonly'), (None, 'required'), (None, 'repeat-min'), (None, 'k'), (None, 'media'), (None, 'pqg'), (None, 'draggable'), (None, 'prompt'), ('http://www.w3.org/XML/1998/namespace', 'lang'), (None, 'selection'), (None, 'dur'), (None, 'href'), (None, 'lang'), (None, 'data'), (None, 'suppress'), (None, 'dy'), (None, 'markerUnits'), (None, 'clip-path'), (None, 'overline-position'), (None, 'rotate'), (None, 'dir'), (None, 'stroke-opacity'), (None, 'rowspan'), (None, 'summary'), (None, 'systemLanguage'), (None, 'transform'), (None, 'g1'), (None, 'list'), (None, 'zoomAndPan'), (None, 'points'), (None, 'action'), (None, 'columnlines'), (None, 'stemv'), (None, 'face'), (None, 'fy'), (None, 'offset'), (None, 'balance'), (None, 'strikethrough-position'), (None, 'ch'), (None, 'replace'), (None, 'units-per-em'), ('http://www.w3.org/1999/xlink', 'arcrole'), (None, 'requiredExtensions'), (None, 'selected'), (None, 'loopcount'), (None, 'repeatCount'), (None, 'font-family'), (None, 'urn'), (None, 'keytype'), (None, 'hspace'), (None, 'autofocus'), (None, 'scope'), (None, 'alphabetic'), ('http://www.w3.org/XML/1998/namespace', 'base'), (None, 'rel'), (None, 'hidefocus'), (None, 'y2'), (None, 'bgproperties'), (None, 'rev'), (None, 'requiredFeatures'), (None, 'ry'), (None, 'rightspacing'), (None, 'for'), (None, 'accesskey'), (None, 'stroke-dashoffset'), (None, 'headers'), (None, 'frame'), (None, 'gradientUnits'), (None, 'radiogroup'), (None, 'calcMode'), (None, 'opacity'), (None, 'ismap'), (None, 'font-variant'), (None, 'choff'), (None, 'font-style'), (None, 'ideographic'), (None, 'stop-opacity'), (None, 'cellspacing'), (None, 'charoff'), (None, 'x1'), (None, 'nohref'), (None, 'mathematical'), (None, 'start'), (None, 'descent'), (None, 'wrap'), (None, 'viewBox'), (None, 'max'), (None, 'bordercolor'), (None, 'stroke-linecap'), (None, 'toppadding'), ('http://www.w3.org/XML/1998/namespace', 'space'), (None, 'tabindex'), (None, 'rspace'), (None, 'marker-end'), (None, 'inputmode'), (None, 'src'), (None, 'stroke-dasharray'), (None, 'columnalign'), (None, 'point-size'), (None, 'bottompadding'), (None, 'galleryimg'), (None, 'cols'), (None, 'font-stretch'), (None, 'keyTimes'), (None, 'cy'), (None, 'shape'), (None, 'hreflang'), (None, 'separator'), (None, 'accumulate'), (None, 'target'), (None, 'fence'), (None, 'leftspacing'), (None, 'bgcolor'), (None, 'char'), (None, 'label'), ('http://www.w3.org/1999/xlink', 'role'), (None, 'contenteditable'), (None, 'underline-thickness'), (None, 'variable'), (None, 'preserveAspectRatio'), (None, 'accept'), (None, 'actiontype'), (None, 'longdesc'), (None, 'style'), (None, 'dx'), (None, 'high'), (None, 'origin'), (None, 'datetime'), (None, 'refX'), (None, 'stroke-linejoin'), (None, 'vrml'), (None, 'equalrows'), (None, 'preload'), (None, 'content'), (None, 'horiz-origin-x'), (None, 'default'), ('http://www.w3.org/1999/xlink', 'type'), (None, 'unicode'), (None, 'disabled'), ('http://www.w3.org/1999/xlink', 'href'), (None, 'cap-height'), (None, 'controls'), (None, 'markerHeight'), (None, 'text-anchor'), (None, 'mathbackground'), (None, 'baseProfile'), (None, 'arabic-form'), (None, 'marker-mid'), (None, 'y'), (None, 'fill-opacity'), (None, 'loopstart'), (None, 'x'), (None, 'multiple'), (None, 'valign'), (None, 'pattern'), (None, 'maxsize'), (None, 'usemap'), (None, 'pathLength'), (None, 'restart'), (None, 'u2'), (None, 'columnspacing'), (None, 'loopend'), (None, 'displaystyle'), (None, 'title'), (None, 'bordercolorlight'), (None, 'volume'), (None, 'font-weight'), (None, 'columnspan'), (None, 'stroke-width'), (None, 'step'), (None, 'cx')}), allowed_css_properties=frozenset({'text-decoration', 'font-size', 'border-bottom-color', 'border-right-color', 'border-collapse', 'float', 'volume', 'vertical-align', 'speak-punctuation', 'background-color', 'clear', 'cursor', 'text-align', 'font', 'font-family', 'line-height', 'stress', 'pause-before', 'voice-family', 'speech-rate', 'text-indent', 'pitch', 'border-top-color', 'height', 'white-space', 'unicode-bidi', 'width', 'speak-header', 'pause-after', 'letter-spacing', 'direction', 'pitch-range', 'richness', 'display', 'font-style', 'overflow', 'border-left-color', 'speak', 'border-color', 'speak-numeral', 'color', 'pause', 'elevation', 'font-variant', 'font-weight', 'azimuth'}), allowed_css_keywords=frozenset({'fuchsia', 'dotted', 'nowrap', 'left', 'center', 'teal', 'yellow', 'none', 'brown', 'dashed', 'red', 'lime', 'right', 'bottom', 'bold', 'italic', 'medium', 'block', 'solid', 'black', 'auto', 'aqua', 'normal', 'green', 'gray', 'transparent', 'blue', 'navy', 'collapse', 'olive', 'pointer', 'top', 'underline', 'both', 'maroon', 'white', 'purple', 'silver', '!important'}), allowed_svg_properties=frozenset({'stroke-opacity', 'stroke-linejoin', 'stroke-linecap', 'fill-rule', 'fill', 'fill-opacity', 'stroke-width', 'stroke'}), allowed_protocols=frozenset({'feed', 'sftp', 'gopher', 'ssh', 'mailto', 'ftp', 'xmpp', 'http', 'rsync', 'irc', 'callto', 'urn', 'rtsp', 'nntp', 'webcal', 'data', 'ed2k', 'news', 'https', 'afs', 'telnet', 'tag', 'aim'}), allowed_content_types=frozenset({'image/gif', 'image/bmp', 'image/webp', 'text/plain', 'image/jpeg', 'image/png'}), attr_val_is_uri=frozenset({(None, 'src'), (None, 'action'), ('http://www.w3.org/XML/1998/namespace', 'base'), (None, 'poster'), (None, 'datasrc'), ('http://www.w3.org/1999/xlink', 'href'), (None, 'dynsrc'), (None, 'href'), (None, 'longdesc'), (None, 'lowsrc'), (None, 'ping'), (None, 'background'), (None, 'cite')}), svg_attr_val_allows_ref=frozenset({(None, 'marker-start'), (None, 'mask'), (None, 'stroke'), (None, 'filter'), (None, 'cursor'), (None, 'color-profile'), (None, 'clip-path'), (None, 'fill'), (None, 'marker-mid'), (None, 'marker'), (None, 'marker-end')}), svg_allow_local_href=frozenset({(None, 'pattern'), (None, 'use'), (None, 'textpath'), (None, 'tref'), (None, 'animateMotion'), (None, 'animateTransform'), (None, 'animate'), (None, 'filter'), (None, 'altGlyph'), (None, 'cursor'), (None, 'animateColor'), (None, 'radialGradient'), (None, 'set'), (None, 'linearGradient'), (None, 'feImage')}))

Creates a Filter

Parameters:
  • allowed_elements – set of elements to allow–everything else will be escaped
  • allowed_attributes – set of attributes to allow in elements–everything else will be stripped
  • allowed_css_properties – set of CSS properties to allow–everything else will be stripped
  • allowed_css_keywords – set of CSS keywords to allow–everything else will be stripped
  • allowed_svg_properties – set of SVG properties to allow–everything else will be removed
  • allowed_protocols – set of allowed protocols for URIs
  • allowed_content_types – set of allowed content types for data URIs.
  • attr_val_is_uri – set of attributes that have URI values–values that have a scheme not listed in allowed_protocols are removed
  • svg_attr_val_allows_ref – set of SVG attributes that can have references
  • svg_allow_local_href – set of SVG elements that can have local hrefs–these are removed

whitespace Module

class html5lib.filters.whitespace.Filter(source)

Bases: html5lib.filters.base.Filter

Collapses whitespace except in pre, textarea, and script elements