ó
ù2¢\c           @   s1  d  d l  Z  d  d l Z d  d l Z d  d l m Z d  d l Z d  d l Z d  d l m	 Z	 d  d l
 m Z m Z d  d l m Z d  d l m Z m Z m Z m Z d  d l m Z y d  d l m Z Wn! e k
 rë d  d	 l m Z n Xd
 e f d „  ƒ  YZ e d ƒ j d ƒ Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   join(   t   url_path_join(   t   NotebookTestBaset   assert_http_error(   t   write(   t   new_notebookt   new_markdown_cellt   new_code_cellt
   new_output(   t   onlyif_cmds_exist(   t   encodebytes(   t   encodestringt   NbconvertAPIc           B   sD   e  Z d  Z d „  Z d d d „ Z e d „ Z d „  Z d „  Z	 RS(   s    Wrapper for nbconvert API calls.c         C   s   | |  _  d  S(   N(   t   request(   t   selfR   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   __init__   s    c         C   s5   |  j  | t d | ƒ d | d | ƒ} | j ƒ  | S(   Nt	   nbconvertt   datat   params(   R   R   t   raise_for_status(   R   t   verbt   patht   bodyR   t   response(    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   _req    s
    	
c         C   s)   |  j  d t | | | ƒ d i | d 6ƒS(   Nt   GETR   t   download(   R   R   (   R   t   formatR   t   nameR   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt	   from_file(   s    c         C   s"   t  j | ƒ } |  j d | | ƒ S(   Nt   POST(   t   jsont   dumpsR   (   R   R   t   nbmodelR   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt	   from_post,   s    c         C   s   |  j  d d ƒ S(   NR   t    (   R   (   R   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   list_formats0   s    N(
   t   __name__t
   __module__t   __doc__R   t   NoneR   t   FalseR   R"   R$   (    (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyR      s   		sG   ‰PNG

   IHDR     x00   wSÞ   IDAT×cûÏ  \.~d‡    IEND®B`‚t   asciit   APITestc           B   s   e  Z d  „  Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z	 RS(   c      	      s:  |  j  } t j j t | d ƒ ƒ s[ t | d ƒ ‰  t j ˆ  ƒ |  j ‡  f d †  ƒ } n  t ƒ  } | j j	 t
 d ƒ ƒ t d d ƒ } | j j	 t d d d d	 ƒ ƒ | j j	 t d d
 d i t d 6d d ƒ ƒ | j j	 | ƒ t j t | d d ƒ d d d ƒ } t | | d d ƒWd  QXt |  j ƒ |  _ d  S(   Nt   fooc              s   t  j ˆ  d t ƒd  S(   Nt   ignore_errors(   t   shutilt   rmtreet   True(    (   t   subdir(    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   cleanup_dirD   s    u   Created by test Â³t   sourceu
   print(2*6)t   output_typet   streamt   textu   12t   execute_resultR   s	   image/pngt   execution_counti   s   testnb.ipynbt   wt   encodings   utf-8t   versioni   (   t   notebook_dirt   osR   t   isdirt   pjoint   mkdirt
   addCleanupR   t   cellst   appendR   R   t   outputsR   t   png_green_pixelt   iot   openR   R   R   t   nbconvert_api(   R   t   nbdirR2   t   nbt   cc1t   f(    (   R1   sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   setUp9   s"    		
t   pandocc         C   s®   |  j  j d d d ƒ } |  j | j d ƒ |  j d | j d ƒ |  j d | j ƒ |  j d | j ƒ |  j  j d	 d d ƒ } |  j d
 | j d ƒ |  j d | j ƒ d  S(   Nt   htmlR,   s   testnb.ipynbiÈ   u	   text/htmls   Content-Typeu   Created by testu   printt   pythonu   text/x-pythonu
   print(2*6)(   RH   R   t   assertEqualt   status_codet   assertInt   headersR6   (   R   t   r(    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   test_from_fileY   s    c         C   s-   t  d ƒ  |  j j d d d ƒ Wd  QXd  S(   Ni”  RO   R,   s   thisdoesntexist.ipynb(   R   RH   R   (   R   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   test_from_file_404e   s    c         C   sO   |  j  j d d d d t ƒ} | j d } |  j d | ƒ |  j d | ƒ d  S(   NRP   R,   s   testnb.ipynbR   s   Content-Dispositiont
   attachments	   testnb.py(   RH   R   R0   RT   RS   (   R   RU   t   content_disposition(    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   test_from_file_downloadj   s    c         C   sP   |  j  j d d d d t ƒ} |  j d | j d ƒ |  j d | j d ƒ d  S(	   Nt   latexR,   s   testnb.ipynbR   u   application/zips   Content-Typeu   .zips   Content-Disposition(   RH   R   R0   RS   RT   (   R   RU   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   test_from_file_zipq   s    c         C   sÌ   |  j  d d ƒ j ƒ  } |  j j d d d | ƒ } |  j | j d ƒ |  j d | j d ƒ |  j d	 | j ƒ |  j d
 | j ƒ |  j j d d d | ƒ } |  j d | j d ƒ |  j d | j ƒ d  S(   NR   s   api/contents/foo/testnb.ipynbR   RO   R!   iÈ   u	   text/htmls   Content-Typeu   Created by testu   printRP   u   text/x-pythonu
   print(2*6)(	   R   R   RH   R"   RQ   RR   RS   RT   R6   (   R   R!   RU   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   test_from_postw   s    c         C   se   |  j  d d ƒ j ƒ  } |  j j d d d | ƒ } |  j d | j d ƒ |  j d | j d	 ƒ d  S(
   NR   s   api/contents/foo/testnb.ipynbR   R[   R!   u   application/zips   Content-Typeu   .zips   Content-Disposition(   R   R   RH   R"   RS   RT   (   R   R!   RU   (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   test_from_post_zip…   s    (
   R%   R&   RM   R	   RV   RW   RZ   R\   R]   R^   (    (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyR+   8   s   	 (   RF   R   R=   t   os.pathR    R?   R.   t   requestst   notebook.utilsR   t   notebook.tests.launchnotebookR   R   t   nbformatR   t   nbformat.v4R   R   R   R   t#   ipython_genutils.testing.decoratorsR	   t   base64R
   t   ImportErrorR   t   objectR   t   decodeRE   R+   (    (    (    sO   lib/python2.7/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.pyt   <module>   s$   "	