U
    {h!                     @   s   d Z ddlZddlmZmZmZmZ ddlmZ ddddd	gZ	e
d
Zdd Zdd Zei ZeedeieeeeeeeeeeeeeeddddeeeeeeedZG dd dZdS )ze
A generic HTML whitelisting engine, designed to accommodate subclassing to override
specific rules.
    N)BeautifulSoupCommentNavigableStringTag)escapehttphttpsftpmailtotelz^[a-z0-9][-+.a-z0-9]*:c                 C   sp   |   }|dd}|dd}|dd}tdd|}|d	d}t|rl|d
dd }|tkrld S | S )Nz&lt;<z&gt;>z&amp;&z[`\000-\040\177-\240\s]+ u   �:   r   )lowerreplaceresubPROTOCOL_REmatchsplitALLOWED_URL_SCHEMES)Z
url_stringZ	unescapedprotocol r   Y/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/whitelist.py	check_url   s    
r   c                    s    fdd}|S )af  
    Generator for functions that can be used as entries in Whitelister.element_rules.
    These functions accept a tag, and modify its attributes by looking each attribute
    up in the 'allowed_attrs' dict defined here:
    * if the lookup fails, drop the attribute
    * if the lookup returns a callable, replace the attribute with the result of calling
      it - for example `{'title': uppercase}` will replace 'title' with the result of
      uppercasing the title. If the callable returns None, the attribute is dropped.
    * if the lookup returns a truthy value, keep the attribute; if falsy, drop it
    c                    s\   t | j D ]H\}} |}|rPt|rV||}|d krD| |= qN|| |< qVq| |= qd S N)listattrsitemsgetcallable)tagattrvalrulenew_valallowed_attrsr   r   fn-   s    

zattribute_rule.<locals>.fnr   )r*   r+   r   r)   r   attribute_rule!   s    r,   hrefT)srcwidthheightZalt)z
[document]abbrdivZemZh1Zh2Zh3Zh4Zh5Zh6hriZimgZliolpstrongr   supZulc                   @   s8   e Zd ZeZdd Zdd Zdd Zdd Zd	d
 Z	dS )Whitelisterc                 C   s"   t |d}| || |jtdS )zQClean up an HTML string to contain just the allowed elements /
        attributeszhtml.parser)	formatter)r   
clean_nodedecoder   )selfhtmldocr   r   r   cleanc   s    
zWhitelister.cleanc                 C   s@   t |tr| || n$t |tr0| || n| || dS )z'Clean a BeautifulSoup document in-placeN)
isinstancer   clean_string_noder   clean_tag_nodeclean_unknown_noder?   rA   noder   r   r   r=   p   s
    

zWhitelister.clean_nodec                 C   s   t |tr|  d S d S r   )rC   r   extractrG   r   r   r   rD   |   s    
zWhitelister.clean_string_nodec                 C   sX   t |jD ]}| || q
z| j|j }W n tk
rJ   |  Y d S X || d S r   )r   contentsr=   element_rulesnameKeyErrorunwrap)r?   rA   r$   childr'   r   r   r   rE      s    zWhitelister.clean_tag_nodec                 C   s   |   d S r   )Z	decomposerG   r   r   r   rF      s    zWhitelister.clean_unknown_nodeN)
__name__
__module____qualname__DEFAULT_ELEMENT_RULESrK   rB   r=   rD   rE   rF   r   r   r   r   r;   `   s   	r;   )__doc__r   Zbs4r   r   r   r   Zdjango.utils.htmlr   r   compiler   r   r,   Zallow_without_attributesrS   r;   r   r   r   r   <module>   sD   
 
