AlkantarClanX12

Your IP : 18.217.98.175


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/lxml/html/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/lxml/html/__pycache__/clean.cpython-37.pyc

B

o��] i�@s�dZddlmZddlZddlZyddlmZddlmZWn$e	k
r`ddl
mZmZYnXddlmZddl
mZdd	l
mZmZdd
l
mZmZyeWnek
r�eZYnXyeWnek
r�eZYnXyeWnek
�reefZYnXddd
ddddgZe�dejejB�Ze�dej�Ze�dej�j Z!e�dej�j Z"dd�Z#e�d�j$Z%e�dejejB�Z&e�'d�Z(ej'ddeid�Z)Gdd
�d
e*�Z+e+�Z,e,j-Z-e�dej�e�d ej�gZ.d!d"d#d$d%d&gZ/e�d'ej�e�d(ej�e�d)�gZ0d*gZ1e.e/e0e1fd+d�Z2d,d-�Z3d.d�Z4e2je4_d"d!d#gZ5d/gZ6d0e5e6ed1�fd2d�Z7d3d�Z8d4d5�Z9e�d6ej�Z:d7d8�Z;dS)9zcA cleanup tool for HTML.

Removes unwanted tags and content.  See the `Cleaner` class for
details.
�)�absolute_importN)�urlsplit)�unquote_plus)rr)�etree)�defs)�
fromstring�XHTML_NAMESPACE)�
xhtml_to_html�_transform_result�
clean_html�clean�Cleaner�autolink�
autolink_html�
word_break�word_break_htmlzexpression\s*\(.*?\)z
@\s*importz^data:image/.+;base64z<(?:javascript|jscript|livescript|vbscript|data|about|mocha):cCst|�rdSt|�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_schemeNsrz[\s\x00-\x08\x0B\x0C\x0E-\x19]+z\[if[\s\n\r]+.*?][\s\n\r]*>zdescendant-or-self::*[@style]z�descendant-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�eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdZdZdZdZejZdZdZddhZdd	�Zed
ddd
gd
d
d
dd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"d"dd�Z#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�iframe�embedcKsZx:|��D].\}}t||�s,td||f��t|||�q
W|jdkrVd|krV|j|_dS)NzUnknown parameter: %s=%r�inline_style)�items�hasattr�	TypeError�setattrr�style)�self�kw�name�valuerrr�__init__�s
zCleaner.__init__�src�href�code�object)�script�link�appletrr�layer�acCs�t|d�r|��}t|�x|�d�D]
}d|_q&W|jsD|�|�t|jpNd�}t|j	p\d�}t|j
pjd�}|jr~|�d�|j
r�t|j�}x:|�tj�D]*}|j}x|��D]}||kr�||=q�Wq�W|j�r2|j
r�|jtjk�s(x@|�tj�D]0}|j}x$|��D]}|�d��r||=�qWq�W|j|jdd�|j�s�x`t|�D]T}|�d	�}	t�d
|	�}
t�d
|
�}
|�|
��r�|jd	=n|
|	k�rJ|�d	|
��qJW|j�s2x�t |�d	��D]t}|�dd
��!��"�dk�r�|�#��q�|j$�p�d
}	t�d
|	�}
t�d
|	�}
|�|
��rd
|_$n|
|	k�r�|
|_$�q�W|j�sB|j%�rN|�tj&�|j%�rb|�tj'�|j�rt|�d	�|j�r�t�(|d	�|j)�r�|�d�nT|j�s�|j�r�xBt |�d��D]0}d|�dd
��!�k�r�|�*|��s�|�#��q�W|j+�r|�d�|j,�r|�-d�|j.�r�x\t |�d��D]J}d}|�/�}x$|dk	�r`|jdk�r`|�/�}�q>W|dk�r,|�#��q,W|�-d�|�-d�|j0�r�|�-tj1�|j2�r�|�d�|�-d�|j3�r�|�-d�g}
g}x`|��D]T}|j|k�r|�*|��r�q�|�4|�n&|j|k�r�|�*|��r*�q�|
�4|��q�W|
�rj|
d|k�rj|
�5d�}d|_|j�6�n8|�r�|d|k�r�|�5d�}|jdk�r�d|_|�6�|�7�x|D]}|�#��q�Wx|
D]}|�8��q�W|j9�r�|�r�t:d��ttj;�}|�rtg}x(|��D]}|j|k�r|�4|��qW|�rt|d|k�r\|�5d�}d|_|j�6�x|D]}|�8��qbW|j<�r�xdt=|�D]X}|�>|��s�|�d�}|�r�d|k�r�d d!|k�rq�d"|}nd}|�d|��q�WdS)#z&
        Cleans the document.
        �getrootZimageZimgrr*�onF)Zresolve_base_hrefr ��typeztext/javascriptz
/* deleted */r+Z
stylesheet�rel�meta)�head�html�title�paramN)r,r))r,)rrr-r)r8Zform)Zbutton�input�select�textarea)ZblinkZmarqueerZdivr6zIIt does not make sense to pass in both allow_tags and remove_unknown_tagsZnofollowz
 nofollow z %s z%s nofollow)?rr/r	�iter�tag�comments�kill_conditional_comments�set�	kill_tags�remove_tags�
allow_tags�scripts�add�safe_attrs_only�
safe_attrsrZElement�attrib�keys�
javascriptr�
startswithZ
rewrite_links�_remove_javascript_linkr�_find_styled_elements�get�_css_javascript_re�sub�_css_import_re�_has_sneaky_javascriptr �list�lower�strip�	drop_tree�text�processing_instructions�CommentZProcessingInstructionZstrip_attributes�links�
allow_elementr4�page_structure�update�embeddedZ	getparent�framesZ
frame_tags�forms�
annoying_tags�append�pop�clear�reverseZdrop_tag�remove_unknown_tags�
ValueErrorZtags�add_nofollow�_find_external_links�allow_follow)r!�doc�elrArBrCrGrH�aname�old�newZfound_parent�parent�_removeZ_kill�badr3rrr�__call__�s




























zCleaner.__call__cCsdS)zF
        Override to suppress rel="nofollow" on some anchors.
        Fr)r!�anchorrrrrj�szCleaner.allow_followcCs�|j|jkrdS|j|j}t|ttf�r^x.|D]&}|�|�}|sFdS|�||�s0dSq0WdS|�|�}|spdS|�||�SdS)z�
        Decide whether an element is configured to be accepted or rejected.

        :param el: an element.
        :return: true to accept the element or false to reject/discard it.
        FTN)r=�_tag_link_attrs�
isinstancerS�tuplerN�allow_embedded_url)r!rl�attrZone_attr�urlrrrr[�s


zCleaner.allow_elementcCs^|jdk	r|j|jkrdSt|�\}}}}}|���dd�d}|dkrLdS||jkrZdSdS)a
        Decide whether a URL that was found in an element's attributes or text
        if configured to be accepted or rejected.

        :param el: an element.
        :param url: a URL found on the element.
        :return: true to accept the URL and false to reject it.
        NF�:�r)�http�httpsT)�whitelist_tagsr=rrT�split�host_whitelist)r!rlrz�scheme�netloc�path�query�fragmentrrrrx�s	
zCleaner.allow_embedded_urlcCsg}|�|dd�tj�dS)z�
        IE conditional comments basically embed HTML that the parser
        doesn't normally see.  We can't allow anything like that, so
        we'll kill any comments that could be conditional.
        cSst�|j�S)N)�_conditional_comment_re�searchrW)rlrrr�<lambda>��z3Cleaner.kill_conditional_comments.<locals>.<lambda>N)�_kill_elementsrrY)r!rkrrrrrr?�sz!Cleaner.kill_conditional_commentscCsDg}x$|�|�D]}||�r|�|�qWx|D]}|��q0WdS)N)r<rbrV)r!rkZ	condition�iteraterrrlrrrr��s
zCleaner._kill_elementscCstdt|��}t|�rdS|S)Nr1)�_substitute_whitespacerr)r!r+rorrrrL�szCleaner._remove_javascript_linkz	/\*.*?\*/cCsF|�d|�}|�dd�}td|�}|��}d|kr6dSd|krBdSdS)a�
        Depending on the browser, stuff like ``e x p r e s s i o n(...)``
        can get interpreted, or ``expre/* stuff */ssion(...)``.  This
        checks for attempt to do stuff like this.

        Typically the response will be to kill the entire style; if you
        have just a bit of Javascript in the style another rule will catch
        that and remove only the Javascript from the style; this catches
        more sneaky attempts.
        r1�\zjavascript:Tzexpression(F)�_substitute_comments�replacer�rT)r!r rrrrR�s
zCleaner._has_sneaky_javascriptcCs8t|�}t|t�rt|�}n
t�|�}||�t||�S)N)r2rv�
basestringr�copy�deepcopyr
)r!r6�result_typerkrrrrs


zCleaner.clean_html)N),�__name__�
__module__�__qualname__�__doc__rDrJr>r rrZr4r\rXr^r_r`rarBrCrArfrFrrGrhr�rr%�dictrursrjr[rxr?r�rL�re�compile�SrPr�rRrrrrrr
csV]	5
zb(?P<body>https?://(?P<host>[a-z0-9._-]+)(?:/[/\-_.,a-z0-9%&?;=~]*)?(?:\([/\-_.,a-z0-9%&?;=~]*\))?)z9mailto:(?P<body>[a-z0-9._-]+@(?P<host>[a-z0-9_.-]+[a-z]))r;�prer(r5r:r.z
^localhostz\bexample\.(?:com|org|net)$z^127\.0\.0\.1$ZnolinkcCs�|j|krdS|�d�}|r>|��}x|D]}||kr*dSq*Wxht|�D]\}t|||||d�|jrHt|j|||jd�\}}	|	rH||_|�|�}
|	||
d|
d�<qHW|j	r�t|j	|||jd�\}}|r�||_	||dd�<dS)a
    Turn any URLs into links.

    It will search for links identified by the given regular
    expressions (by default mailto and http(s) links).

    It won't link text in an element in avoid_elements, or an element
    with a class in avoid_classes.  It won't link to anything with a
    host that matches one of the regular expressions in avoid_hosts
    (default localhost and 127.0.0.1).

    If you pass in an element, the element's tail will not be
    substituted, only the contents of the element.
    N�class)�link_regexes�avoid_elements�avoid_hosts�
avoid_classes)�factoryr|r)
r=rNr�rSr�tail�
_link_textZmakeelement�indexrW)rlr�r�r�r��
class_nameZmatch_class�childrWZ
tail_childrenr�Zpre_childrenrrrr/s4



cCs�d}g}d}�x�d\}}x�|D]~}	|}
xJ|	j||
d�}|dkr@P|�d�}x"|D]}
|
�|�rP|��}
PqPWPq(W|dkr|q|dks�|��|kr|}|��}qW|dkr�|r�|djr�t�||d_n|r�t�|}P|�d�}|��}|�d�s�|�d��r|d	8}|dd�}|d|���}|�rB|dj�r6t�||d_n|�rLt�|}|d
�}|�d|�|�d�}|�sx|}|�d��s�|�d��r�|dd�}||_|�	|�||d�}qW||fS)
Nr1r)NN)�pos�host����.�,r|r.r'�body)
r��group�end�startr��AssertionError�endswithr@rWrb)rWr�r�r�Zleading_textrZZlast_pos�
best_matchZbest_posZregexZ	regex_pos�matchr�Z
host_regexr+r�Z	prev_textrtr�rrrr�\sf







r�cOs@t|�}t|t�rt|�}n
t�|�}t|f|�|�t||�S)N)r2rvr�rr�r�rr
)r6�argsr"r�rkrrrr�s


Znobreak�(i c	Cs�|jtkrdS|�d�}|rLd}|��}x|D]}||kr.d}Pq.W|rLdS|jrbt|j||�|_x4|D],}t|||||d�|jrht|j||�|_qhWdS)a�
    Breaks any long words found in the body of the text (not attributes).

    Doesn't effect any of the tags in avoid_elements, by default
    ``<textarea>`` and ``<pre>``

    Breaks words by inserting &#8203;, which is a unicode character
    for Zero Width Space character.  This generally takes up no space
    in rendering, but does copy as a space, and in monospace contexts
    usually takes up space.

    See http://www.cs.tut.fi/~jkorpela/html/nobr.html for a discussion
    Nr�FT)�	max_widthr�r��break_character)r=�_avoid_word_break_elementsrNr�rW�_break_textrr�)	rlr�r�r�r�r�Z
dont_breakZavoidr�rrrr�s*



cOs*t|�}t|�}t|f|�|�t||�S)N)r2rrr
)r6r�r"r�rkrrrr�scCs>|��}x0|D](}t|�|krt|||�}|�||�}qW|S)N)r��len�
_insert_breakr�)rWr�r��words�word�replacementrrrr��s
r�z[^a-z]cCs�|}d}xrt|�|krz|d|�}tt�|��}|r\|d}|��|dkr\|d|���}|||7}|t|�d�}q
W||7}|S)Nr1r��
)r�rS�_break_prefer_re�finditerr�)r��widthr�Z	orig_word�resultr�ZbreaksZ
last_breakrrrr��sr�)<r��
__future__rr�r��urlparser�urllibr�ImportError�urllib.parse�lxmlrZ	lxml.htmlrrrr	r
�unichr�	NameError�chr�unicode�strr��bytes�__all__r�r��IrOrQr�rrrrPr�r�ZXPathrMrir)r
rrZ
_link_regexesZ_avoid_elementsZ_avoid_hostsZ_avoid_classesrr�rr�Z_avoid_word_break_classesrrr�r�r�rrrr�<module>s�




8*:	
&