U
    Sh
                     @  s   d dl mZ d dlmZ d dlmZ d dlZd dlmZm	Z	m
Z
mZ d dlZddlmZ dZd	d	d
ddZd	d	d
ddZedZedZdd	dddddZdS )    )annotations)Callable)suppressN)quoteunquoteurlparse
urlunparse   )	_punycode)zhttp:zhttps:zmailto:str)urlreturnc              	   C  s\   t j| dd}|jrL|jr$|jtkrLtt |jt	|jd}W 5 Q R X t 
t |S )zvNormalize destination URLs in links

    ::

        [label]:   destination   'title'
                ^^^^^^^^^^^
    TZslashes_denote_hosthostname)mdurlparser   protocolRECODE_HOSTNAME_FORr   	Exception_replacer
   Zto_asciiencodeformatr   parsed r   S/root/rtd-docs/venv/lib/python3.8/site-packages/markdown_it/common/normalize_url.pynormalizeLink   s    
r   c              	   C  sd   t j| dd}|jrL|jr$|jtkrLtt |jt	|jd}W 5 Q R X t 
t |t jd S )zSNormalize autolink content

    ::

        <destination>
         ~~~~~~~~~~~
    Tr   r   %)r   r   r   r   r   r   r   r   r
   Z
to_unicodedecoder   ZDECODE_DEFAULT_CHARSr   r   r   r   normalizeLinkText(   s    
r    z!^(vbscript|javascript|file|data):z!^data:image\/(gif|png|jpeg|webp);zCallable[[str], bool] | Nonebool)r   	validatorr   c                 C  s8   |dk	r|| S |    } t| r4tt| S dS )a  Validate URL link is allowed in output.

    This validator can prohibit more than really needed to prevent XSS.
    It's a tradeoff to keep code simple and to be secure by default.

    Note: url should be normalized at this point, and existing entities decoded.
    NT)striplowerBAD_PROTO_REsearchr!   GOOD_DATA_RE)r   r"   r   r   r   validateLinkF   s    r(   )N)
__future__r   collections.abcr   
contextlibr   reurllib.parser   r   r   r   r    r
   r   r   r    compiler%   r'   r(   r   r   r   r   <module>   s   

