
    O&i!                     h   d Z ddlZddlZddlZddlZddlmZ ddlmZmZm	Z	m
Z
 ddlmZ 	 ddlmZ n# e$ r	 ddlmZ Y nw xY w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  ej        e          Z e             Z!dZ"de#de#ddfdZ$ G d d          Z%de#de&fdZ' G d d          Z(dS )z"Theming support for HTML builders.    N)path)TYPE_CHECKINGAnyDictList)ZipFile)entry_points)package_dir)
ThemeError)__)logging)	ensuredir)Sphinxz
theme.conffilename	targetdirreturnc                     t          |           t          |           5 }|                                D ]}|                    d          rt	          j        ||          }t          t	          j        |                     t          t	          j        |          d          5 }|                    |	                    |                     ddd           n# 1 swxY w Y   	 ddd           dS # 1 swxY w Y   dS )z%Extract zip file to target directory./wbN)
r   r   namelistendswithr   joindirnameopenwriteread)r   r   archivenameentryfps         [/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/sphinx/theming.pyextract_zipr"       sj   i			 -g$$&& 	- 	-D}}S!! Ii..Edl5))***di&&-- -d++,,,- - - - - - - - - - - - - - -	-- - - - - - - - - - - - - - - - - -s6   BC3$)CC3CC3 C!C33C7:C7c            	           e Zd ZdZdededdddfdZdee         fd	Zefd
edede	de	fdZ
i fdeee	f         deee	f         fdZddZdS )ThemezA Theme is a set of HTML templates and configurations.

    This class supports both theme directory and theme archive (zipped theme).r   
theme_pathfactoryHTMLThemeFactoryr   Nc                 l   || _         d | _        d | _        t          j        |          rd | _        || _        nMt          j        d          | _        t          j        | j        |          | _        t          || j                   t          j                    | _        | j                            t          j        | j        t                    d           	 | j                            dd          }ni# t          j        $ r%}t#          t%          d          |z            |d }~wt          j        $ r%}t#          t%          d          |z            |d }~ww xY w|dk    rQ	 |                    |          | _        d S # t"          $ r'}t#          t%          d	          ||fz            |d }~ww xY wd S )
Nsxtzutf-8)encodingthemeinheritz%theme %r doesn't have "theme" settingz'theme %r doesn't have "inherit" settingnonez(no theme named %r found, inherited by %r)r   baserootdirr   isdirthemedirtempfilemkdtempr   r"   configparserRawConfigParserconfigr   	THEMECONFgetNoSectionErrorr   r   NoOptionErrorcreate)selfr   r%   r&   r,   excs         r!   __init__zTheme.__init__3   s   		:j!! 	3DL&DMM $+E22DL IdlD99DM
DM222"2444=)<<wOOO	]koogy99GG* 	[ 	[ 	[R HIIDPQQWZZ) 	] 	] 	]R JKKdRSSY\\	] f;#NN733			 ; ; ; $N!O!O")4"1 2 27:;; s<   C4 4E D##E5 EE$F   
F1
"F,,F1c                 d    | j         | j        gS | j        g| j                                         z   S )zReturn a list of theme directories, beginning with this theme's,
        then the base theme's, then that one's base theme's, etc.
        )r.   r1   get_theme_dirsr<   s    r!   r@   zTheme.get_theme_dirsS   s3     9M?"M?TY%=%=%?%???    sectiondefaultc                 4   	 | j                             ||          S # t          j        t          j        f$ r_}| j        r!| j                            |||          cY d}~S |t          u r"t          t          d          ||fz            ||cY d}~S d}~ww xY w)zdReturn the value for a theme configuration setting, searching the
        base theme chain.
        Nz:setting %s.%s occurs in none of the searched theme configs)
r6   r8   r4   r:   r9   r.   
get_config	NODEFAULTr   r   )r<   rC   r   rD   r=   s        r!   rF   zTheme.get_config\   s    
	;??7D111*L,GH 	 	 	y Dy++GT7CCCCCCCC)##  %= "> ">AH$"P Q QVYZ 	s&    B"BB ,BBB	overridesc                 p   | j         r| j                                         }ni }	 |                    | j                            d                     n# t
          j        $ r Y nw xY w|                                D ]9\  }}||vr+t                              t          d          |z             4|||<   :|S )z6Return a dictionary of theme options and their values.optionsz!unsupported theme option %r given)
r.   get_optionsupdater6   itemsr4   r9   loggerwarningr   )r<   rH   rJ   optionvalues        r!   rK   zTheme.get_optionsl   s    9 	i++--GGG	NN4;,,Y778888* 	 	 	D	 '__.. 	( 	(MFEW$$r"EFFOPPPP"'s   -A A%$A%c                     | j         r+	 t          j        | j                    n# t          $ r Y nw xY w| j        r| j                                         dS dS )zRemove temporary directories.N)r/   shutilrmtree	Exceptionr.   cleanuprA   s    r!   rV   zTheme.cleanup   st    < 	dl++++   9 	 I	  	 s   # 
00r   N)__name__
__module____qualname____doc__strr>   r   r@   rG   r   rF   r   rK   rV    rB   r!   r$   r$   .   s       R R;S ;c ;<N ;SW ; ; ; ;@@S	 @ @ @ @ BK  # S 3 s      79  T#s(^ T#s(^    (           rB   r$   c                     	 t          |           5 }t          |                                v cddd           S # 1 swxY w Y   dS # t          $ r Y dS w xY w)zBCheck whether the specified file is an archived theme file or not.NF)r   r7   r   rU   )r   fs     r!   is_archived_themer`      s    X 	-!

,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-   uus.   A 9A =A  =A 
AAc                       e Zd ZdZddZddZdeddfd	Zd
eddfdZddZ	ddZ
d
eddfdZdedeeef         fdZd
edefdZdS )r'   z A factory class for HTML Themes.appr   r   Nc                     || _         |j        j        | _        |                                  t          |j        dd           r!|                     |j        j                   d S d S )Nhtml_theme_path)	rb   registryhtml_themesthemesload_builtin_themesgetattrr6   load_additional_themesrd   )r<   rb   s     r!   r>   zHTMLThemeFactory.__init__   sj    l.  """3:0$77 	D''
(BCCCCC	D 	DrB   c                     |                      t          j        t          d                    }|                                D ]\  }}|| j        |<   dS )zLoad built-in themes.rg   N)find_themesr   r   r
   rM   rg   )r<   rg   r   r+   s       r!   rh   z$HTMLThemeFactory.load_builtin_themes   sU    !!$)K"B"BCC!<<>> 	& 	&KD% %DK	& 	&rB   theme_pathsc                     |D ]l}t          j        t          j        | j        j        |                    }|                     |          }|                                D ]\  }}|| j        |<   mdS )z7Load additional themes placed at specified directories.N)r   abspathr   rb   confdirrl   rM   rg   )r<   rm   r%   abs_theme_pathrg   r   r+   s          r!   rj   z'HTMLThemeFactory.load_additional_themes   s}    % 	* 	*J!\$)DH4Dj*Q*QRRN%%n55F%||~~ * *e$)D!!*	* 	*rB   r   c                 h    |dk    r|                                   dS |                     |           dS )z,Try to load a theme with the specified name.	alabasterN)load_alabaster_themeload_external_themer<   r   s     r!   load_extra_themez!HTMLThemeFactory.load_extra_theme   s?    ;%%'''''$$T*****rB   c                 l    ddl }t          j        |                                d          | j        d<   dS )zLoad alabaster theme.r   Nrs   )rs   r   r   get_pathrg   )r<   rs   s     r!   rt   z%HTMLThemeFactory.load_alabaster_theme   s8    #'9Y-?-?-A-A;#O#OK   rB   c                     	 ddl }|                                }t          j        |d          | j        d<   dS # t
          $ r Y dS w xY w)z+Load sphinx_rtd_theme theme (if installed).r   Nsphinx_rtd_theme)r{   get_html_theme_pathr   r   rg   ImportError)r<   r{   r%   s      r!   load_sphinx_rtd_themez&HTMLThemeFactory.load_sphinx_rtd_theme   sf    	####)==??J.2i
DV.W.WDK*+++ 	 	 	DD	s   59 
AAc                     t          d          }	 ||         }| j        j                            | j        |j                   | j        j                                         dS # t          $ r Y dS w xY w)zjTry to load a theme using entry_points.

        Sphinx refers to ``sphinx_themes`` entry_points.
        zsphinx.html_themes)groupN)r	   rb   re   load_extensionmoduler6   post_init_valuesKeyError)r<   r   theme_entry_pointsentry_points       r!   ru   z$HTMLThemeFactory.load_external_theme   s     *0DEEE	,T2KH,,TX{7IJJJHO,,...F 	 	 	DD	s   AA$ $
A21A2r%   c                    i }t          j        |          s|S t          j        |          D ]}t          j        ||          }t          j        |          ro|                                                    d          rHt          |          r|dd         }|||<   qt          
                    t          d          |           t          j        t          j        |t                              r|||<   |S )z'Search themes from specified directory.z.zipNzAfile %r on theme path is not a valid zipfile or contains no theme)r   r0   oslistdirr   isfilelowerr   r`   rN   rO   r   r7   )r<   r%   rg   r   pathnamer   s         r!   rl   zHTMLThemeFactory.find_themes   s   !#z*%% 	MZ
++ 	- 	-EyU33H{8$$ 	-)?)?)G)G 	-$X.. N ":D#+F4LLNN2 'E $F $FGLN N N N ;ty9==>> -$,F5MrB   c                 \   || j         vr|                     |           || j         vrA|dk    r;t                              t	          d                     |                                  || j         vrt          t	          d          |z            t          || j         |         |           S )zCreate an instance of theme.r{   zKsphinx_rtd_theme (< 0.3.0) found. It will not be available since Sphinx-6.0z-no theme named %r found (missing theme.conf?))r&   )rg   rw   rN   rO   r   r~   r   r$   rv   s     r!   r;   zHTMLThemeFactory.create   s    t{""!!$'''t{""t/A'A'ANN2 J K K L L L&&(((t{""R OPPSWWXXXT4;t,d;;;;rB   )rb   r   r   NrW   )rX   rY   rZ   r[   r>   rh   r\   rj   rw   rt   r~   ru   r   rl   r$   r;   r]   rB   r!   r'   r'      s$       **D D D D& & & &*# *$ * * * *+S +T + + + +P P P P
        c d38n    *<3 <5 < < < < < <rB   r'   ))r[   r4   r   rS   r2   r   typingr   r   r   r   zipfiler   importlib_metadatar	   r}   importlib.metadatasphinxr
   sphinx.errorsr   sphinx.localer   sphinx.utilr   sphinx.util.osutilr   sphinx.applicationr   	getLoggerrX   rN   objectrG   r7   r\   r"   r$   boolr`   r'   r]   rB   r!   <module>r      s   ( (     				         1 1 1 1 1 1 1 1 1 1 1 1      0/////// 0 0 0////////0       $ $ $ $ $ $             ( ( ( ( ( ( *)))))) 
	8	$	$FHH		-# -# -$ - - - -Z  Z  Z  Z  Z  Z  Z  Z z     _< _< _< _< _< _< _< _< _< _<s   3 A A