o
    iW                     @   s   d Z ddlZddlmZmZmZ ddlmZmZm	Z	m
Z
mZ ddlmZ dZdZzddlmZ dd	lmZ d
ZdZW n/ eyi   zddlmZ dZd
Zejdedd W n eyf   ejdedd Y nw Y nw dgZG dd deZdd ZdS )zD
NBConvert Preprocessor for sanitizing HTML rendering of notebooks.
    N)ALLOWED_ATTRIBUTESALLOWED_TAGSclean)AnyBoolListSetUnicode   )PreprocessorF)ALLOWED_CSS_PROPERTIES)CSSSanitizerT)ALLOWED_STYLESzFSupport for bleach <5 will be removed in a future version of nbconvert   )
stacklevelz[The installed bleach/tinycss2 do not provide CSS sanitization, please upgrade to bleach >=5SanitizeHTMLc                   @   s   e Zd ZdZededdZee de	ddZ
ee deddZeddddZeddd	dZedh d
ddZedddhddZdd Zdd Zdd ZdS )r   z A preprocessor to sanitize html.TzAllowed HTML tag attributes)configdefault_valuehelpzList of HTML tags to allowz,Allowed CSS styles if <style> tag is allowedFz:If True, remove unsafe markup entirely instead of escapingz)If True, strip comments from escaped HTML>   	image/png
image/jpeg
text/latex
text/plainapplication/jsonmetadataz4Cell output mimetypes to render without modificationz	text/htmlztext/markdownz8Cell output types to display after escaping with Bleach.c                 C   sd   |j dkr| |j|_||fS |j dkr | |j|_||fS |j dkr0| |j|_||fS dS )a  
        Sanitize potentially-dangerous contents of the cell.

        Cell Types:
          raw:
            Sanitize literal HTML
          markdown:
            Sanitize literal HTML
          code:
            Sanitize outputs that could result in code execution
        rawmarkdowncodeN)	cell_typesanitize_html_tagssourcesanitize_code_outputsoutputs)selfcell	resources
cell_index r'   [/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbconvert/preprocessors/sanitize.pypreprocess_cellf   s   


zSanitizeHTML.preprocess_cellc                 C   s   |D ]C}|d dv rq|j }g }|D ]#}|| jv rq|| jv r0| jd| | || ||< q|| q|D ]}| jd| ||= q8q|S )z
        Sanitize code cell outputs.

        Removes 'text/javascript' fields from display_data outputs, and
        runs `sanitize_html_tags` over 'text/html'.
        output_type)streamerrorzSanitizing %szRemoving %s)datasafe_output_keyssanitized_output_typesloginfor   append)r#   r"   outputr-   	to_removekeyr'   r'   r(   r!      s"   

z"SanitizeHTML.sanitize_code_outputsc                 C   sV   | j | j| j| jd}trt| jd}|j|d n	tr#|j| jd t	|fi |S )z=
        Sanitize a string containing raw HTML tags.
        )tags
attributesstripstrip_commentsallowed_css_properties)css_sanitizer)styles)
r6   r7   r8   r9   _USE_BLEACH_CSS_SANITIZERr   r=   update_USE_BLEACH_STYLESr   )r#   html_strkwargsr<   r'   r'   r(   r      s   zSanitizeHTML.sanitize_html_tagsN)__name__
__module____qualname____doc__r   r   r7   r   r	   r   r6   r   r=   r   r8   r9   r   r.   r/   r)   r!   r   r'   r'   r'   r(   r   0   sX    	c                   C   s   t rttdS d S )Nr:   )r>   r   r   r'   r'   r'   r(   _get_default_css_sanitizer   s   
rG   )rF   warningsbleachr   r   r   	traitletsr   r   r   r   r	   baser   r>   r@   bleach.css_sanitizerr   r   r   ImportErrorwarnDeprecationWarningUserWarning__all__r   rG   r'   r'   r'   r(   <module>   sF    

 