o
    Zh
                     @  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ZdddZedZedZddddZdS )    )annotations)Callable)suppressN)quoteunquoteurlparse
urlunparse   )	_punycode)zhttp:zhttps:zmailto:urlstrreturnc                 C  sp   t j| dd}|jr0|jr|jtv r0tt |jt	|jd}W d   n1 s+w   Y  t 
t |S )zvNormalize destination URLs in links

    ::

        [label]:   destination   'title'
                ^^^^^^^^^^^
    TZslashes_denote_hosthostnameN)mdurlparser   protocolRECODE_HOSTNAME_FORr   	Exception_replacer
   Zto_asciiencodeformatr   parsed r   W/var/www/html/lang_env/lib/python3.10/site-packages/markdown_it/common/normalize_url.pynormalizeLink   s   

r   c                 C  sx   t j| dd}|jr0|jr|jtv r0tt |jt	|jd}W d   n1 s+w   Y  t 
t |t jd S )zSNormalize autolink content

    ::

        <destination>
         ~~~~~~~~~~~
    Tr   r   N%)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);	validatorCallable[[str], bool] | Noneboolc                 C  s8   |dur|| S |    } t| rt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)   )r   r   r   r   )N)r   r   r!   r"   r   r#   )
__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    



