o
    i                     @   s   U d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ d	ZG d
d dee	jZg Zee ed< dS )z.Serve files directly from the ContentsManager.    N)decodebytes)List)ensure_async)web)
authorized)JupyterHandlercontentsc                       sN   e Zd ZdZeZe fddZej	e
dd Zej	e
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 )zThe content security policy.z; sandbox allow-scripts)supercontent_security_policy)self	__class__ X/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyter_server/files/handlers.pyr      s   z$FilesHandler.content_security_policyc                 C   s$   | j |dd |   | j |ddS )zThe head response.F)include_body)getcheck_xsrf_cookie)r   pathr   r   r   head#   s   zFilesHandler.headTc           
         s  |    | j}|js t||I dH r | jd td|	d}d|v r2|
dd\}}n|}t|j|d|dI dH }| ddrL| | | d	rZ| d
d nEt|\}}|dkrk| d
d |dkrv| d
d n)|dur| d
d n|dur| d
| n|d dkr| d
d n| d
d |r|d dkr|d d}	| t|	 n| |d  |   dS dS )zGet a file by path.Nz,Refusing to serve hidden file, via 404 Errori  /   file)typecontentdownloadz.ipynbzContent-Typezapplication/x-ipynb+jsonz
text/plainztext/plain; charset=UTF-8gzipzapplication/gzipzapplication/octet-streamformatbase64r   ascii)r   contents_managerallow_hiddenr   	is_hiddenloginfor   	HTTPErrorstriprsplitr   get_argumentset_attachment_headerlowerendswith
set_header	mimetypes
guess_typeencodewriter   flush)
r   r   r   cm_namemodelcur_mimeencoding	b64_bytesr   r   r   r   +   sD   


zFilesHandler.get)T)__name__
__module____qualname____doc__AUTH_RESOURCEauth_resourcepropertyr   r   authenticatedr   r   r   __classcell__r   r   r   r   r	      s    r	   default_handlers)r<   r-   r   r   typingr   jupyter_core.utilsr   tornador   jupyter_server.authr   jupyter_server.base.handlersr   r=   StaticFileHandlerr	   rB   __annotations__r   r   r   r   <module>   s    M