o
    ^ij                     @  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 er9d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)TYPE_CHECKING)ensure_async)web)
authorized)JupyterHandler)	Awaitable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__ X/home/ubuntu/hpml_nyu/venv/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   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   1   sD   


zFilesHandler.get)r   r   r   r   )T)__name__
__module____qualname____doc__AUTH_RESOURCEauth_resourcepropertyr   r   authenticatedr   r   r   __classcell__r   r   r   r   r      s    r   zlist[JupyterHandler]default_handlers)rA   
__future__r   r2   r#   r   typingr   jupyter_core.utilsr   tornador   jupyter_server.auth.decoratorr   jupyter_server.base.handlersr   collections.abcr	   rB   StaticFileHandlerr   rG   __annotations__r   r   r   r   <module>   s    M