o
    i
                     @   s`   d 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 G dd de	Zg ZdS )	z.Serve files directly from the ContentsManager.    N)decodebytes)genweb)IPythonHandler)maybe_futurec                       sH   e Zd ZdZe fddZejdd Zeje	j
d	ddZ  ZS )
FilesHandlerzserve files via ContentsManager

    Normally used when ContentsManager is not a FileContentsManager.

    FileContentsManager subclasses use AuthenticatedFilesHandler by default,
    a subclass of StaticFileHandler.
    c                    s   t  jd S )Nz; sandbox allow-scripts)supercontent_security_policy)self	__class__ R/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook/files/handlers.pyr	      s   z$FilesHandler.content_security_policyc                 C   s   |    | j|ddS )NF)include_body)check_xsrf_cookieget)r
   pathr   r   r   head   s   zFilesHandler.headTc           	      c   st   |    | j}||r|js| jd td|d}d|v r-|	dd\}}n|}t
|j|d|dV }| ddrE| | | d	rS| d
d n0t|d }|dkre| d
d n|d urp| d
| n|d dkr}| d
d n| d
d |r|d dkr|d d}| t| n|d dkr| t|d  n| |d  |   d S d S )Nz,Refusing to serve hidden file, via 404 Errori  /   file)typecontentdownloadFz.ipynbzContent-Typezapplication/x-ipynb+jsonr   z
text/plainztext/plain; charset=UTF-8formatbase64zapplication/octet-streamr   asciijson)r   contents_manager	is_hiddenallow_hiddenloginfor   	HTTPErrorstriprsplitr   r   get_argumentset_attachment_headerlowerendswith
set_header	mimetypes
guess_typeencodewriter   r   dumpsflush)	r
   r   r   cm_namemodelcur_mime	b64_bytesr   r   r   r   $   s@   


zFilesHandler.get)T)__name__
__module____qualname____doc__propertyr	   r   authenticatedr   r   	coroutiner   __classcell__r   r   r   r   r      s    
r   )r:   r+   r   r   r   tornador   r   notebook.base.handlersr   notebook.utilsr   r   default_handlersr   r   r   r   <module>   s    D