
    oi"                         d dl Z d dlZd dlZddlmZ  G d dej                  j                        Z G d dej                  j                        Z	 G d d	ej                  j                        Z
y)
    N   )collect_static_pathsc                   P     e Zd ZdZ fdZ fdZdedef fdZed        Z	 xZ
S )TemplateStaticFileHandlera  Static file handler that serves the static files for the template system.

    URL paths should be of the form <`template_name>/static/<path>`

    A url such as lab/static/voila.js can be translated to a real path such
    /my/prefix/jupyter/voila/templates/base/static/voila.js
    Meaning the url portion is not part of the real (absolute path)

    For this system, we don't need to use the root, since this is handled in the
    paths module.
    c                 &    t         |   d       y )Nz!/fake-root/voila-template-system/)path)super
initialize)self	__class__s    a/home/ubuntu/docker-apps/notebooks/venv/lib/python3.12/site-packages/voila/static_file_handler.pyr
   z$TemplateStaticFileHandler.initialize   s     CD    c                     |j                  dd      \  }}}|dk(  sJ t        ddg|      | _        t        |   |      S )N/   staticvoila	nbconvert)splitr   rootsr	   parse_url_path)r   r   templater   _ignorer   s        r   r   z(TemplateStaticFileHandler.parse_url_path"   sM     %)JJsA$6!&'!!!)7K*@(K
w%d++r   rootabsolute_pathc                     d }| j                   D ]  }	 t        | 	  ||      c S  |sJ |# t        j                  j
                  $ r}|}Y d }~Ad }~ww xY wN)r   r	   validate_absolute_pathtornadoweb	HTTPError)r   r   r   last_exceptioner   s        r   r   z0TemplateStaticFileHandler.validate_absolute_path+   se     JJ 	#D#w5dMJJ	#
 ~ ;;(( #!"#s   -A
AAc                    t         j                  j                  |      j                  t         j                  j                  d      \  }}}|dk(  sJ t        ddg|      }|D ]b  }t         j                  j                  t         j                  j                  ||            }t         j                  j                  |      s`|c S  S )Nr   r   r   r   )	osr   normpathr   sepr   abspathjoinexists)clsr   r   r   r   relpathr   r(   s           r   get_absolute_pathz+TemplateStaticFileHandler.get_absolute_path7   s    $&GG$4$4T$:$@$@a$P!&'!!!$g{%;XF 	Dggoobggll4&ABGww~~g&	 r   )__name__
__module____qualname____doc__r
   r   strr   classmethodr-   __classcell__r   s   @r   r   r      s:    
E,
3 
s 
  r   r   c                   *     e Zd ZdZd fd	Zd Z xZS )MultiStaticFileHandlera/  A static file handler that 'merges' a list of directories

    If initialized like this::

        application = web.Application([
            (r"/content/(.*)", web.MultiStaticFileHandler, {"paths": ["/var/1", "/var/2"]}),
        ])

    A file will be looked up in /var/1 first, then in /var/2.

    c                 <    || _         t        | 	  |d   |       y )Nr   )r   default_filename)r   r	   r
   )r   pathsr9   r   s      r   r
   z!MultiStaticFileHandler.initializeS   s!    
a;KLr   c                    | j                   d   | _        | j                   D ]h  }t        j                  j	                  t        j                  j                  ||            }t        j                  j                  |      s`|| _         |S  S )Nr   )r   r   r%   r   r(   r)   r*   )r   r   r   r(   s       r   r-   z(MultiStaticFileHandler.get_absolute_pathW   sk    JJqM	JJ 	Dggoobggll4&>?Gww~~g& 		
 r   r   )r.   r/   r0   r1   r
   r-   r4   r5   s   @r   r7   r7   F   s    
Mr   r7   c                   .     e Zd Zg g f fd	Z fdZ xZS )AllowListFileHandlerc                 @    || _         || _        t        |   di | y )N )	allowlistdenylistr	   r
   )r   r@   rA   kwargsr   s       r   r
   zAllowListFileHandler.initializec   s!    " $V$r   c                 &   t        fd| j                  D              }t        fd| j                  D              }|s t        j                  j                  dd      |r t        j                  j                  dd      t        |   |      S )Nc              3   J   K   | ]  }t        j                  |        y wr   re	fullmatch.0patternr   s     r   	<genexpr>z9AllowListFileHandler.get_absolute_path.<locals>.<genexpr>k   s     T'",,w5T    #c              3   J   K   | ]  }t        j                  |        y wr   rE   rH   s     r   rK   z9AllowListFileHandler.get_absolute_path.<locals>.<genexpr>l   s     Rgt4RrL   i  zFile not allowlistedzFile denylisted)anyr@   rA   r   r    r!   r	   r-   )r   r   r   allowlisted
denylistedr   s     `  r   r-   z&AllowListFileHandler.get_absolute_pathh   su     TT^^TTRDMMRR
++''-CDD++''->??w(t44r   )r.   r/   r0   r
   r-   r4   r5   s   @r   r=   r=   b   s    #% %
	5 	5r   r=   )r%   rF   tornado.webr   r:   r   r    StaticFileHandlerr   r7   r=   r?   r   r   <module>rS      sV    
 	  '1 = = 1hW[[:: 857;;88 5r   