
    Xhj                        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rdd
lmZ dZ G d deej&                        Zg Zded<   y)z.Serve files directly from the ContentsManager.    )annotationsN)decodebytes)TYPE_CHECKING)ensure_async)web)
authorized)JupyterHandler)	Awaitablecontentsc                       e Zd ZdZeZe fd       Zej                  e
dd              Zej                  e
dd              Z x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                    t         |   dz   S )zThe content security policy.z; sandbox allow-scripts)supercontent_security_policy)self	__class__s    Q/var/www/html/myenv/lib/python3.12/site-packages/jupyter_server/files/handlers.pyr   z$FilesHandler.content_security_policy"   s    
 w.1JJJ    c                n    | j                  |d       | j                          | j                  |d      S )zThe head response.F)include_body)getcheck_xsrf_cookie)r   paths     r   headzFilesHandler.head)   s3     	E* xx5x11r   c                R  K   | j                          | j                  }|j                  sRt        |j	                  |             d{   r0| j
                  j                  d       t        j                  d      |j                  d      }d|v r|j                  dd      \  }}n|}t        |j                  |d|             d{   }| j                  dd      r| j                  |       |j                         j                  d	      r| j!                  d
d       nt#        j$                  |      \  }}|dk(  r| j!                  d
d       |dk(  r| j!                  d
d       nW|| j!                  d
d       nB|| j!                  d
|       n-|d   dk(  r| j!                  d
d       n| j!                  d
d       |r\|d   dk(  r/|d   j'                  d      }	| j)                  t+        |	             n| j)                  |d          | j-                          yy7 7 Zw)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_bytess
             r   r   zFilesHandler.get1   s    
 	 ""bll46H)I#I#IHHMMHI--$$zz#$;kk#q)GAtD"266$V\6#RSSZ.&&t, ::<  *OON,FG!*!5!5d!;Hh<'0KL6!0BC%0JK%9xH,0JK0KLX(*!),33G<	

;y12

5+,JJL E $J Ts&   AH'H!	BH'
H$EH'$H')r   strreturnzAwaitable[None] | None)T)__name__
__module____qualname____doc__AUTH_RESOURCEauth_resourcepropertyr   r   authenticatedr   r   r   __classcell__)r   s   @r   r   r      sg     "MK K 	2  2 	.  .r   r   zlist[JupyterHandler]default_handlers)rD   
__future__r   r3   r$   r   typingr   jupyter_core.utilsr   tornador   jupyter_server.auth.decoratorr   jupyter_server.base.handlersr	   collections.abcr
   rE   StaticFileHandlerr   rJ   __annotations__ r   r   <module>rU      sR    4 #     +  4 7)J>3#8#8 JZ *, & +r   