o $a!@sdZddlZddlZddlZddlZddlmZddlmZmZm Z m Z ddl m Z ddl Z ddlmZddlmZddlmZdd lmZdd lmZerTdd lmZeeZeZd Zd e de ddfddZ!GdddZ"d e de#fddZ$GdddZ%dS)z sphinx.theming ~~~~~~~~~~~~~~ Theming support for HTML builders. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)path) TYPE_CHECKINGAnyDictList)ZipFile) package_dir) ThemeError)__)logging) ensuredir)Sphinxz theme.conffilename targetdirreturnc Cst|t|C}|D]5}|drq t||}tt|tt|d}|| |Wdn1s=wYq WddS1sNwYdS)z%Extract zip file to target directory./wbN) r rnamelistendswithrjoindirnameopenwriteread)rrarchivenameentryfpr0/usr/lib/python3/dist-packages/sphinx/theming.py extract_zip%s    "r c @seZdZdZdededdddfdd Zdeefd d Zefd eded e de fddZ ifde ee fde ee ffddZ dddZ dS)ThemezA Theme is a set of HTML templates and configurations. This class supports both theme directory and theme archive (zipped theme).r theme_pathfactoryHTMLThemeFactoryrNc Cs*||_d|_d|_t|rd|_||_ntd|_t|j||_t ||jt |_ |j t|jtz |j dd}Wn+t jyX}z ttd||d}~wt jym}z ttd||d}~ww|dkrz |||_WdSty}z ttd||f|d}~wwdS)Nsxtthemeinheritz%theme %r doesn't have "theme" settingz'theme %r doesn't have "inherit" settingnonez(no theme named %r found, inherited by %r)rbaserootdirrisdirthemedirtempfilemkdtemprr configparserRawConfigParserconfigr THEMECONFgetNoSectionErrorr r NoOptionErrorcreate)selfrr"r#r'excrrr__init__8s@    zTheme.__init__cCs$|jdur |jgS|jg|jS)zReturn a list of theme directories, beginning with this theme's, then the base theme's, then that one's base theme's, etc. N)r)r,get_theme_dirsr7rrrr:Xs zTheme.get_theme_dirssectiondefaultc Csz|j||WStjtjfy@}z(|jr%|j|||WYd}~S|tur4tt d||f||WYd}~Sd}~ww)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) r1r3r/r5r4r) get_config NODEFAULTr r )r7r<rr=r8rrrr>aszTheme.get_config overridescCs||jr |j}ni}z ||jdWn tjy Ynw|D]\}}||vr7tt d|q%|||<q%|S)z6Return a dictionary of theme options and their values.optionsz!unsupported theme option %r given) r) get_optionsupdater1itemsr/r4loggerwarningr )r7r@rAoptionvaluerrrrBqs  zTheme.get_optionscCsB|jrzt|jWn tyYnw|jr|jdSdS)zRemove temporary directories.N)r*shutilrmtree Exceptionr)cleanupr;rrrrLs z Theme.cleanuprN)__name__ __module__ __qualname____doc__strr9rr:r?rr>rrBrLrrrrr!3s  &r!cCsRzt|}t|vWdWS1swYWdSty(YdSw)zBCheck whether the specified file is an archived theme file or not.NF)rr2rrK)rfrrris_archived_themes  ( rTc@seZdZdZdddZddd Zd eddfd d Zd eddfddZdddZ dddZ d eddfddZ dede eeffddZ d edefddZdS)r$z A factory class for HTML Themes.appr rNcCs<||_|jj|_|t|jddr||jjdSdS)Nhtml_theme_path) rUregistry html_themesthemesload_builtin_themesgetattrr1load_additional_themesrV)r7rUrrrr9s  zHTMLThemeFactory.__init__cCs2|ttd}|D] \}}||j|<q dS)zLoad built-in themes.rYN) find_themesrrrrDrY)r7rYrr&rrrrZs z$HTMLThemeFactory.load_builtin_themes theme_pathscCsJ|D] }tt|jj|}||}|D] \}}||j|<qqdS)z7Load additional themes placed at specified directories.N)rabspathrrUconfdirr]rDrY)r7r^r"abs_theme_pathrYrr&rrrr\s  z'HTMLThemeFactory.load_additional_themesrcCs"|dkr |dS||dS)z,Try to load a theme with the specified name. alabasterN)load_alabaster_themeload_external_themer7rrrrload_extra_themes z!HTMLThemeFactory.load_extra_themecCs"ddl}t|d|jd<dS)zLoad alabaster theme.rNrb)rbrrget_pathrY)r7rbrrrrcsz%HTMLThemeFactory.load_alabaster_themecCs>zddl}|}t|d|jd<WdStyYdSw)z+Load sphinx_rtd_theme theme (if installed).rNsphinx_rtd_theme)rhget_html_theme_pathrrrY ImportError)r7rhr"rrrload_sphinx_rtd_themes z&HTMLThemeFactory.load_sphinx_rtd_themecCsDtd|}zt|}|jj|j|jWdSty!YdSw)zjTry to load a theme using entry_points. Sphinx refers to ``sphinx_themes`` entry_points. zsphinx.html_themesN) pkg_resourcesiter_entry_pointsnextrUrWload_extension module_name StopIteration)r7r entry_points entry_pointrrrrds  z$HTMLThemeFactory.load_external_themer"cCsi}t|s |St|D]9}t||}t|r:|dr:t|r1|dd}|||<qt t d|qtt|t rG|||<q|S)z'Search themes from specified directory.z.zipNzAfile %r on theme path is not a valid zipfile or contains no theme) rr+oslistdirrisfilelowerrrTrErFr r2)r7r"rYrpathnamerrrrr]s      zHTMLThemeFactory.find_themescCsj||jvr ||||jvr|dkrttd|||jvr+ttd|t||j||dS)zCreate an instance of theme.rhzKsphinx_rtd_theme (< 0.3.0) found. It will not be available since Sphinx-6.0z-no theme named %r found (missing theme.conf?))r#)rYrfrErFr rkr r!rerrrr6s   zHTMLThemeFactory.create)rUr rNrM)rNrOrPrQr9rZrRr\rfrcrkrdrr]r!r6rrrrr$s     r$)&rQr/rurIr-rtypingrrrrzipfilerrlsphinxr sphinx.errorsr sphinx.localer sphinx.utilr sphinx.util.osutilr sphinx.applicationr getLoggerrNrEobjectr?r2rRr r!boolrTr$rrrrs.          ]