filters Package

base Module

alphabeticalattributes Module

class html5lib.filters.alphabeticalattributes.Filter(source)[source]

Bases: html5lib.filters.base.Filter

Alphabetizes attributes for elements

inject_meta_charset Module

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

Bases: html5lib.filters.base.Filter

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

__init__(source, encoding)[source]

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)[source]

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)[source]

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)[source]

Bases: html5lib.filters.base.Filter

Removes optional tags from the token stream

sanitizer Module

Deprecated from html5lib 1.1.

See here for information about its deprecation; Bleach is recommended as a replacement. Please let us know in the aforementioned issue if Bleach is unsuitable for your needs.

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

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

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)[source]

Bases: html5lib.filters.base.Filter

Collapses whitespace except in pre, textarea, and script elements