ó
§]c           @   sz   d  Z  d d l m Z 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 e f d     YZ d S(	   sD   
NBConvert Preprocessor for sanitizing HTML rendering of notebooks.
i˙˙˙˙(   t   ALLOWED_ATTRIBUTESt   ALLOWED_STYLESt   ALLOWED_TAGSt   clean(   t   Anyt   Boolt   Listt   Sett   Unicodei   (   t   Preprocessort   SanitizeHTMLc        
   B   s  e  Z e d  e d e d d  Z e e   d  e d e d d Z	 e e   d  e d e
 d d Z e d  e d e d d  Z e d  e d e d d  Z e d  e d d d	 d
 d d d h d d  Z e d  e d d d h d d  Z d   Z d   Z d   Z RS(   t   configt   default_valuet   helps   Allowed HTML tag attributess   List of HTML tags to allows0   Allowed CSS styles if <style> tag is whitelisteds:   If True, remove unsafe markup entirely instead of escapings)   If True, strip comments from escaped HTMLt   metadatas
   text/plains
   text/latexs   application/jsons	   image/pngs
   image/jpegs4   Cell output mimetypes to render without modifications	   text/htmls   text/markdowns8   Cell output types to display after escaping with Bleach.c         C   s   | j  d k r. |  j | j  | _ | | f S| j  d k r\ |  j | j  | _ | | f S| j  d k r |  j | j  | _ | | f Sd S(   s  
        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
        t   rawt   markdownt   codeN(   t	   cell_typet   sanitize_html_tagst   sourcet   sanitize_code_outputst   outputs(   t   selft   cellt	   resourcest
   cell_index(    (    s?   lib/python2.7/site-packages/nbconvert/preprocessors/sanitize.pyt   preprocess_cellJ   s    

c         C   sÖ   xÏ | D]Ç } | d d k r# q n  | j  } g  } xm | D]e } | |  j k rT q9 q9 | |  j k r |  j j d |  |  j | |  | | <q9 | j |  q9 Wx) | D]! } |  j j d |  | | =qİ Wq W| S(   sŞ   
        Sanitize code cell outputs.

        Removes 'text/javascript' fields from display_data outputs, and
        runs `sanitize_html_tags` over 'text/html'.
        t   output_typet   streamt   errors   Sanitizing %ss   Removing %s(   R   R   (   t   datat   safe_output_keyst   sanitized_output_typest   logt   infoR   t   append(   R   R   t   outputR   t	   to_removet   key(    (    s?   lib/python2.7/site-packages/nbconvert/preprocessors/sanitize.pyR   c   s     	c         C   s7   t  | d |  j d |  j d |  j d |  j d |  j S(   s=   
        Sanitize a string containing raw HTML tags.
        t   tagst
   attributest   stylest   stript   strip_comments(   R   R(   R)   R*   R+   R,   (   R   t   html_str(    (    s?   lib/python2.7/site-packages/nbconvert/preprocessors/sanitize.pyR      s    				(   t   __name__t
   __module__R   t   TrueR    R)   R   R   R   R(   R   R*   R   t   FalseR+   R,   R   R    R!   R   R   R   (    (    (    s?   lib/python2.7/site-packages/nbconvert/preprocessors/sanitize.pyR
      sN   													N(   t   __doc__t   bleachR    R   R   R   t	   traitletsR   R   R   R   R   t   baseR	   R
   (    (    (    s?   lib/python2.7/site-packages/nbconvert/preprocessors/sanitize.pyt   <module>   s   "(