
    zi:                    f   d Z ddlmZ ddl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 ddlmZ ej        dk    rddlmZ n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 e
rddlmZ  ej        e           Z! e"            Z#dZ$ddZ% G d d          Z&ddZ' G d d          Z(dS )z"Theming support for HTML builders.    )annotationsN)path)TYPE_CHECKINGAny)ZipFile)   
   )entry_points)package_dir)
ThemeError)__)logging)	ensuredir)Sphinxz
theme.conffilenamestr	targetdirreturnNonec                    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         Y/var/www/tmov.alphamb/tmov_inventario/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d	ZddZefddZdd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!   r   
theme_pathfactoryHTMLThemeFactoryr   r   c                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__8   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	list[str]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.
        )r1   r4   get_theme_dirsr?   s    r$   rD   zTheme.get_theme_dirsX   s3     9M?"M?TY%=%=%?%???    sectiondefaultr   c                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)
r9   r;   r7   r=   r<   r1   
get_config	NODEFAULTr   r   )r?   rG   r!   rH   r@   s        r$   rJ   zTheme.get_configa   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NNNNNN	s&    B"BB ,BBBN	overridesdict[str, Any] | Nonedict[str, Any]c                   |i }| j         r| j                                         }ni }t          j        t          j                  5  |                    | j                            d                     ddd           n# 1 swxY w Y   |                                D ]9\  }}||vr+t          
                    t          d          |z             4|||<   :|S )z6Return a dictionary of theme options and their values.Noptionsz!unsupported theme option %r given)r1   get_options
contextlibsuppressr7   r<   updater9   itemsloggerwarningr   )r?   rL   rP   optionvalues        r$   rQ   zTheme.get_optionsp   s   I9 	i++--GGG !<== 	9 	9NN4;,,Y77888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 '__.. 	( 	(MFEW$$r"EFFOPPPP"'s   .B  BBc                    | j         rJt          j        t                    5  t	          j        | j                    ddd           n# 1 swxY w Y   | j        r| j                                         dS dS )zRemove temporary directories.N)r2   rR   rS   	Exceptionshutilrmtreer1   cleanuprE   s    r$   r^   zTheme.cleanup   s    < 	,$Y// , ,dl+++, , , , , , , , , , , , , , , 9 	 I	  	 s   AAA)r!   r   r(   r   r)   r*   r   r   )r   rB   )rG   r   r!   r   rH   r   r   r   )N)rL   rM   r   rN   r   r   )
__name__
__module____qualname____doc__rA   rD   rK   rJ   rQ   r^    rF   r$   r'   r'   3   s        R R; ; ; ;@@ @ @ @ BK         *           rF   r'   boolc                    	 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   r:   r   r[   )r   fs     r$   is_archived_themerh      s    X 	-!

,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-   uus.   A 9A =A  =A 
AAc                  R    e Zd ZdZddZddZdd
ZddZddZddZ	ddZ
ddZdS )r*   z A factory class for HTML Themes.appr   r   r   c                    || _         |j        j        | _        |                                  t          |j        dd           r!|                     |j        j                   d S d S )Nhtml_theme_path)	rj   registryhtml_themesthemesload_builtin_themesgetattrr9   load_additional_themesrl   )r?   rj   s     r$   rA   zHTMLThemeFactory.__init__   sj    l.  """3:0$77 	D''
(BCCCCC	D 	DrF   c                    |                      t          j        t          d                    }|                                D ]\  }}|| j        |<   dS )zLoad built-in themes.ro   N)find_themesr   r   r   rU   ro   )r?   ro   r!   r.   s       r$   rp   z$HTMLThemeFactory.load_builtin_themes   sU    !!$)K"B"BCC!<<>> 	& 	&KD% %DK	& 	&rF   theme_pathsr   c                    |D ]l}t          j        t          j        | j        j        |                    }|                     |          }|                                D ]\  }}|| j        |<   mdS )z7Load additional themes placed at specified directories.N)r   abspathr   rj   confdirrt   rU   ro   )r?   ru   r(   abs_theme_pathro   r!   r.   s          r$   rr   z'HTMLThemeFactory.load_additional_themes   s}    % 	* 	*J!\$)DH4Dj*Q*QRRN%%n55F%||~~ * *e$)D!!*	* 	*rF   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*****rF   c                l    ddl }t          j        |                                d          | j        d<   dS )zLoad alabaster theme.r   Nr{   )r{   r   r   get_pathro   )r?   r{   s     r$   r|   z%HTMLThemeFactory.load_alabaster_theme   s8    #'9Y-?-?-A-A;#O#OK   rF   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
   rj   rm   load_extensionmoduler9   post_init_valuesKeyError)r?   r!   theme_entry_pointsentry_points       r$   r}   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(   dict[str, str]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   r3   oslistdirr   isfilelowerr   rh   rV   rW   r   r:   )r?   r(   ro   r"   pathnamer!   s         r$   rt   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rF   r'   c                    || j         vr|                     |           || j         vrt          t          d          |z            t	          || j         |         |           S )zCreate an instance of theme.z-no theme named %r found (missing theme.conf?))r)   )ro   r   r   r   r'   r~   s     r$   r>   zHTMLThemeFactory.create   si    t{""!!$'''t{""R OPPSWWXXXT4;t,d;;;;rF   N)rj   r   r   r   r_   )ru   r   r   r   )r!   r   r   r   )r(   r   r   r   )r!   r   r   r'   )r`   ra   rb   rc   rA   rp   rr   r   r|   r}   rt   r>   rd   rF   r$   r*   r*      s        **D D D D& & & &* * * *+ + + +P P P P
      *< < < < < <rF   r*   )r   r   r   r   r   r   )r   r   r   re   ))rc   
__future__r   r7   r   r\   sysr5   r   typingr   r   zipfiler   version_infoimportlib.metadatar
   importlib_metadatarR   sphinxr   sphinx.errorsr   sphinx.localer   sphinx.utilr   sphinx.util.osutilr   sphinx.applicationr   	getLoggerr`   rV   objectrK   r:   r%   r'   rh   r*   rd   rF   r$   <module>r      s   ( ( " " " " " "     				  



        % % % % % % % %      w/////////////           $ $ $ $ $ $             ( ( ( ( ( ( *)))))) 
	8	$	$FHH		- - - -Y  Y  Y  Y  Y  Y  Y  Y x   P< P< P< P< P< P< P< P< P< P<rF   