
    ~Ti:Q                       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
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! ddl"m#Z# erIddl$m%Z% ddlm&Z&m'Z'm(Z( ddl)m*Z* ddlm+Z+ ddl,m-Z-  G d de(d      Z. G d de(d      Z/ G d de(d      Z0 ejb                  e2      Z3 e4       Z5dZ6dZ7 G d  d!      Z8 G d" d#      Z9d3d$Z:	 	 	 	 	 	 	 	 d4d%Z;	 	 	 	 	 	 d5d&Z<d6d'Z=d7d(Z>d8d)Z?d9d+Z@d:d,ZAd;d-ZBd<d.ZC G d/ d*      ZDd=d0ZEe2d1k(  r eF eEej                  d2d             y)>z"Theming support for HTML builders.    )annotations)ThemeHTMLThemeFactoryN)entry_points)Path)TYPE_CHECKING)ZipFile)package_dir)check_confval_types)RemovedInSphinx10Warning)
ThemeError)__)logging)_StrPath)	ensuredir)Callable)AnyRequired	TypedDict)Sphinx)Config)SphinxComponentRegistryc                  "    e Zd ZU ded<   ded<   y)
_ThemeTomlzRequired[_ThemeTomlTheme]themedict[str, str]optionsN__name__
__module____qualname____annotations__     A/home/agent/.local/lib/python3.12/site-packages/sphinx/theming.pyr   r   $   s    ((r$   r   F)totalc                  6    e Zd ZU ded<   ded<   ded<   ded<   y)	_ThemeTomlThemezRequired[str]inherit	list[str]stylesheetssidebars_ThemeTomlThemePygmentspygments_styleNr   r#   r$   r%   r(   r(   (   s    //r$   r(   c                  "    e Zd ZU ded<   ded<   y)r-   strdefaultdarkNr   r#   r$   r%   r-   r-   .   s    	r$   r-   z
theme.tomlz
theme.confc                  R    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZd	dZefd
dZdddZddZ	y)r   zA Theme is a set of HTML templates and configurations.

    This class supports both theme directory and theme archive (zipped theme).
    c                  || _         t        |      | _        || _        i }d| _        d| _        d | _        d | _        t        |j                               D ]  }||j                  z  }|j                  |j                  | _        |j
                  |j
                  | _        |j                  |j                  | _        |j                  v|j                  | _         || _        y )Nr#   )nametuple_dirs	_tmp_dirsr+   sidebar_templatespygments_style_defaultpygments_style_darkreversedvaluesr   _options)selfr5   configspathstmp_dirsr   configs          r%   __init__zTheme.__init__@   s     	5\
!"$,.2426#/3 w~~/0 		FFv~~%G!!-#)#5#5 ''3)/)A)A&,,8.4.K.K+))5+1+E+E(		F  r$   c                H    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   r7   r?   s    r%   get_theme_dirszTheme.get_theme_dirs^   s     C$**-..r$   c                   |dk(  ry|dk(  r dj                  | j                        xs |}n|dk(  r dj                  | j                        xs |}ng|dk(  r| j                  xs |}nQ|dk(  r| j                  xs |}n;|}n8|dk(  r| j
                  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+   r9   r:   r;   r>   getr   r   _NO_DEFAULT)r?   sectionr5   r1   valuemsgs         r%   
get_configzTheme.get_configd   s     g|#		$"2"23>w#		$"8"89DW))33>w..00;G	!MM%%dG4EDC S/!KQRV C S/!r$   Nc                    |i }| j                   j                         }|j                         D ].  \  }}||vr t        j	                  t        d      |       *|||<   0 |S )z6Return a dictionary of theme options and their values.z!unsupported theme option %r given)r>   copyitemsloggerwarningr   )r?   	overridesr   optionrR   s        r%   get_optionszTheme.get_options   se    I--$$&&__. 	(MFEW$r"EFO"'		( r$   c                    | j                   D ]9  }t        j                  t              5  t	        j
                  |       ddd       ; y# 1 sw Y   FxY w)zRemove temporary directories.N)r8   
contextlibsuppress	Exceptionshutilrmtree)r?   tmp_dirs     r%   _cleanupzTheme._cleanup   sI    ~~ 	'G$$Y/ 'g&' '	'' 's   A

A	)
r5   r0   r@   zdict[str, _ConfigFile]rA   
list[Path]rB   re   returnNone)rf   zlist[_StrPath])rQ   r0   r5   r0   r1   r   rf   r   N)rZ   zdict[str, Any] | Nonerf   zdict[str, Any]rf   rg   )
r   r    r!   __doc__rD   rI   rP   rT   r\   rd   r#   r$   r%   r   r   :   sW    
   (	 
     
 </ BM >'r$   r   c                  p    e Zd ZdZ	 d
ddddd	 	 	 	 	 	 	 	 	 	 	 ddZddZddZddZedd       Z	dd	Z
y)r   z A factory class for HTML Themes.N)confdirapprC   registryc              x   |Bt        j                  dt        d       |}|j                  }|j                  }|j
                  }|J |J |J |J || _        || _        |j                  | _	        i | _
        | j                          t        |dd       x}r| j                  |       | j                          y )NzPositional parameters for HTMLThemeFactory are deprecated, and will be removed in Sphinx 10. Please use keyword parameters instead.   )category
stacklevelhtml_theme_path)warningswarnr   rl   rC   rn   _app_confdirhtml_themes_themes_entry_point_themes_load_builtin_themesgetattr_load_additional_themes_load_entry_point_themes)r?    _deprecated_positional_parameterrl   rm   rC   rn   rs   s          r%   rD   zHTMLThemeFactory.__init__   s     ,7MM9 2 3CkkGZZF||H"""!!!###	++BD !!#%f.?FF?F((9%%'r$   c                    | j                  t        dz        }|j                         D ]  \  }}t        |      | j                  |<    y)zLoad built-in themes.themesN)_find_themesr
   rW   r   ry   )r?   r   r5   r   s       r%   r{   z%HTMLThemeFactory._load_builtin_themes   sB    "";#9:!<<> 	1KD%!)%DLL	1r$   c                    |D ]`  }| j                   |z  j                         }| j                  |      }|j                         D ]  \  }}t	        |      | j
                  |<    b y)z7Load additional themes placed at specified directories.N)rw   resolver   rW   r   ry   )r?   theme_paths
theme_pathabs_theme_pathr   r5   r   s          r%   r}   z(HTMLThemeFactory._load_additional_themes   sc    % 	5J"mmj8AACN&&~6F%||~ 5e%-e_T"5	5r$   c                    t        d      D ]T  }|j                  | j                  v r| j                  |j                  f	 	 	 	 	 dd}|| j
                  |j                  <   V y)zTry to load a theme with the specified name.

        This uses the ``sphinx.html_themes`` entry point from package metadata.
        zsphinx.html_themes)groupc                R    | j                  |       t        | | j                         y rh   )setup_extension_config_post_initrC   )rm   theme_modules     r%   _load_theme_closurezFHTMLThemeFactory._load_entry_point_themes.<locals>._load_theme_closure   s     
 ##L1!#szz2r$   N)rm   r   r   r0   rf   rg   )r   r5   ry   rv   modulerz   )r?   entry_pointr   s      r%   r~   z)HTMLThemeFactory._load_entry_point_themes   s|    
 (.BC 	MK4<</ #ii$/$6$633 "3 	3 :MD$$[%5%56	Mr$   c                   i }| j                         s|S | j                         D ]  }|j                  }|j                         rX|j                  j                         dk(  r;t        |      r|||j                  <   Wt        j                  t        d      |       w|t        z  }|t        z  }|j                         s|j                         s|||<    |S )z'Search themes from specified directory.z.zipzAfile %r on theme path is not a valid zipfile or contains no theme)is_diriterdirr5   is_filesuffixlower_is_archived_themestemrX   rY   r   _THEME_TOML_THEME_CONF)r   r   pathnameentry	toml_path	conf_paths         r%   r   zHTMLThemeFactory._find_themes   s     #%  "M"**, 	-HMME!hoo&;&;&=&G%h/,4F8==)NN;  %{2	${2	$$&)*;*;*=$,F5M#	-& 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?))r@   rA   rB   )rz   ry   r   r   _load_theme_with_ancestorsr   )r?   r5   entry_point_loaderr   
theme_dirsrB   s         r%   createzHTMLThemeFactory.create   s    4+++!%!9!9$!? t||#R OPSWWXX'ALL$$(
$
H
 T6hOOr$   rh   )r   Sphinx | Nonerl   zPath | Nonerm   r   rC   zConfig | Nonern   zSphinxComponentRegistry | Nonerf   rg   ri   )r   r*   rf   rg   )r   r   rf   zdict[str, Path])r5   r0   rf   r   )r   r    r!   rj   rD   r{   r}   r~   staticmethodr   r   r#   r$   r%   r   r      s    * ;?!(
  $! $37!(*7!(
 !( !( !( 1!( 
!(F15M&  6Pr$   r   c                   	 t        |       5 }t        |j                               }t        |v xs t        |v cddd       S # 1 sw Y   yxY w# t
        $ r Y yw xY w)zBCheck whether the specified file is an archived theme file or not.NF)r	   	frozensetnamelistr   r   r`   )filenamefr   s      r%   r   r     s_    X 	F! .H(*EkX.E	F 	F 	F  s-   A +A	A AA A 	AAc          	        i }g }g }t        d      D ]  }t        | ||          \  }}}	}
|j                  |       |	|j                  |	       |
|| <   |dk(  r n||v rt        d      | z  }t	        |      ||v r||vr||   } |        ||vr4t        d      | |dj                  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: %srL   z#The %r theme has too many ancestors)range_load_themeappendr   r   rN   sorted)r5   r   entry_point_themesr   r   rB   _r)   	theme_dirrc   rC   rS   r   s                r%   r   r     s*    &(FJH 2Y .9$D@Q.R+GV)$OOG$tff<=DCS/!((WK-G!3G!< +%( w		&*= >?@C S/!+. 67$>o:x''r$   c                  |j                         rd }|}n/t        t        j                  d            }|| z  }t	        ||       |t
        z  x}j                         r#t        |      }t        ||       }t        |      }nS|t        z  x}j                         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   )
r5   r   rc   r   r   
_cfg_tabler)   rC   r   _cfg_parsers
             r%   r   r   >  s     	 x''./dN	Z+,,	557%i0
&z48$Z0 ;.
.)	7	7	9&y1&{D9$[1EFRSSIw..r$   c                  t        |       t        |       5 }|j                         D ]N  }|j                  d      r||z  }t        |j                         |j                  |j                  |             P 	 ddd       y# 1 sw Y   yxY w)z%Extract zip file to target directory./N)r   r	   r   endswithparentwrite_bytesread)r   
target_dirarchiver5   r   s        r%   r   r   Y  s}    j		 2g$$& 	2D}}S!%Eell#gll401	22 2 2s   A"BBc                   t        j                  | j                  d            }dD ci c]  }||v s|||    c}S c c}w )Nutf-8encoding)r   r   )tomllibloads	read_text)config_file_pathcss      r%   r   r   f  sA    &00'0BCA1<Q!VAqtG<<<s   	??c                V   d| vrt        d      |z  }t        |      | d   }t        |t              st        d      |z  }t        |      |j	                  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dictrO   )cfgr5   rS   r   r)   s        r%   r   r   k  s    c;<tCoLEeT">?$Foii	2&GGH4OoC#i.$/DELCS/!Nr$   _ConfigFilec          
     f   | d   }d|v rt        |d         }nd }d|v rt        |d         }nd }|j                  di       }t        |t              rd| d}t	        d      |z  }t        |      |j                  d      }|j                  d	      }t        ||||| j                  d
i             S )Nr   r+   r,   r.   zpygments_style = { default = "z" }z>The "theme.pygments_style" setting must be a table. Hint: "%s"r1   r2   r   r+   r9   r:   r;   r   )r6   rO   r   r0   r   r   r   )	r   r   r+   r9   pygments_tablehintrS   r:   r;   s	            r%   r   r   ~  s    LE.3E-4H.IU49%
:K4L YY/4N.#&00@EOPSWW 	 o)7););I)F&4&8&8&@+5/	2& r$   c               T    t        j                         }|j                  | d       |S )Nr   r   )configparserRawConfigParserr   )r   r   s     r%   r   r     s&    $$&AFFgF.Hr$   c                    | j                  d      st        t        d      |z        | j                  ddd       x}r|S t        d      |z  }t        |      )Nr   r   r)   fallbackr   )has_sectionr   r   rO   )r   r5   r)   rS   s       r%   r   r     s]    ??7#FG$NOO'''9t'<<w<
C
Dt
KC
S/r$   c                  | j                  ddd      x}r3t        t        t        j                  |j                  d                  }nd }| j                  ddd      x}r3t        t        t        j                  |j                  d                  }nd }| j                  ddd       }| j                  ddd       }| j                  d	      rt        | j                  d	            ni }t        |||||
      S )Nr   rK   r   r   ,r,   r.   rM   r   r   )
rO   r6   rG   r0   stripsplitr   r   rW   r   )r   rK   r+   sidebarr9   r:   r;   r   s           r%   r   r     s   WWWlRW@@z@.3		:++C01/
 ''':';;w;49		7==-.5
 !),!D *1 * '*gg& '. ' -0OOI,Fd399Y'(BG+5/ r$   c                  H    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 ddZddZd	dZd
dZy)r   r   c                f    || _         || _        || _        || _        |j	                         | _        y rh   )r+   r9   r:   r;   rV   r   )r?   r+   r9   r:   r;   r   s         r%   rD   z_ConfigFile.__init__  s1     4?9J2H#/B '.||~r$   c                    | 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+   r9   r:   r;   r   rH   s    r%   __repr__z_ConfigFile.__repr__  sr    ~~**+ ,++. /!!%!7!7 : ;&&*&A&A%D E##'#;#;"> ?||&a)	
r$   c                8   t        |t              r| j                  |j                  k(  xrj | j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j
                  |j
                  k(  xr | j                  |j                  k(  S t        S rh   )r   r   r+   r9   r:   r;   r   NotImplemented)r?   others     r%   __eq__z_ConfigFile.__eq__  s    e[)  E$5$55 2**e.E.EE2//53O3OO2 ,,0I0II2 LLEMM1 r$   c                    t        | j                  j                  | j                  | j                  | j
                  | j                  | j                  f      S rh   )hashr   r!   r+   r9   r:   r;   r   rH   s    r%   __hash__z_ConfigFile.__hash__  sL    NN''""''$$LL
  	r$   N)r+   tuple[str, ...] | Noner9   r   r:   
str | Noner;   r   r   r   rf   rg   )rf   r0   )r   objectrf   bool)rf   int)r   r    r!   	__slots__rD   r   r   r   r#   r$   r%   r   r     sW    I6+6 26 !+	6
 (6  6 
6
	r$   c           	     |   | d d dgk7  rt        d      | dd  } t        |       dk7  rt        d       t        d      t        | d         j	                         }|t
        z  }|j                         r|j                         st        |d       yt        |      }|j                  d      st        d       y|j                  ddd 	      }|st        d
       ydd| dg}|j                  ddd	      }|s|j                  d       ne|dura|j                  d       |j                  d t        t        j                  |j!                  d            D               |j                  d       |j                  ddd	      }|s|j                  d       nd|dur`|j                  d       |t        t        j                  |j!                  d            D cg c]  }d| d
 c}z  }|j                  d       g }	|j                  ddd	      }
|
dur|	j                  d|
 d       |j                  ddd	      }|dur|	j                  d| d       |	r&|j                  ddj#                  |	      z   d z          |j                  d!      rd|j                  d"       |j                  d#       ||j%                  d!      D 
cg c]"  \  }}
|
j'                  dd$      x}s	 | d%| d$ c}
}z  }|t(        z  }|j+                  d&j#                  |      d&z   d'(       t        d)|       yc c}w c c}
}w )*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 = ""rK   .zstylesheets = []zstylesheets = [c              3  (   K   | ]
  }d | d  yw)    "",Nr#   ).0r   s     r%   	<genexpr>z(_migrate_conf_to_toml.<locals>.<genexpr>  s     WAE!B-Ws   r   ]r,   zsidebars = []zsidebars = [r  r  r.   zdefault = "rM   zdark = "zpygments_style = { rL   z }r   r   z	[options]z\"z = "
r   r   zWritten converted settings to )
SystemExitlenprintr   r   r   r   r   r   r   rO   r   extendrG   r0   r   r   rN   rW   replacer   
write_text)argvr   r   r   r)   
toml_linesrK   r   r   stylesr1   r2   keydr   s                  r%   _migrate_conf_to_tomlr    s<   BQxN##m8D
4yA~IJmT!W%%'IK'IY%6%6%8m^_	
 "9-K""7+-.oogy4o@G78 	
gYa J
 ,EJ,-	3	+,WSYY
@P@PQT@U1VWW#oogzCo@G/*		.)c#))W]]3=O.PQqc}QQ
#Foog'7#oFGcG9A./??7$9C?HD3a()/$))F2CCdJKy)"+& + 1 1) <
W__S%000T e4s!
 	

 K'I:.5H	*9-
893 R 
s   L3	'L8__main__r   )r   r   rf   r   )r5   r0   r   zdict[str, _StrPath]r   zdict[str, Callable[[], None]]rf   z5tuple[dict[str, _ConfigFile], list[Path], list[Path]])r5   r0   r   r   rf   z*tuple[str, Path, Path | None, _ConfigFile])r   r   r   r   rf   rg   )r   r   rf   r   )r   r   r5   r0   rf   r0   )r   r   rf   r   )r   r   rf   configparser.RawConfigParser)r   r  r5   r0   rf   r0   )r   r  rf   r   )r  r*   rf   r   )Hrj   
__future__r   __all__r   r^   ra   sysr   r   rt   importlib.metadatar   pathlibr   typingr   zipfiler	   sphinxr
   sphinx.configr   r   sphinx.deprecationr   sphinx.errorsr   sphinx.localer   sphinx.utilr   sphinx.util._pathlibr   sphinx.util.osutilr   collections.abcr   r   r   r   sphinx.applicationr   r   sphinx.registryr   r   r(   r-   	getLoggerr   rX   r   rP   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r#   r$   r%   <module>r+     st   ( "
'    
    +      B 7 $   ) ((//)$7 Ye  0)5 0)5 
 
		8	$h[' ['|qP qPh%(
%($%( 6%(
 ;%(P/
////6
2=
&8:4 4nBJ z
*388AB<8
99 r$   