ó
ù2¢\c           @   s–   d  Z  d d l Z d d l Z y d d l m Z Wn! e k
 rU d d l m Z n Xd d l m Z d d l	 m
 Z
 d e
 f d „  ƒ  YZ g  Z d S(	   s.   Serve files directly from the ContentsManager.iÿÿÿÿN(   t   decodebytes(   t   decodestring(   t   web(   t   IPythonHandlert   FilesHandlerc           B   sD   e  Z d  Z e d „  ƒ Z e j d „  ƒ Z e j e d „ ƒ Z	 RS(   sÝ   serve files via ContentsManager

    Normally used when ContentsManager is not a FileContentsManager.

    FileContentsManager subclasses use AuthenticatedFilesHandler by default,
    a subclass of StaticFileHandler.
    c         C   s   t  t |  ƒ j d S(   Ns   ; sandbox allow-scripts(   t   superR   t   content_security_policy(   t   self(    (    s6   lib/python2.7/site-packages/notebook/files/handlers.pyR      s    c         C   s   |  j  ƒ  |  j | d t ƒS(   Nt   include_body(   t   check_xsrf_cookiet   gett   False(   R   t   path(    (    s6   lib/python2.7/site-packages/notebook/files/handlers.pyt   head$   s    
c   	      C   sû  |  j  ƒ  |  j } | j | ƒ rN | j rN |  j j d ƒ t j d ƒ ‚ n  | j d ƒ } d | k r„ | j	 d d ƒ \ } } n | } | j
 | d d d | ƒ} |  j d t ƒ rÇ |  j | ƒ n  | j d	 ƒ ré |  j d
 d ƒ n„ t j | ƒ d } | d k r|  j d
 d ƒ nR | d  k	 r:|  j d
 | ƒ n3 | d d k r]|  j d
 d ƒ n |  j d
 d ƒ | r÷| d d k r¬| d j d ƒ } |  j t | ƒ ƒ n> | d d k rÙ|  j t j | d ƒ ƒ n |  j | d ƒ |  j ƒ  n  d  S(   Ns,   Refusing to serve hidden file, via 404 Errori”  t   /i   t   typet   filet   contentt   downloads   .ipynbs   Content-Types   application/x-ipynb+jsoni    s
   text/plains   text/plain; charset=UTF-8t   formatt   base64s   application/octet-streamt   asciit   json(   R	   t   contents_managert	   is_hiddent   allow_hiddent   logt   infoR   t	   HTTPErrort   stript   rsplitR
   t   get_argumentR   t   set_attachment_headert   endswitht
   set_headert	   mimetypest
   guess_typet   Nonet   encodet   writeR    R   t   dumpst   flush(	   R   R   R   t   cmt   _t   namet   modelt   cur_mimet	   b64_bytes(    (    s6   lib/python2.7/site-packages/notebook/files/handlers.pyR
   )   s<    
	(
   t   __name__t
   __module__t   __doc__t   propertyR   R   t   authenticatedR   t   TrueR
   (    (    (    s6   lib/python2.7/site-packages/notebook/files/handlers.pyR      s
   (   R2   R#   R   R   R    t   ImportErrorR   t   tornadoR   t   notebook.base.handlersR   R   t   default_handlers(    (    (    s6   lib/python2.7/site-packages/notebook/files/handlers.pyt   <module>   s   D