
    -PhL                       d Z ddlmZ dZddl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 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 ddlmZ ddlmZ ddlm Z  erFddl!m"Z" ddlm#Z#m$Z$m%Z% ddl&m'Z'  G d de%d          Z( G d de%d          Z) G d de%d          Z* ej+        e,          Z- e.            Z/dZ0dZ1 G d d          Z2 G d d           Z3dEd%Z4dFd-Z5dGd0Z6dHd3Z7dId5Z8dJd7Z9dKd9Z:dLd;Z;dMd<Z<dNd=Z= G d> d8          Z>dOdBZ?e,dCk    r! e@ e?ejA        dDd                             dS )Pz"Theming support for HTML builders.    )annotations)ThemeHTMLThemeFactoryN)entry_points)Path)TYPE_CHECKING)ZipFile)package_dir)check_confval_types)
ThemeError)__)logging)_StrPath)	ensuredir)Callable)AnyRequired	TypedDict)Sphinxc                  $    e Zd ZU ded<   ded<   dS )
_ThemeTomlzRequired[_ThemeTomlTheme]themedict[str, str]optionsN__name__
__module____qualname____annotations__     N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/theming.pyr   r       s*         ((((r!   r   F)totalc                  8    e Zd ZU ded<   ded<   ded<   ded<   dS )	_ThemeTomlThemezRequired[str]inherit	list[str]stylesheetssidebars_ThemeTomlThemePygmentspygments_styleNr   r    r!   r"   r%   r%   $   sB         //////r!   r%   c                  $    e Zd ZU ded<   ded<   dS )r*   strdefaultdarkNr   r    r!   r"   r*   r*   *   s"         					r!   r*   z
theme.tomlz
theme.confc                  @    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 )r   zA Theme is a set of HTML templates and configurations.

    This class supports both theme directory and theme archive (zipped theme).
    namer-   configsdict[str, _ConfigFile]paths
list[Path]tmp_dirsreturnNonec                  || _         t          |          | _        || _        i }d| _        d| _        d | _        d | _        t          |	                                          D ]X}||j
        z  }|j        |j        | _        |j        |j        | _        |j        |j        | _        |j        |j        | _        Y|| _        d S )Nr    )r1   tuple_dirs	_tmp_dirsr(   sidebar_templatespygments_style_defaultpygments_style_darkreversedvaluesr   _options)selfr1   r2   r4   r6   r   configs          r"   __init__zTheme.__init__<   s     	5\\
!"$,.2426#/3 w~~//00 		F 		FFv~%G!-#)#5 '3)/)A&,8.4.K+)5+1+E(r!   list[_StrPath]c                P    t          t          t          | j                            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.
        )listmapr   r;   rC   s    r"   get_theme_dirszTheme.get_theme_dirsZ   s     C$*--...r!   sectionr.   r   c                   |dk    ri|dk    rd                     | j                  p|}n|dk    rd                     | j                  p|}nc|dk    r
| j        p|}nS|dk    r
| j        p|}nC|}n@|dk    r| j                            ||          }nt          d          }t          |          |t          u r#t          d	          ||fz  }t          |          |S )
zdReturn the value for a theme configuration setting, searching the
        base theme chain.
        r   
stylesheet, r)   r+   pygments_dark_styler   zoTheme configuration sections other than [theme] and [options] are not supported (tried to get a value from %r).z:setting %s.%s occurs in none of the searched theme configs)
joinr(   r=   r>   r?   rB   getr   r   _NO_DEFAULT)rC   rL   r1   r.   valuemsgs         r"   
get_configzTheme.get_config`   s    g|##		$"233>w##		$"899DW)))3>w...0;G	!!M%%dG44EED C S//!KQRRV C S//!r!   N	overridesdict[str, Any] | Nonedict[str, Any]c                    |i }| j                                         }|                                D ]7\  }}||vr)t                              t          d          |           2|||<   8|S )z6Return a dictionary of theme options and their values.Nz!unsupported theme option %r given)rB   copyitemsloggerwarningr   )rC   rW   r   optionrT   s        r"   get_optionszTheme.get_options   sx    I-$$&&&__.. 	( 	(MFEW$$r"EFFOOOO"'r!   c                    | j         D ]G}t          j        t                    5  t	          j        |           ddd           n# 1 swxY w Y   HdS )zRemove temporary directories.N)r<   
contextlibsuppress	Exceptionshutilrmtree)rC   tmp_dirs     r"   _cleanupzTheme._cleanup   s    ~ 	' 	'G$Y// ' 'g&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	's   AA	A	)
r1   r-   r2   r3   r4   r5   r6   r5   r7   r8   )r7   rF   )rL   r-   r1   r-   r.   r   r7   r   N)rW   rX   r7   rY   r7   r8   )
r   r   r   __doc__rE   rK   rS   rV   r`   rh   r    r!   r"   r   r   6   s         
       </ / / / BM     >    ' ' ' ' ' 'r!   r   c                  R    e Zd ZdZddZddZdd
ZddZedd            Z	ddZ
dS )r   z A factory class for HTML Themes.appr   r7   r8   c                    || _         |j        j        | _        i | _        |                                  t          |j        dd           r|                     |j        j	                   | 
                                 d S )Nhtml_theme_path)_appregistryhtml_themes_themes_entry_point_themes_load_builtin_themesgetattrrD   _load_additional_themesro   _load_entry_point_themes)rC   rm   s     r"   rE   zHTMLThemeFactory.__init__   sx    	|/BD !!###3:0$77 	E(()CDDD%%'''''r!   c                    |                      t          dz            }|                                D ]\  }}t          |          | j        |<   dS )zLoad built-in themes.themesN)_find_themesr
   r\   r   rs   )rC   rz   r1   r   s       r"   ru   z%HTMLThemeFactory._load_builtin_themes   sT    "";#9::!<<>> 	1 	1KD%!)%DL	1 	1r!   theme_pathsr'   c                    |D ]i}| j         j        |z                                  }|                     |          }|                                D ]\  }}t          |          | j        |<   jdS )z7Load additional themes placed at specified directories.N)rp   confdirresolver{   r\   r   rs   )rC   r|   
theme_pathabs_theme_pathrz   r1   r   s          r"   rw   z(HTMLThemeFactory._load_additional_themes   s~    % 	5 	5J"i/*<EEGGN&&~66F%||~~ 5 5e%-e__T""5	5 	5r!   c                    t          d          D ]1}|j        | j        v r| j        |j        fdd	}|| j        |j        <   2d
S )zTry to load a theme with the specified name.

        This uses the ``sphinx.html_themes`` entry point from package metadata.
        zsphinx.html_themes)grouprm   r   theme_moduler-   r7   r8   c                Z    |                      |           t          | | j                   d S ri   )setup_extension_config_post_initrD   )rm   r   s     r"   _load_theme_closurezFHTMLThemeFactory._load_entry_point_themes.<locals>._load_theme_closure   s0    
 ##L111!#sz22222r!   N)rm   r   r   r-   r7   r8   )r   r1   rs   rp   modulert   )rC   entry_pointr   s      r"   rx   z)HTMLThemeFactory._load_entry_point_themes   s|    
 (.BCCC 	M 	MK4<// #i$/$63 3 3 3 3 :MD$[%566	M 	Mr!   r   r   dict[str, Path]c                   i }|                                  s|S |                                 D ]}|j        }|                                r`|j                                        dk    rCt          |          r|||j        <   Tt          	                    t          d          |           }|t          z  }|t          z  }|                                s|                                r|||<   |S )z'Search themes from specified directory.z.zipzAfile %r on theme path is not a valid zipfile or contains no theme)is_diriterdirr1   is_filesuffixlower_is_archived_themestemr]   r^   r   _THEME_TOML_THEME_CONF)r   rz   pathnameentry	toml_path	conf_paths         r"   r{   zHTMLThemeFactory._find_themes   s    #%  "" 	M"**,, 	- 	-HME!! -ho&;&;&=&=&G&G%h// 	,4F8=))NN;      %{2	${2	$$&& -)*;*;*=*= -$,F5Mr!   r1   r-   r   c                    || j         v r| j         |         } |             || j        vrt          t          d          |z            t	          || j        | j                   \  }}}t          ||||          S )zCreate an instance of theme.z-no theme named %r found (missing theme.toml?))r2   r4   r6   )rt   rs   r   r   _load_theme_with_ancestorsr   )rC   r1   entry_point_loaderrz   
theme_dirsr6   s         r"   createzHTMLThemeFactory.create   s    4+++!%!9$!?   t|##R OPPSWWXXX'AL$(
 (
$
H
 T6hOOOOr!   N)rm   r   r7   r8   rj   )r|   r'   r7   r8   )r   r   r7   r   )r1   r-   r7   r   )r   r   r   rk   rE   ru   rw   rx   staticmethodr{   r   r    r!   r"   r   r      s        **( ( ( (1 1 1 15 5 5 5M M M M&    \6P P P P P Pr!   r   filenamer   r7   boolc                   	 t          |           5 }t          |                                          }t          |v p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	   	frozensetnamelistr   r   rd   )r   fr   s      r"   r   r      s    X 	F! ..H(*EkX.E	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F    uus4   A 3AA AA AA 
A,+A,r1   r-   r|   dict[str, _StrPath]entry_point_themesdict[str, Callable[[], None]]5tuple[dict[str, _ConfigFile], list[Path], list[Path]]c          	     8   i }g }g }t          d          D ]}t          | ||                    \  }}}	}
|                    |           |	|                    |	           |
|| <   |dk    r n||v r!t          d          | z  }t	          |          ||v r||vr||         } |             ||vrDt          d          | |d                    t          |                    fz  }t	          |          |} t          d          | z  }t	          |          |||fS )N
   nonez%The %r theme has circular inheritancezQThe %r theme inherits from %r, which is not a loaded theme. Loaded themes are: %srO   z#The %r theme has too many ancestors)range_load_themeappendr   r   rQ   sorted)r1   r|   r   rz   r   r6   _r&   	theme_dirrg   rD   rU   r   s                r"   r   r      sl    &(FJH 2YY  .9$D@Q.R.R+GV)$$$OOG$$$tfEf<==DCS//!(((WK-G-G!3G!<   +%%(  w		&*=*= > >?@C S//!677$>oo:x''r!   r   *tuple[str, Path, Path | None, _ConfigFile]c                  |                                 rd }|}n6t          t          j        d                    }|| z  }t	          ||           |t
          z  x}                                r/t          |          }t          ||           }t          |          }nl|t          z  x}                                r/t          |          }	t          |	|           }t          |	          }nt          t          d          |z            ||||fS )Nsxtz'no theme configuration file found in %r)r   r   tempfilemkdtemp_extract_zipr   r   _load_theme_toml_validate_theme_toml_convert_theme_tomlr   _load_theme_conf_validate_theme_conf_convert_theme_confr   r   )
r1   r   rg   r   r   
_cfg_tabler&   rD   r   _cfg_parsers
             r"   r   r      s     ,		 x'..//dN	Z+++,,	5577 	T%i00
&z488$Z00 ;.
.)	7	7	9	9 T&y11&{D99$[11EFFRSSSIw..r!   
target_dirr8   c               R   t          |           t          |           5 }|                                D ]Y}|                    d          r||z  }t          |j                   |                    |                    |                     Z	 ddd           dS # 1 swxY w Y   dS )z%Extract zip file to target directory./N)r   r	   r   endswithparentwrite_bytesread)r   r   archiver1   r   s        r"   r   r   ;  s    j			 2g$$&& 	2 	2D}}S!! %Eel###gll4001111	22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s   A/BB #B config_file_pathc               p    t          j        |                     d                    fddD             S )Nutf-8encodingc                *    i | ]}|v ||         S r    r    ).0scs     r"   
<dictcomp>z$_load_theme_toml.<locals>.<dictcomp>J  s$    <<<Q!VVAqtVVVr!   )r   r   )tomllibloads	read_textr   r   s    @r"   r   r   H  s?    &00'0BBCCA<<<<1<<<<r!   cfgc                   d| vr!t          d          |z  }t          |          | d         }t          |t                    s!t          d          |z  }t          |          |                    dd          }|s!t          d          |z  }t          |          d| v r<t          | d         t                    s!t          d          |z  }t          |          |S )	Nr   'theme %r doesn't have the "theme" tablez+The %r theme "[theme]" table is not a tabler&    4The %r theme must define the "theme.inherit" settingr   z-The %r theme "[options]" table is not a table)r   r   
isinstancedictrR   )r   r1   rU   r   r&   s        r"   r   r   M  s    c;<<tCooLEeT"" >??$Fooii	2&&G GHH4OooC#i.$// 	"DEELCS//!Nr!   _ConfigFilec          
        | d         }d|v rt          |d                   }nd }d|v rt          |d                   }nd }|                    di           }t          |t                    r'd| d}t	          d          |z  }t          |          |                    d          }|                    d	          }t          |||||                     d
i                     S )Nr   r(   r)   r+   zpygments_style = { default = "z" }z>The "theme.pygments_style" setting must be a table. Hint: "%s"r.   r/   r   r(   r=   r>   r?   r   )r:   rR   r   r-   r   r   r   )	r   r   r(   r=   pygments_tablehintrU   r>   r?   s	            r"   r   r   `  s   LE.3E-4H.I.IU49%
:K4L4L YY/44N.#&& EEEEOPPSWW 	 oo)7););I)F)F&4&8&8&@&@+5/	2&&   r!   configparser.RawConfigParserc               Z    t          j                    }|                    | d           |S )Nr   r   )configparserRawConfigParserr   r   s     r"   r   r   |  s,    $&&AFFgF...Hr!   c                    |                      d          st          t          d          |z            |                     ddd           x}r|S t          d          |z  }t          |          )Nr   r   r&   fallbackr   )has_sectionr   r   rR   )r   r1   r&   rU   s       r"   r   r     sv    ??7## PFGG$NOOO'''9t'<<<w 
C
D
Dt
KC
S//r!   c               X   |                      ddd          x}r;t          t          t          j        |                    d                              }nd }|                      ddd          x}r;t          t          t          j        |                    d                              }nd }|                      ddd           }|                      ddd           }|                     d	          r"t          |                     d	                    ni }t          |||||
          S )Nr   rN   r   r   ,r)   r+   rP   r   r   )
rR   r:   rI   r-   stripsplitr   r   r\   r   )r   rN   r(   sidebarr=   r>   r?   r   s           r"   r   r     sF   WWWlRW@@@z .3	:++C0011/
 /
 ''':';;;w !49	7==--..5
 5
 !),!D *1 * * '*gg& '. ' ' -0OOI,F,FNd399Y''(((BG+5/   r!   c                  2    e Zd ZdZddZddZddZddZdS )r   r   r(   tuple[str, ...] | Noner=   r>   
str | Noner?   r   r   r7   r8   c                p    || _         || _        || _        || _        |                                | _        d S ri   )r(   r=   r>   r?   r[   r   )rC   r(   r=   r>   r?   r   s         r"   rE   z_ConfigFile.__init__  s7     4?9J2H#/B '.||~~r!   r-   c                p    | j         j         d| j        d| j        d| j        d| j        d| j        dS )Nz(stylesheets=z, sidebar_templates=z, pygments_style_default=z, pygments_style_dark=z
, options=))	__class__r   r(   r=   r>   r?   r   rJ   s    r"   __repr__z_ConfigFile.__repr__  ss    ~* ) )+) )!%!7) ) '+&A) ) $(#;	) )
 |) ) )	
r!   otherobjectr   c                    t          |t                    rP| j        |j        k    o?| j        |j        k    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S t          S ri   )r   r   r(   r=   r>   r?   r   NotImplemented)rC   r   s     r"   __eq__z_ConfigFile.__eq__  s}    e[)) 	 E$55 2*e.EE2/53OO2 ,0II2 LEM1 r!   intc                r    t          | j        j        | j        | j        | j        | j        | j        f          S ri   )hashr   r   r(   r=   r>   r?   r   rJ   s    r"   __hash__z_ConfigFile.__hash__  s>    N'"'$L
   	r!   N)r(   r   r=   r   r>   r   r?   r   r   r   r7   r8   )r7   r-   )r   r   r7   r   )r7   r   )r   r   r   	__slots__rE   r   r   r   r    r!   r"   r   r     sk        I6 6 6 6
 
 
 
	 	 	 	     r!   argvr'   r   c           	     t   | d d         dgk    rt          d          | dd          } t          |           dk    rt          d           t          d          t          | d                                                   }|t
          z  }|                                r|                                st          |d           dS t          |          }|	                    d          st          d           dS |
                    ddd 	          }|st          d
           dS dd| dg}|
                    ddd	          }|s|                    d           nx|durt|                    d           |                    d t          t          j        |                    d                    D                        |                    d           |
                    ddd	          }|s|                    d           nh|durd|                    d           |d t          t          j        |                    d                    D             z  }|                    d           g }|
                    ddd	          }	|	dur|                    d|	 d           |
                    ddd	          }
|
dur|                    d|
 d           |r.|                    dd                    |          z   dz              |	                    d           rN|                    d!           |                    d"           |fd#|                    d           D             z  }|t&          z  }|                    d$                    |          d$z   d%&           t          d'|           dS )(N   conf_to_tomlr   z9Usage: python -m sphinx.theming conf_to_toml <theme path>zC must be a path to a theme directory containing a "theme.conf" filer   zThe "theme" table is missing.r&   r   z'The "theme.inherit" setting is missing.z[theme]zinherit = ""rN   .zstylesheets = []zstylesheets = [c              3  "   K   | ]
}d | dV  dS )    "",Nr    r   r   s     r"   	<genexpr>z(_migrate_conf_to_toml.<locals>.<genexpr>   s*      WWA-!---WWWWWWr!   r   ]r)   zsidebars = []zsidebars = [c                    g | ]}d | d	S )r  r	  r    r
  s     r"   
<listcomp>z)_migrate_conf_to_toml.<locals>.<listcomp>  s     QQQ}q}}}QQQr!   r+   zdefault = "rP   zdark = "zpygments_style = { rO   z }r   r   z	[options]c                Z    g | ]'\  }}|                     d d          xs	 	 | d d (S )r  z\"Tz = ")replace)r   keyr.   ds      r"   r  z)_migrate_conf_to_toml.<locals>.<listcomp>  sa     
 
 
W__S%000
 6:

 
 
r!   
r   r   zWritten converted settings to )
SystemExitlenprintr   r   r   r   r   r   r   rR   r   extendrI   r-   r   r   rQ   r\   r   
write_text)r  r   r   r   r&   
toml_linesrN   r   stylesr.   r/   r   r  s               @r"   _migrate_conf_to_tomlr    s   BQBxN###mm8D
4yyA~~IJJJmmT!W%%''IK'I Y%6%6%8%8 ___	
 	
 	
 q"9--K""7++ -...qoogy4o@@G 7888q 	 g   J
 ,EEJ ,----	3		+,,,WWSY
@P@PQT@U@U1V1VWWWWWW#oogzCo@@G /****			.)))QQc#)W]]3=O=O.P.PQQQQ
#Foog'7#oFFGc.G...///??7$9C?HHD3(((())) L/$))F2C2CCdJKKKy)) 
"+&&& 
 
 
 
 + 1 1) < <
 
 
 	

 K'I:..5HHH	
89
8
89991r!   __main__r  )r   r   r7   r   )r1   r-   r|   r   r   r   r7   r   )r1   r-   r   r   r7   r   )r   r   r   r   r7   r8   )r   r   r7   r   )r   r   r1   r-   r7   r-   )r   r   r7   r   )r   r   r7   r   )r   r   r1   r-   r7   r-   )r   r   r7   r   )r  r'   r7   r   )Brk   
__future__r   __all__r   rb   re   sysr   r   importlib.metadatar   pathlibr   typingr   zipfiler	   sphinxr
   sphinx.configr   r   sphinx.errorsr   sphinx.localer   sphinx.utilr   sphinx.util._pathlibr   sphinx.util.osutilr   collections.abcr   r   r   r   sphinx.applicationr   r   r%   r*   	getLoggerr   r]   r   rS   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r    r!   r"   <module>r.     s   ( ( " " " " " "
'          



   + + + + + +                               B B B B B B $ $ $ $ $ $             ) ) ) ) ) ) ( ( ( ( ( ( ((((((//////////))))))         Ye        0 0 0 0 0)5 0 0 0 0    )5    
 
	8	$	$fhh[' [' [' [' [' [' [' ['|WP WP WP WP WP WP WP WPt   %( %( %( %(P/ / / /6
2 
2 
2 
2= = = =
   &   8         :4 4 4 4 4 4 4 4nB B B BJ z
***38ABB<88
9
99 r!   