a
    �˜ëj
  ã                   @  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  sp   t j| dd�}|jr`|jr$|jtv r`ttƒ�$ |jt 	|j¡d�}W d  ƒ n1 sV0    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   ú_/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/markdown_it/common/normalize_url.pyÚnormalizeLink   s    ÿÿ
2r   c                 C  sx   t j| dd�}|jr`|jr$|jtv r`ttƒ�$ |jt 	|j¡d�}W d  ƒ n1 sV0    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    ÿÿ
2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u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   

