
    b                     "   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ZdZ	 ddlmZ ddlmZ dZdZddlmZ dgZ G d de      Zy# e$ r@ 	 dd	lmZ dZdZ ej&                  d
e       n# e$ r  ej&                  de       Y nw xY wY Yw xY w)zD
NBConvert Preprocessor for sanitizing HTML rendering of notebooks.
    N)ALLOWED_ATTRIBUTESALLOWED_TAGSclean)AnyBoolListSetUnicodeF)ALLOWED_CSS_PROPERTIES)CSSSanitizerT)ALLOWED_STYLESzFSupport for bleach <5 will be removed in a future version of nbconvertz[The installed bleach/tinycss2 do not provide CSS sanitization, please upgrade to bleach >=5   )PreprocessorSanitizeHTMLc                       e Zd Z eded      Z e e       ded      Z	 e e       de
d      Z eddd      Z eddd      Z edh d	d
      Z edddhd      Zd Zd Zd Zy)r   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                 6   |j                   dk(  r$| j                  |j                        |_        ||fS |j                   dk(  r$| j                  |j                        |_        ||fS |j                   dk(  r$| j                  |j                        |_        ||fS y)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_indexs       B/usr/lib/python3/dist-packages/nbconvert/preprocessors/sanitize.pypreprocess_cellzSanitizeHTML.preprocess_cellc   s     >>U" 11$++>DK?"^^z)11$++>DK?"^^v%55dllCDL?" &    c                 f   |D ]  }|d   dv r|j                   }g }|D ]f  }|| j                  v r|| j                  v r6| j                  j	                  d|z         | j                  ||         ||<   V|j                  |       h |D ]#  }| j                  j	                  d|z         ||= %  |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keys         r(   r"   z"SanitizeHTML.sanitize_code_outputs|   s      	Fm$(;;;;DI 	*$///D777HHMM/C"78 $ 7 7S	 BDI $$S)	* ! mc12I!	& r*   c                 *   t        | j                  | j                  | j                  | j                        }t
        r)t        | j                        }|j                  |       n"t        r|j                  | j                         t        |fi |S )z=
        Sanitize a string containing raw HTML tags.
        )tags
attributesstripstrip_comments)allowed_css_properties)css_sanitizer)styles)dictr9   r:   r;   r<   _USE_BLEACH_CSS_SANITIZERr   r?   update_USE_BLEACH_STYLESr   )r$   html_strkwargsr>   s       r(   r    zSanitizeHTML.sanitize_html_tags   sr     **..	
 %(LMMMM6MMM-X(((r*   N)__name__
__module____qualname__r   r   r:   r   r
   r   r9   r   r?   r   r;   r<   r	   r0   r1   r)   r"   r     r*   r(   r   r   .   s     (*J
 	")	D 	$;	F IE
 8N 
 D !
 H#28)r*   )__doc__warningsbleachr   r   r   	traitletsr   r   r   r	   r
   rA   rC   bleach.css_sanitizerr   r   r   ImportErrorwarnDeprecationWarningUserWarningbaser   __all__r   rI   r*   r(   <module>rU      s     : : 3 3!  
M1 $* 
{)< {)3  

)$)!!T	

  
+	


s5   A	 	BA-,B-BBBBB