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