o
    h!                     @   s   d Z ddlZddlmZmZmZmZ ddlmZ g dZ	e
dZdd Zd	d
 Zei Zi dededeidededededededededededededeeddddded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|r6|d
dd }|tvr6d 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)
url_string	unescapedprotocol r   Q/var/www/html/ndineBlogger/venv/lib/python3.10/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 ]%\}} |}|r)t|r'||}|d u r"| |= q|| |< q	 q| |= 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.   z
[document]ahrefbbrdivemh1h2h3h4h5h6hriimgT)srcwidthheightaltliol)pstrongr   sup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   sD   t |tr| || dS t |tr| || dS | || dS )z'Clean a BeautifulSoup document in-placeN)
isinstancer   clean_string_noder   clean_tag_nodeclean_unknown_noderL   rN   noder   r   r   rJ   p   s
   

zWhitelister.clean_nodec                 C   s   t |tr|  d S d S r    )rP   r   extractrT   r   r   r   rQ   |   s   
zWhitelister.clean_string_nodec                 C   sV   t |jD ]}| || qz| j|j }W n ty$   |  Y d S w || d S r    )r!   contentsrJ   element_rulesnameKeyErrorunwrap)rL   rN   r&   childr)   r   r   r   rR      s   zWhitelister.clean_tag_nodec                 C   s   |   d S r    )	decomposerT   r   r   r   rS      s   zWhitelister.clean_unknown_nodeN)
__name__
__module____qualname__DEFAULT_ELEMENT_RULESrX   rO   rJ   rQ   rR   rS   r   r   r   r   rH   `   s    	rH   )__doc__r   bs4r   r   r   r   django.utils.htmlr   r   compiler   r   r.   allow_without_attributesra   rH   r   r   r   r   <module>   sj    
 	
