o
    tf)                     @  s   U d Z ddlm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ded< dS )z.Serve files directly from the ContentsManager.    )annotationsN)decodebytes)	Awaitable)ensure_async)web)
authorized)JupyterHandlercontentsc                      sP   e Zd ZdZeZe fddZej	e
d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__ f/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/jupyter_server/files/handlers.pyr      s   z$FilesHandler.content_security_policypathstrreturnAwaitable[None] | Nonec                 C  s$   | j |dd |   | j |ddS )zThe head response.F)include_body)getcheck_xsrf_cookie)r   r   r   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   Zcontents_managerZallow_hiddenr   Z	is_hiddenloginfor   	HTTPErrorstriprsplitr   Zget_argumentZset_attachment_headerlowerendswithZ
set_header	mimetypes
guess_typeencodewriter   flush)
r   r   r   cm_namemodelZcur_mimeencodingZ	b64_bytesr   r   r   r   .   sD   


zFilesHandler.get)r   r   r   r   )T)__name__
__module____qualname____doc__AUTH_RESOURCEZauth_resourcepropertyr   r   authenticatedr   r   r   __classcell__r   r   r   r   r
      s    r
   zlist[JupyterHandler]default_handlers)r8   
__future__r   r+   r"   r   typingr   Zjupyter_core.utilsr   tornador   Zjupyter_server.auth.decoratorr   Zjupyter_server.base.handlersr   r9   ZStaticFileHandlerr
   r=   __annotations__r   r   r   r   <module>   s    M