
    ^h                    z    S r SSKJr  SSKrSSKrSSKJr  SSKJrJr  SSK	J
r
  SSKJr  SSKJr   " S	 S
\5      rg)z+Tornado handlers for dynamic theme loading.    )annotationsN)glob)Any	Generator)urlparse)FileFindHandler)url_path_joinc                  z    \ rS rSrSr    S	             S
S jjr S       SS jjrSS jrSS jrSr	g)ThemesHandler   z4A file handler that mangles local urls in CSS files.Nc           	         U=(       d    / n/ nU H(  nUS-   n	UR                  S [        U	SS9 5       5        M*     [        U[        5      (       d  U/nXq-   n[        R
                  " XX#S9  X@l        g)zInitialize the handler.z
/**/themesc              3  $   #    U  H  ov   M     g 7fN ).0paths     Z/home/james-whalen/.local/lib/python3.13/site-packages/jupyterlab_server/themes_handler.py	<genexpr>+ThemesHandler.initialize.<locals>.<genexpr>#   s     R.QdT.Qs   T)	recursive)default_filenameno_cache_pathsN)extendr   
isinstancelistr   
initialize
themes_url)
selfr   r   r   r   labextensions_pathkwargs	ext_pathsext_dirtheme_patterns
             r   r   ThemesHandler.initialize   s|     052!	)G#l2MRd=D.QRR *
 $%%6D"")9	
 %    c                    [         R                  R                  U5      u  pEUS:w  a  [        R                  " XU5      $ U R                  5       $ )zRetrieve the content of the requested resource which is located
at the given absolute path.

This method should either return a byte string or an iterator
of byte strings.
.css)osr   splitextr   get_content_get_css)r   abspathstartendbaseexts         r   r*   ThemesHandler.get_content/   s@     GG$$W-	&="..wsCC}}r%   c                    U R                   c   e[        R                  R                  U R                   5      u  pUS:w  a  [        R
                  " U 5      $ [        U R                  5       5      $ )z:Retrieve the total size of the resource at the given path.r'   )absolute_pathr(   r   r)   r   get_content_sizelenr+   )r   r/   r0   s      r   r4   ThemesHandler.get_content_size>   sY    !!---GG$$T%7%78	&="33D994==?##r%   c                  ^ U R                   c   e[        U R                   S5       nUR                  5       R                  S5      nSSS5        U R                  (       d  g[
        R                  R                  U R                  5      R                  [
        R                  S5      n[        U R                  U5      mSnSU4S jjn[        R                  " XEW5      R                  S5      $ ! , (       d  f       N= f)	z"Get the mangled css file contents.Nrbzutf-8r%   /zurl\('(.*)'\)|url\('(.*)'\)c                  > U R                  5       n[        S U R                  5        5       5      n[        U5      nUR	                  S5      (       d  UR
                  (       a  U$ UR                  U[        TU5      5      $ )z6Replace the matched relative url with the mangled url.c              3  6   #    U  H  o(       d  M  Uv   M     g 7fr   r   )r   gs     r   r   ;ThemesHandler._get_css.<locals>.replacer.<locals>.<genexpr>[   s     3:a:s   
	r9   )groupnextgroupsr   
startswithschemereplaceujoin)mr>   partparsedbasepaths       r   replacer(ThemesHandler._get_css.<locals>.replacerW   sa    GGIE3188:33D d^Fs##v}}==uXt'<==r%   )rE   r   returnr   )r3   openreaddecoder   r(   r   dirnamerC   seprD   resubencode)r   fiddatabasedirpatternrI   rH   s         @r   r+   ThemesHandler._get_cssF   s    !!---$$$d+s88:$$W-D , ''//$)),44RVVSA'2
 1	> vvg.55g>>7 ,+s    C..
C<)r   )NNNN)r   zstr | list[str]r   
str | Noner   list[str] | Noner   rY   r   rZ   r    r   rK   None)NN)r,   strr-   
int | Noner.   r]   rK   z$bytes | Generator[bytes, None, None])rK   int)rK   bytes)
__name__
__module____qualname____firstlineno____doc__r   r*   r4   r+   __static_attributes__r   r%   r   r   r      s    >
 (,+/!%/3%% %% )	%
 % -% % 
%8 IM#-;E	-$?r%   r   )rd   
__future__r   r(   rQ   r   typingr   r   urllib.parser   jupyter_server.base.handlersr   jupyter_server.utilsr	   rD   r   r   r%   r   <module>rk      s0    1 # 	 	  ! ! 8 7S?O S?r%   