B
o] i @ s d Z ddlmZ ddlZddlZyddlmZ ddlmZ W n$ e k
r` ddl
mZmZ Y nX ddlmZ ddl
mZ dd l
mZmZ dd
l
mZmZ ye W n ek
r eZY nX ye W n ek
r eZY nX ye W n ek
r eefZY nX ddd
ddddgZedejejB ZedejZedejj Z!edejj Z"dd Z#edj$Z%edejejB Z&e'dZ(ej'ddeidZ)G dd
d
e*Z+e+ Z,e,j-Z-edejed ejgZ.d!d"d#d$d%d&gZ/ed'ejed(ejed)gZ0d*gZ1e.e/e0e1fd+dZ2d,d- Z3d.d Z4e2j e4_ d"d!d#gZ5d/gZ6d0e5e6ed1fd2dZ7d3d Z8d4d5 Z9ed6ejZ:d7d8 Z;dS )9zcA cleanup tool for HTML.
Removes unwanted tags and content. See the `Cleaner` class for
details.
)absolute_importN)urlsplit)unquote_plus)r r )etree)defs)
fromstringXHTML_NAMESPACE)
xhtml_to_html_transform_result
clean_htmlcleanCleanerautolink
autolink_html
word_breakword_break_htmlzexpression\s*\(.*?\)z
@\s*importz^data:image/.+;base64z<(?:javascript|jscript|livescript|vbscript|data|about|mocha):c C s t | rd S t| S )N)_is_image_dataurl_is_possibly_malicious_scheme)s r B/opt/alt/python37/lib64/python3.7/site-packages/lxml/html/clean.py_is_javascript_schemeN s r z[\s\x00-\x08\x0B\x0C\x0E-\x19]+z\[if[\s\n\r]+.*?][\s\n\r]*>zdescendant-or-self::*[@style]zdescendant-or-self::a [normalize-space(@href) and substring(normalize-space(@href),1,1) != '#'] |descendant-or-self::x:a[normalize-space(@href) and substring(normalize-space(@href),1,1) != '#']x)Z
namespacesc @ s e Zd ZdZdZdZdZdZdZdZ dZ
dZdZdZ
dZdZdZdZdZdZdZdZejZdZdZddhZdd Zed
ddd
gd
d
d
ddZdd Zdd Zdd Z dd Z!dd Z"d"ddZ#dd Z$e%&de%j'j(Z)dd Z*d d! Z+dS )#r
a
Instances cleans the document of each of the possible offending
elements. The cleaning is controlled by attributes; you can
override attributes in a subclass, or set them in the constructor.
``scripts``:
Removes any ``<script>`` tags.
``javascript``:
Removes any Javascript, like an ``onclick`` attribute. Also removes stylesheets
as they could contain Javascript.
``comments``:
Removes any comments.
``style``:
Removes any style tags.
``inline_style``
Removes any style attributes. Defaults to the value of the ``style`` option.
``links``:
Removes any ``<link>`` tags
``meta``:
Removes any ``<meta>`` tags
``page_structure``:
Structural parts of a page: ``<head>``, ``<html>``, ``<title>``.
``processing_instructions``:
Removes any processing instructions.
``embedded``:
Removes any embedded objects (flash, iframes)
``frames``:
Removes any frame-related tags
``forms``:
Removes any form tags
``annoying_tags``:
Tags that aren't *wrong*, but are annoying. ``<blink>`` and ``<marquee>``
``remove_tags``:
A list of tags to remove. Only the tags will be removed,
their content will get pulled up into the parent tag.
``kill_tags``:
A list of tags to kill. Killing also removes the tag's content,
i.e. the whole subtree, not just the tag itself.
``allow_tags``:
A list of tags to include (default include all).
``remove_unknown_tags``:
Remove any tags that aren't standard parts of HTML.
``safe_attrs_only``:
If true, only include 'safe' attributes (specifically the list
from the feedparser HTML sanitisation web site).
``safe_attrs``:
A set of attribute names to override the default list of attributes
considered 'safe' (when safe_attrs_only=True).
``add_nofollow``:
If true, then any <a> tags will have ``rel="nofollow"`` added to them.
``host_whitelist``:
A list or set of hosts that you can use for embedded content
(for content like ``<object>``, ``<link rel="stylesheet">``, etc).
You can also implement/override the method
``allow_embedded_url(el, url)`` or ``allow_element(el)`` to
implement more complex rules for what can be embedded.
Anything that passes this test will be shown, regardless of
the value of (for instance) ``embedded``.
Note that this parameter might not work as intended if you do not
make the links absolute before doing the cleaning.
Note that you may also need to set ``whitelist_tags``.
``whitelist_tags``:
A set of tags that can be included with ``host_whitelist``.
The default is ``iframe`` and ``embed``; you may wish to
include other tags like ``script``, or you may want to
implement ``allow_embedded_url`` for more control. Set to None to
include all tags.
This modifies the document *in place*.
TFNr iframeembedc K sZ x:| D ].\}}t| |s,td||f t| || q
W | jd krVd|krV| j| _d S )NzUnknown parameter: %s=%rinline_style)itemshasattr TypeErrorsetattrr style)selfkwnamevaluer r r __init__ s
zCleaner.__init__srchrefcodeobject)scriptlinkappletr r layerac C s t |dr| }t| x|dD ]
}d|_q&W | jsD| | t| jpNd}t| j p\d}t| j
pjd}| jr~|d | j
rt| j}x:|tjD ]*}|j}x| D ]}||kr||= qW qW | jr2| j
r| jtjks(x@|tjD ]0}|j}x$| D ]}|dr||= qW qW |j| jdd | jsx`t|D ]T}|d } td
| }
td
|
}
| |
r|jd = n|
| krJ|d |
qJW | js2xt |d D ]t}|dd
! "