Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/galaxy/util/sanitize_html.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author | shellac |
---|---|
date | Thu, 14 May 2020 14:56:58 -0400 |
parents | 26e78fe6e8c4 |
children |
comparison
equal
deleted
inserted
replaced
1:75ca89e9b81c | 2:6af9afd405e9 |
---|---|
1 """ | |
2 HTML Sanitizer (lists of acceptable_* ripped from feedparser) | |
3 """ | |
4 import bleach | |
5 | |
6 _acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area', 'article', | |
7 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button', 'canvas', | |
8 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', | |
9 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', | |
10 'div', 'dl', 'dt', 'em', 'event-source', 'fieldset', 'figure', | |
11 'footer', 'font', 'form', 'header', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | |
12 'hr', 'i', 'img', 'input', 'ins', 'keygen', 'kbd', 'label', 'legend', | |
13 'li', 'm', 'map', 'menu', 'meter', 'multicol', 'nav', 'nextid', 'ol', | |
14 'output', 'optgroup', 'option', 'p', 'pre', 'progress', 'q', 's', | |
15 'samp', 'section', 'select', 'small', 'sound', 'source', 'spacer', | |
16 'span', 'strike', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', | |
17 'textarea', 'time', 'tfoot', 'th', 'thead', 'tr', 'tt', 'u', 'ul', | |
18 'var', 'video', 'noscript'] | |
19 | |
20 _acceptable_attributes = ['abbr', 'accept', 'accept-charset', 'accesskey', | |
21 'action', 'align', 'alt', 'autocomplete', 'autofocus', 'axis', | |
22 'background', 'balance', 'bgcolor', 'bgproperties', 'border', | |
23 'bordercolor', 'bordercolordark', 'bordercolorlight', 'bottompadding', | |
24 'cellpadding', 'cellspacing', 'ch', 'challenge', 'char', 'charoff', | |
25 'choff', 'charset', 'checked', 'cite', 'class', 'clear', 'color', | |
26 'cols', 'colspan', 'compact', 'contenteditable', 'controls', 'coords', | |
27 'data', 'datafld', 'datapagesize', 'datasrc', 'datetime', 'default', | |
28 'delay', 'dir', 'disabled', 'draggable', 'dynsrc', 'enctype', 'end', | |
29 'face', 'for', 'form', 'frame', 'galleryimg', 'gutter', 'headers', | |
30 'height', 'hidefocus', 'hidden', 'high', 'href', 'hreflang', 'hspace', | |
31 'icon', 'id', 'inputmode', 'ismap', 'keytype', 'label', 'leftspacing', | |
32 'lang', 'list', 'longdesc', 'loop', 'loopcount', 'loopend', | |
33 'loopstart', 'low', 'lowsrc', 'max', 'maxlength', 'media', 'method', | |
34 'min', 'multiple', 'name', 'nohref', 'noshade', 'nowrap', 'open', | |
35 'optimum', 'pattern', 'ping', 'point-size', 'prompt', 'pqg', | |
36 'radiogroup', 'readonly', 'rel', 'repeat-max', 'repeat-min', 'replace', | |
37 'required', 'rev', 'rightspacing', 'rows', 'rowspan', 'rules', 'scope', | |
38 'selected', 'shape', 'size', 'span', 'src', 'start', 'step', 'summary', | |
39 'suppress', 'tabindex', 'target', 'template', 'title', 'toppadding', | |
40 'type', 'unselectable', 'usemap', 'urn', 'valign', 'value', 'variable', | |
41 'volume', 'vspace', 'vrml', 'width', 'wrap', 'xml:lang'] | |
42 | |
43 | |
44 def sanitize_html(htmlSource, allow_data_urls=False): | |
45 kwd = dict(tags=_acceptable_elements, attributes=_acceptable_attributes, strip=True) | |
46 if allow_data_urls: | |
47 kwd["protocols"] = bleach.ALLOWED_PROTOCOLS + ["data"] | |
48 return bleach.clean(htmlSource, **kwd) |