o
    Ni                     @  s  U 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Zddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZmZ 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mZ ddlmZ ddlm Z m!Z! ddlm"Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZD ddlEmFZF ddlGmHZH ddlImJZJ ddlKmLZL dd lMmNZN dd!lOmPZPmQZQ dd"lRmSZS dd#lTmUZU dd$lVmWZW dd%lXmYZY dd&lZm[Z[m\Z\m]Z] dd'l^m_Z_m`Z`maZambZbmcZcmdZd dd(lemfZf dd)lgmhZh erddd*limjZjmkZk dd+lmlZl dd,lmmnZn dd-lompZp dd.lqmrZr dd/lsmtZt dd0lumvZv d1ZweHxeyZze{d2Z|e}e~ee2 ee}e~ee3 f  ef Zd3ed4< djd8d9ZG d:d; d;e%ZdkdAdBZdkdCdDZdldLdMZdmdNdOZdkdPdQZdkdRdSZdkdTdUZdkdVdWZdkdXdYZdnd[d\Zdod^d_Ze'd`dafe)dbdafdcZddede< dpdhdiZdS )qzSeveral HTML builders.    )annotationsN)path)Path)TYPE_CHECKINGAnyquote)nodes)	Publisher)OptionParser)DocTreeInputStringOutput)relative_path)__display_version__package_dir)version_info)Builder)_CascadingStyleSheet_file_checksum_JavaScript)	BuildInfo)ENUMConfig_deprecation_warning)Index
IndexEntry)ImageAdapter)IndexEntries)document_tocglobal_toctree_for_doc)ConfigError
ThemeError)PygmentsBridge)___)js_index)HTMLThemeFactory)logging)_format_rfc3339_microseconds)is_url)bold)progress_messagestatus_iterator)new_document)
copy_asset)format_date)InventoryFile)DOTFILESMatcherpatmatch)SEP_last_modified_timecopyfile	ensurediros_pathrelative_uri)
HTMLWriter)HTML5Translator)IteratorSet)	TypeAlias)Node)Reader)Sphinx)BuildEnvironment)ExtensionMetadatazobjects.invz[
]+r?   DOMAIN_INDEX_TYPElocale
str | Nonereturnc                 C  s   | r|  ddS dS )zdConvert a locale string to a language tag (ex. en_US -> en-US).

    refs: BCP 47 (:rfc:`5646`)
    r$   -N)replace)rF    rK   Q/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/builders/html/__init__.pyconvert_locale_to_language_tag_   s   rM   c                      s  e Zd ZU dZdZdZedZeZ	dZ
dZdZdZeZded< dZdZg dZdZdZd	ZdZdZd
ZdZd
ZdZdZded< g Zded< d fddZdddZ dddZ!dddZ"dd d!Z#dd#d$Z$dd%d&Z%dd'd(Z&e'dd*d+Z(dd,d-Z)dd0d1Z*e'dd3d4Z+dd5d6Z,dd7d8Z-e'dd:d;Z.dd<d=Z/dd?d@Z0ddDdEZ1ddHdIZ2ddNdOZ3ddPdQZ4ddTdUZ5ddVdWZ6ddXdYZ7e8edZdd[d\Z9dd]d^Z:e8ed_dd`daZ;ddbdcZ<ddddeZ=ddfdgZ>ddhdiZ?ddjdkZ@ddldmZAddndoZBddqdrZCddsdtZDddudvZEddwdxZFddydzZGdd{d|ZHdd}d~ZIdddZJd fddZKdddZLdddZM	ddddZNdddZOdddZPddddZQ			ddddZRdddZSdddZTe8eddddZUdddZV  ZWS )StandaloneHTMLBuilderz&
    Builds standalone HTML docs.
    htmlz!The HTML pages are in %(outdir)s.Tz.htmlr   indexer_format)zimage/svg+xmlz	image/pngz	image/gifz
image/jpegzsearchindex.jsF strimgpathzlist[DOMAIN_INDEX_TYPE]domain_indicesapprB   envrC   rH   Nonec                   s`   t  || g | _g | _tjjjdd}t||j	t
| ttddd}|jddd || _d S )Nrestructuredtext)parser_nameunicodeencoding)readerparserwritersource_classdestinationT)output_encoding	traceback)super__init__
_css_files	_js_filesdocutilsreadersdoctreerA   r
   r^   r;   r   r   get_settings
_publisher)selfrU   rV   r]   pub	__class__rK   rL   re      s   
zStandaloneHTMLBuilder.__init__c                 C  s   |   | _d| _i | _d| _|   |   |   |   | 	dd}|d ur+|| _
| 	dd}|d ur9|| _n| j
| _| 	dd| _d S )N_imagesrQ   file_suffixrO   link_suffix	use_index)create_build_info
build_infoimagedir
secnumberscurrent_docnameinit_templatesinit_highlighterinit_css_filesinit_js_filesget_builder_config
out_suffixrs   rt   )rm   html_file_suffixhtml_link_suffixrK   rK   rL   init   s    
zStandaloneHTMLBuilder.initr   c                 C  s   t | j| jtdhS )NrO   )r   configtags	frozensetrm   rK   rK   rL   ru         z'StandaloneHTMLBuilder.create_build_infoc                   sb    fdd j jD ttd j jddttjd j jdg }|D ]}t|r.|  S q#dS )Nc                   s    g | ]}t | jjd dqS )LC_MESSAGES	sphinx.js)r   joinr   language).0dirr   rK   rL   
<listcomp>   s    z>StandaloneHTMLBuilder._get_translations_js.<locals>.<listcomp>rF   r   r   zshare/sphinx/localerQ   )	r   locale_dirsr   r   r   r   sysprefixisfile)rm   
candidatesjsfilerK   r   rL   _get_translations_js   s    

z*StandaloneHTMLBuilder._get_translations_jsIterator[str]c                 c  s^    t | jjtr| jjV  d S | jjd ur| jjE d H  d S | jr*| jjE d H  d S dV  d S )Nzdefault.css)
isinstancer   
html_stylerR   themestylesheetsr   rK   rK   rL   _get_style_filenames   s   
z*StandaloneHTMLBuilder._get_style_filenames'tuple[str, dict[str, str | int | bool]]c                 C  s   | j j| j jfS N)r   
html_themehtml_theme_optionsr   rK   rK   rL   get_theme_config      z&StandaloneHTMLBuilder.get_theme_configc                 C  sD   t | j}|  \}}||| _|| _|   | j| | j d S r   )	r'   rU   r   creater   theme_optionscreate_template_bridge	templatesr   )rm   theme_factory
theme_namer   rK   rK   rL   rz      s   
z$StandaloneHTMLBuilder.init_templatesc                 C  s   | j jd ur| j j}n| jr| jjpd}nd}td|| _| jr%| jj}nd }|  |d ur>td|| _| jj	dddd d S d | _d S )NnonesphinxrO   pygments_dark.cssz(prefers-color-scheme: dark)pygments_dark_css)mediaid)
r   pygments_styler   pygments_style_defaultr#   highlighterpygments_style_darkdark_highlighterrU   add_css_file)rm   style
dark_stylerK   rK   rL   r{      s$   



z&StandaloneHTMLBuilder.init_highlighterlist[_CascadingStyleSheet]c                 C  s   t t| jj ddd | jS )Nz
.css_files	   r   remove)r   __name__rp   rf   r   rK   rK   rL   	css_files  s   zStandaloneHTMLBuilder.css_filesc                 C  s   g | _ | jddd |  D ]	}| j|dd q| jjjD ]\}}| j|fi | q| ddD ]\}}|dd | j|fi | q1d S )Npygments.css   priorityr   rO   r      )rf   r   r   rU   registryr   r~   
setdefaultrm   filenameattrsrK   rK   rL   r|     s   z$StandaloneHTMLBuilder.init_css_filesr   kwargsc                 K  sB   d|vr
t d|}t|fi | }| jvr| j| d S d S N://_static)	posixpathr   r   rf   appendrm   r   r   assetrK   rK   rL   r     s
   z"StandaloneHTMLBuilder.add_css_filelist[_JavaScript]c                 C  s"   | j j d}tt|dd | jS )Nz.script_filesr   r   )rp   r   r   rg   )rm   canonical_namerK   rK   rL   script_files  s   z"StandaloneHTMLBuilder.script_filesc                 C  s   g | _ | jddd | jddd | jddd | jjjD ]\}}| j|p&dfi | q| ddD ]\}}|d	d
 | j|pBdfi | q3|  rT| d d S d S )Nzdocumentation_options.jsr   r   zdoctools.jszsphinx_highlight.jsrQ   js_filesrO   r   r   translations.js)rg   add_js_filerU   r   r   r~   r   r   r   rK   rK   rL   r}   $  s   z#StandaloneHTMLBuilder.init_js_filesc                 K  sF   |rd|vrt d|}t|fi | }| jvr!| j| d S d S r   )r   r   r   rg   r   r   rK   rK   rL   r   4  s
   z!StandaloneHTMLBuilder.add_js_filerG   c                 C  s\   |  dd}|d ur|S t| jjj}t|dkr|d S t|dkr,|d |d S d S )Nmath_rendererrO      r      mathjax)r~   listrU   r   html_inline_math_rendererslenr   )rm   name	renderersrK   rK   rL   math_renderer_name;  s   
z(StandaloneHTMLBuilder.math_renderer_namec              
   c  s   | j d }zt|}W n" ty' } zttd| W Y d }~nGd }~w ty/   Y n;w | j|krj|	d}zt
|| | j| W n	 tyQ   Y nw td}tttd|  | jjE d H  d S | jrt| j d }zt|}W n	 ty   Y nw ||krttdtd | j  nd}| jjD ]X}|| jjvrtd	| |V  q| |}	zt|	}
W n ty   d}
Y nw z&t| j|}t||}||
krtd
|	t|
t||t| |V  W q ty   Y qw d S )N
.buildinfoz"Failed to read build info file: %rz.buildinfo.bakz9build_info mismatch, copying .buildinfo to .buildinfo.bakzbuilding [html]: i@B zOtemplate %s has been changed since the previous build, all docs will be rebuiltr   z![build target] did not in env: %rz>[build target] targetname %r(%s), template(%s), docname %r(%s))outdirr   load
ValueErrorloggerwarningr%   OSErrorrv   	with_nameshutilmovedumpinfor+   rV   
found_docsr   intnewest_template_mtimer6   	Exceptionnewest_template_nameall_docsdebugget_outfilenamedoc2pathmaxr)   )rm   build_info_fnamerv   excbuild_info_backupmsgtemplate_mtime	old_mtimedocname
targetnametargetmtime	doc_mtimesrcmtimerK   rK   rL   get_outdated_docsO  s   


	

z'StandaloneHTMLBuilder.get_outdated_docs	list[str]c                 C  s   | j j| j j S r   )r   html_extra_pathhtml_static_pathr   rK   rK   rL   get_asset_paths  r   z%StandaloneHTMLBuilder.get_asset_pathsnodeNode | Nonedict[str, str]c                 C  sB   |du rddiS t d}|| | j| | j  | jjjS )z$Utility: Render a lone doctree node.NfragmentrQ   z<partial node>)r.   r   rl   
set_sourcepublishr_   parts)rm   r  docrK   rK   rL   render_partial  s   


z$StandaloneHTMLBuilder.render_partialdocnamesSet[str]c                 C  s(  d | _ | jr&ddlm} | jjp| jj}|| j|| jj| jj	| _ | 
| t| | _t  tjdtd t| jj| jfdd | _W d    n1 sOw   Y  t| jj| j_g | _| jj }rt|tsqd}t|}nd}| jj D ],}|jD ]&}|j d|j }|r||vrq~||  \}	}
|	r| j!|||	|
f q~qy| jj" }d urt#|pt$d	| jj| jj% d
}nd }| jj&pd}| jj'pd}t(|st)*|}t(|st)*|}| j+ | _,g }| j-r|!dt$ddt$df | jD ]\}}}}|j.r|!||j/d|j.f q| j0j1j2D ]\}}| j3|fi | q| j0j1j4D ]\}}| j5|p3dfi | q)t6t78| j9| _:t6t78| j;| _<t6| = }i d| j>d| jj?dt@Ad| jjBd| jjCd|d| jjDd| jjEd| jjEd| jjFd| jjGd| jjHd| jjId| jjJd| jjKd| jjLd| jjMd | jjNi d!| jOd"| jPd#| j;d$tQ| jjd%| j9d&tRd'tSd(tTjUd d) d*|d+|d,| jd-g d.|d/t$d0| jj? d1|d2d| _V| jWr	|  jVd3d4 | jWX| jYZ D O  _V|  jV| jj[O  _Vd S )5Nr   )IndexBuilderignore)categoryT)defaults
componentsread_config_filesFrI   z	%b %d, %Y)r   
local_timerQ   genindexzGeneral IndexIindexembeddedprojectreleaseversionlast_updated	copyright
master_docroot_docuse_opensearch	docstitle
shorttitleshow_copyrightshow_search_summaryshow_sphinx
has_sourceshow_sourcesourcelink_suffixrr   rs   r   r   r   sphinx_versionsphinx_version_tupledocutils_version_info   stylesrellinksbuilderparentslogo_urllogo_altz
Logo of %sfavicon_urlhtml5_doctypec                 S  s   i | ]
\}}d | |qS )theme_rK   )r   keyvalrK   rK   rL   
<dictcomp>(  s    
z9StandaloneHTMLBuilder.prepare_writing.<locals>.<dictcomp>)\indexersearchsphinx.searchr  r   html_search_languager   rV   html_search_optionshtml_search_scorerload_indexerr;   	docwriterwarningscatch_warningsfilterwarningsDeprecationWarningr   settingsget_default_valuesdocsettingsboolhtml_compact_listscompact_listsrT   html_domain_indicesr   r   domainssortedindicesr   generater   html_last_updated_fmtr0   r$   html_last_updated_use_utc	html_logohtml_faviconr*   r   basenamecollect_relations	relationsrt   	shortname	localnamerU   r   r   r   r   r   r   dictfromkeysrf   _orig_css_filesrg   _orig_js_filesr   r  r  return_codes_resubr  r  r  r!  html_use_opensearch
html_titlehtml_short_titlehtml_show_copyrighthtml_show_search_summaryhtml_show_sphinxhtml_copy_sourcehtml_show_sourcelinkhtml_sourcelink_suffixr   rs   rM   r   r+  rh   __version_info__globalcontextr   get_optionsr   itemshtml_context)rm   r  r  langindices_configcheck_namesdomain	index_cls
index_namecontentcollapselu_fmtr  logofaviconr0  	indexnameindexcls_content	_collapsecss_filenamer   js_filenamer/  rK   rK   rL   prepare_writing  s   


	





	
 !#
z%StandaloneHTMLBuilder.prepare_writingr   bodymetatagsdict[str, Any]c                 C  sl  d }}g }| j d dd }| j|}| jj}	|rP|d rPz%| ||d | |	|d  d d}||d |d dtdf W n t	yO   d}Y nw |r|d rz%| ||d | |	|d  d d}||d |d d	td
f W n t	y   d}Y nw |r|d rt
t	 || ||d | |	|d  d d W d   n1 sw   Y  | j|d }|r|d s|r|  |  | jj|}
|
r| |
d nd}t| j|dt|d }| jjr	|| }|| jjkr|| jj7 }nd}| jj|}t| j|| j}| |d }||||||||||| jj| dk|dS )z1Collect items for the template context of a page.Nr0  r   title)linkr  Nnextr   Ppreviousr   rQ   Fr  )r2  prevr  r  metar  r  r0  
sourcenametocdisplay_tocpage_source_suffix)rk  rX  getrV   titlesget_relative_urir  r   r$   KeyError
contextlibsuppresspopreverse
longtitlesrR   r   r   r   rg  ri  metadatar   r   toc_num_entries)rm   r   r  r  r  r  r2  r0  relatedr  
title_noder  source_suffixr  r  self_tocr  rK   rK   rL   get_doc_context.  sx   ""

z%StandaloneHTMLBuilder.get_doc_contextc                 C  s8   | j | j | j | j | j | j | j   d S r   )finish_tasksadd_taskcopy_download_filescopy_static_filescopy_extra_filesr   r   rK   rK   rL   copy_assets~  s   z!StandaloneHTMLBuilder.copy_assetsrj   nodes.documentc                 C  s   t dd}| j|_| jj|i | _| jj|i | _t	| 
|d| _t	| 
|d| _|| _| j|| | j  | jjd }| jj}| |||}| j|||d d S )Nutf-8r[   rq   
_downloadsr  )	event_arg)r   rI  rG  rV   toc_secnumbersr  rx   toc_fignumbers
fignumbersr:   get_target_urirS   dlpathry   rB  writeassemble_partsr  
clean_metar  handle_page)rm   r   rj   ra   r  r  ctxrK   rK   rL   	write_doc  s   

zStandaloneHTMLBuilder.write_docc                 C  sT   t | || j| _| | | jj|}|r| |d nd}| 	||| d S )Nr  rQ   )
r:   r  rw   rS   post_process_imagesrV   r  r  r  
index_page)rm   r   rj   r  r  rK   rK   rL   write_doc_serialized  s
   
z*StandaloneHTMLBuilder.write_doc_serializedc                 C  sR   | j | j | j | j | j | j | j | j | j | j |   d S r   )r  r  gen_indicesgen_pages_from_extensionsgen_additional_pagescopy_image_fileswrite_buildinfohandle_finishr   rK   rK   rL   finish  s   zStandaloneHTMLBuilder.finishzgenerating indicesc                 C  s   | j r|   |   d S r   )rt   write_genindexwrite_domain_indicesr   rK   rK   rL   r    s   z!StandaloneHTMLBuilder.gen_indicesc                 C  s4   | j dD ]}|D ]\}}}| ||| q
qd S )Nhtml-collect-pages)eventsemitr  )rm   pagelistpagenamecontexttemplaterK   rK   rL   r    s
   z/StandaloneHTMLBuilder.gen_pages_from_extensionszwriting additional pagesc                 C  s   | j j D ]\}}tj|d dd | |i | q| jr,tjddd | di d | j jrM| jrOtjddd t	| j
dd	}| jd
i d	|d d S d S d S )N Tnonlzsearch r<  zsearch.htmlzopensearch r   zopensearch.xml
opensearch)outfilename)r   html_additional_pagesrm  r   r   r  r<  ra  r   r   r   )rm   r  r  fnrK   rK   rL   r    s   z*StandaloneHTMLBuilder.gen_additional_pagesc                 C  s   t | j| }dd |D }||| jjd}tjddd | jjrP| d|d | d	|d
 t||ddD ]\\}}}||||d}| d| |d q7d S | d|d
 d S )Nc                 S  s"   g | ]\}}t d d |D qS )c                 s  s&    | ]\}\}}}d t | V  qdS )r   N)r   )r   r$   subitemsrK   rK   rL   	<genexpr>  s   $ zBStandaloneHTMLBuilder.write_genindex.<locals>.<listcomp>.<genexpr>)sum)r   _kentriesrK   rK   rL   r     s    z8StandaloneHTMLBuilder.write_genindex.<locals>.<listcomp>)genindexentriesgenindexcountssplit_indexz	genindex Tr  r  zgenindex-split.htmlzgenindex-allzgenindex.html)strict)r8  r  countr  z	genindex-zgenindex-single.html)	r   rV   create_indexr   html_split_indexr   r   r  zip)rm   r  indexcountsgenindexcontextr8  r  r  r  rK   rK   rL   r    s*   	z$StandaloneHTMLBuilder.write_genindexc                 C  sF   | j D ]\}}}}|j||d}tj|d dd | ||d qd S )N)
indextitleru  collapse_indexr  Tr  zdomainindex.html)rT   rZ  r   r   r  )rm   rz  r{  ru  rv  indexcontextrK   rK   rL   r    s   z*StandaloneHTMLBuilder.write_domain_indicesc                 C  s   | j r\t| jjj}t| j| j  t| j t	ddt
| j | jj|dD ]9}| j | }zt| j| | j| j | dd W q$ ty[ } ztt	d| j| | W Y d }~q$d }~ww d S d S )Nzcopying images... brownstringify_funcTforcezcannot copy image file '%s': %s)imagesr   rU   rV   get_original_image_urir8   r   rw   r-   r%   r   	verbosityr7   srcdirr   r   r   )rm   r  srcdesterrrK   rK   rL   r    s4   


z&StandaloneHTMLBuilder.copy_image_filesc                   s   d fdd} j jret jd  t j jtddt j j jj|d	D ]@}z jd  j j| d
  }t|j	 t
 j| |dd W q& tyd } zttd j| | W Y d }~q&d }~ww d S d S )NfrR   rH   c                   s   t  j| S r   )r   r  )r  r   rK   rL   
to_relpath  s   z=StandaloneHTMLBuilder.copy_download_files.<locals>.to_relpathr  zcopying downloadable files... r  r  r   Tr  z$cannot copy downloadable file %r: %s)r  rR   rH   rR   )rV   dlfilesr8   r   r-   r%   r   rU   r  parentr7   r  r   r   r   )rm   r  r  r  r  rK   r   rL   r    s2   


z)StandaloneHTMLBuilder.copy_download_filesc                 C  s   t | jdd}t|ddd}|| j  W d   n1 s"w   Y  | jrTt | jdd}t|ddd}|| j  W d   dS 1 sMw   Y  dS dS )z!Create a style file for pygments.r   r   wr  r[   Nr   )r   r   r   openr  r   get_stylesheetr   )rm   pyg_pathr  	dark_pathrK   rK   rL   create_pygments_style_file!  s   "z0StandaloneHTMLBuilder.create_pygments_style_filec                 C  s,   |   }|rt|| jd d dd dS dS )z(Copy a JavaScript file for translations.r   r   Tr  N)r   r7   r   )rm   r   rK   rK   rL   copy_translation_js,  s   
z)StandaloneHTMLBuilder.copy_translation_jsc                 C  s~   | j dur;t| j dr&| j  D ]}t|}t|| jd |j dd qdS | j   }r=t|| jd d dd dS dS dS )z#Copy a JavaScript file for stemmer.Nget_js_stemmer_rawcodesr   Tr  z_stemmer.js)r;  hasattrr  r   r7   r   r   get_js_stemmer_rawcode)rm   r   js_pathjs_stemmer_rawcoderK   rK   rL   copy_stemmer_js6  s$   


z%StandaloneHTMLBuilder.copy_stemmer_jsr  c              
   C  sR   ddd}| j r%t| j  D ]}tt|d	 | jd
 t|| j|dd qd S d S )Nr   rR   errorr   rH   rW   c                 S  s   t d}t|| | d S )Nz?Failed to copy a file in the theme's 'static' directory: %s: %r)r%   r   r   )r   r  r   rK   rK   rL   onerrorJ  s   z>StandaloneHTMLBuilder.copy_theme_static_files.<locals>.onerrorstaticr   Texcludedr  rendererr  r  r   rR   r  r   rH   rW   )r   reversedget_theme_dirsr/   r   r   r2   r   )rm   r  r  entryrK   rK   rL   copy_theme_static_filesI  s   

z-StandaloneHTMLBuilder.copy_theme_static_filesc              
   C  sT   ddd}t g | jjd	}| jjD ]}t| j| | jd
 ||| j|dd qd S )Nr   rR   r  r   rH   rW   c                 S  s   t td| | d S )Nz1Failed to copy a file in html_static_file: %s: %r)r   r   r%   )r   r  rK   rK   rL   r  [  s   
z=StandaloneHTMLBuilder.copy_html_static_files.<locals>.onerrorz**/.*r   Tr  r  )r3   r   exclude_patternsr  r/   confdirr   r   )rm   r  r  r  r  rK   rK   rL   copy_html_static_filesZ  s   
z,StandaloneHTMLBuilder.copy_html_static_filesc                 C  H   | j jr t| j js"| j| j j }t|| jd |j dd d S d S d S Nr   Tr  )r   rT  r*   r
  r7   r   r   rm   source_pathrK   rK   rL   copy_html_logol     
z$StandaloneHTMLBuilder.copy_html_logoc                 C  r  r  )r   rU  r*   r
  r7   r   r   r  rK   rK   rL   copy_html_faviconu  r  z'StandaloneHTMLBuilder.copy_html_faviconc              
   C  s   zTt tdddA t| jd  | j }| jd ur#|| j  | 	  | 
  |   | | | | |   |   W d    W d S 1 sMw   Y  W d S  tyo } zttd| W Y d }~d S d }~ww )Nzcopying static filesFr  r   zcannot copy static file %r)r,   r%   r8   r   rk  copyr;  updatecontext_for_searchtoolr  r  r  r  r  r  r  r   r   r   )rm   r  r  rK   rK   rL   r  ~  s$   




&z'StandaloneHTMLBuilder.copy_static_filesc              
   C  s   z6t tddd# t| jj}| jjD ]}t| j| | j|dd qW d   W dS 1 s/w   Y  W dS  t	yQ } zt
td| W Y d}~dS d}~ww )zCopy html_extra_path files.zcopying extra filesFr  T)r  r  Nzcannot copy extra file %r)r,   r%   r3   r   r	  r  r/   r
  r   r   r   r   )rm   r  
extra_pathr  rK   rK   rL   r    s    &	z&StandaloneHTMLBuilder.copy_extra_filesc              
   C  sP   z| j | jd  W d S  ty' } zttd| W Y d }~d S d }~ww )Nr   z#Failed to write build info file: %r)rv   r   r   r   r   r   r%   )rm   r   rK   rK   rL   r    s   z%StandaloneHTMLBuilder.write_buildinfoc                 C  s   | j r
| j   d S d S r   )r   _cleanupr   rK   rK   rL   cleanup  s   zStandaloneHTMLBuilder.cleanupr@   c                   s   t  | | jjr]| jr_|tjD ]M t fdddD s!qt j	tj
r)qd d v r0q d }tj
dddd	}|| jv rNt| j| j| |d
< n||d
<  | |  qdS dS dS )zsPick the best candidate for an image and link down-scaled images to
        their high resolution version.
        c                 3      | ]}| v V  qd S r   rK   )r   r8  r  rK   rL   r        z<StandaloneHTMLBuilder.post_process_images.<locals>.<genexpr>)scalewidthheightzno-scaled-linkclassesurirQ   T)internalrefuriN)rd   r  r   html_scaled_image_linkfindallr	   imageanyr   r  	referencer  r   r   rS   replace_selfr   )rm   rj   r   r'  ro   r  rL   r    s$   

z)StandaloneHTMLBuilder.post_process_imagesc              	   C  s   | j d usJ t| jj|}zIt| j| j}| j	r;t
|dd}| j || j W d    n1 s5w   Y  nt
|d}| j || j W d    n1 sSw   Y  W n ttfym   |rkttd Y nw | j | d S )Nr  r[   rbzcsearch index couldn't be loaded, but not all documents will be built: the index will be incomplete.)r;  setrV   r   
differencer   r   r   searchindex_filenameindexer_dumps_unicoder  r   rP   r   r   r   r   r%   prune)rm   r  keepsearchindexfnftfbrK   rK   rL   rA    s.   
z"StandaloneHTMLBuilder.load_indexerr  r  c                 C  sz   | j d ur9|r;t| jj|dd}| jj|i }d|v s!d|v r.| j ||dtd d S | j |||| d S d S d S )NF)basez	no-searchnosearchrQ   )r;  rR   rV   r   r  r  feedr.   )rm   r  rj   r  r   r  rK   rK   rL   r    s   z StandaloneHTMLBuilder.index_pagerv  rJ  c                 K  sP   d|vrd|d< | ddkr|d t| j|| fd|i|}| |d S )NincludehiddenFmaxdepthrQ   rv  r  )r  r  r    rV   r  )rm   r   rv  r   toctreerK   rK   rL   _get_local_toctree  s   
z(StandaloneHTMLBuilder._get_local_toctreec                 C  s   t | jt|| j S r   )r   r   r   r9   r   )rm   r  rK   rK   rL   r     s   z%StandaloneHTMLBuilder.get_outfilenamer  c           
      C  s   d
dd}d }t | jj}| dd}td	}| D ]\}}	t||r:|r6||r6||r5t||| q|}|	}qt ||d< d S )NpatternrR   rH   rJ  c                   s   t  fdddD S )Nc                 3  r  r   rK   )r   charr:  rK   rL   r    r  zKStandaloneHTMLBuilder.add_sidebars.<locals>.has_wildcard.<locals>.<genexpr>z*?[)r&  r<  rK   r<  rL   has_wildcard  r   z8StandaloneHTMLBuilder.add_sidebars.<locals>.has_wildcardsidebarsrO   z8page %s matches two patterns in html_sidebars: %r and %r)r:  rR   rH   rJ  )	r   r   sidebar_templatesr~   r%   rm  r4   r   r   )
rm   r  r  r=  matchedr>  html_sidebarsr   r:  pat_sidebarsrK   rK   rL   add_sidebars  s   

z"StandaloneHTMLBuilder.add_sidebarsNtypc                 C  s   t || j S r   )r   rs   )rm   r   rD  rK   rK   rL   r    s   z$StandaloneHTMLBuilder.get_target_uri	page.htmladdctxtemplatenamer  r  c              
     sF  j  } |d< |d< jj|d< }|ddd }jjr2tjj|d< nd |d< d|fd6fdd|d< d7fdd}||d< fdd|d< 	| |
| dt |t pqdt |d< jj d8 fdd}	|	|d < d9 fd#d$}
|
|d%< jjd d < jjd d < ||| jd&|||}|r|}zt|d' d(d d)|d'< W n	 ty   Y nw tt t|d* d+d d)|d*< W d    n1 sw   Y  z	j||}W n, ty   ttd, Y d S  ty& } ztd-|f }t ||d }~ww |s/!}t"t#$| z"t%|d.|d d/d0}|&| W d    n	1 sRw   Y  W n t'yt } zttd1|| W Y d }~nd }~ww j(r|)d2rt#jd3t*|d2 }t"t#$| t+j,-|d4d5 d S d S d S ):Nr  current_page_namer\   #r   r   pageurlFotherurirR   resourcerJ  baseurirH   c                   sB   |rd| v r| S |s  | } t|| pd}|dkr js|}|S )Nr   rI  )r  r:   allow_sharp_as_current_path)rK  rL  rM  r   r   rK   rL   pathto/  s   
z1StandaloneHTMLBuilder.handle_page.<locals>.pathtorO  r   c                   s6   |  j jv rdS | dkr jrdS | dko ddS )NTr<  r  rt   rO   )rV   r   r<  r~   )r   r   rK   rL   hasdoc@  s
   z1StandaloneHTMLBuilder.handle_page.<locals>.hasdocrP  c                    s   j  fi | S r   )r9  )r   )r  rm   rK   rL   <lambda>I  s    z3StandaloneHTMLBuilder.handle_page.<locals>.<lambda>r8  z...content_rootcssr   c                   sl   dd | j  D }t| jdd}jdvr(t | j }r(|d| 7 }ddt| d	| d
S )Nc                 S  s2   g | ]\}}|d ur| dt j|dd dqS )N="Tr   "rO   escaper   r8  valuerK   rK   rL   r   S  s
    zFStandaloneHTMLBuilder.handle_page.<locals>.css_tag.<locals>.<listcomp>TrL  >   epubhtmlhelp?v=z<link r  z href="z" />)	
attributesrm  osfspathr   r   r   r   rO  )rT  r   r   checksumr   rO  rm   rK   rL   css_tagR  s   
z2StandaloneHTMLBuilder.handle_page.<locals>.css_tagrd  js_JavaScript | strc                   s   t | tsd| dd dS | jdd}dd | j D }| js9|r3d	d
t| d| dS d| dS t	| jdd}dt	| jv rLnj
dkr`t | j }r`|d| 7 }|rpd	d
t| d| dS d| dS )Nz<script src="Tr[  z"></script>r  rQ   c                 S  s:   g | ]\}}|d kr|dur| dt j|dd dqS )r  NrU  Tr   rV  rW  rY  rK   rK   rL   r   i  s
    zEStandaloneHTMLBuilder.handle_page.<locals>.js_tag.<locals>.<listcomp>z<script r  >z	</script>z<script>zMathJax.js?r\  r^  z src=")r   r   r_  r  rm  r   r   rO  r`  ra  r   r   )re  r  r   r   rb  rc  rK   rL   js_tagc  s&   

z1StandaloneHTMLBuilder.handle_page.<locals>.js_tagrh  html-page-contextr   c                 S     | j S r   r   )re  rK   rK   rL   rQ        )r8  r   c                 S  rj  r   r   )rT  rK   rK   rL   rQ    rk  za Unicode error occurred when rendering the page %s. Please make sure all config values that contain non-ASCII content are Unicode strings.z6An error happened in rendering the page %s.
Reason: %rr  xmlcharrefreplace)r\   errorszerror writing file %s: %sr  _sourcesTr  )rK  rR   rL  rJ  rM  rR   rH   rR   )r   rR   rH   rJ  )rT  r   rH   rR   )re  rf  rH   rR   ).rk  r  r   html_output_encodingr  rsplithtml_baseurlr   r   rC  r  r5   r  rU   r   r]  rf   r^  rg   update_page_contextemit_firstresultrO  AttributeErrorr  r  r   renderUnicodeErrorr   r   r%   r   r"   r   r8   r   dirnamer  r  r   
copysourcer  r9   r7   rV   r   )rm   r  rF  rG  r  r  r  default_baseurirP  rd  rh  newtmploutputr   r   r  r  source_namerK   )r   r  rO  rm   rL   r    s   



" 


z!StandaloneHTMLBuilder.handle_pagec                 C  s   d S r   rK   )rm   r  rG  r  r  rK   rK   rL   rr    s   z)StandaloneHTMLBuilder.update_page_contextc                 C  s    | j | j | j | j d S r   )r  r  dump_search_indexdump_inventoryr   rK   rK   rL   r    s   z#StandaloneHTMLBuilder.handle_finishzdumping object inventoryc                 C  s   t t| jt| j|  d S r   )r1   r   r   r   r   INVENTORY_FILENAMErV   r   rK   rK   rL   r~    s   z$StandaloneHTMLBuilder.dump_inventoryc              	   C  s  | j d u rd S ttd| j   e | j | jj t| j	| j
}| jrHt|d ddd}| j || j W d    n1 sBw   Y  nt|d d}| j || j W d    n1 sbw   Y  t|d | W d    d S 1 szw   Y  d S )Nzdumping search index in %sz.tmpr  r  r[   wb)r;  r,   r%   labelr.  rV   r   r   r   r   r,  r-  r  r   rP   r`  rJ   )rm   r0  r1  r2  rK   rK   rL   r}    s   
"z'StandaloneHTMLBuilder.dump_search_index)rU   rB   rV   rC   rH   rW   )rH   rW   )rH   r   )rH   rR   )rH   r   )rH   r   )rH   r   )r   rR   r   r   rH   rW   )rH   r   )rH   rG   )rH   r  )r  r  rH   r  )r  r  rH   rW   )r   rR   r  rR   r  rR   rH   r  )r   rR   rj   r  rH   rW   )r  r  rH   rW   )rj   r@   rH   rW   )r  rR   rj   r  r  rR   rH   rW   )T)r   rR   rv  rJ  r   r   rH   rR   )r  rR   rH   rR   )r  rR   r  r  rH   rW   r   )r   rR   rD  rG   rH   rR   )rE  NN)r  rR   rF  r  rG  rR   r  rG   r  r   rH   rW   )
r  rR   rG  rR   r  r  r  r   rH   rW   )Xr   
__module____qualname____doc__r   formatr%   epilogr<   default_translator_classrx  allow_parallelr   rs   r&   rP   __annotations__r-  r#  supported_image_typessupported_remote_imagessupported_data_uri_imagesr,  add_permalinksrN  r  r<  rt   download_supportrS   rT   re   r   ru   r   r   r   rz   r{   propertyr   r|   r   r   r}   r   r   r   r  r  r  r  r  r  r  r  r,   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rA  r  r9  r   rC  r  r  rr  r  r~  r}  __classcell__rK   rK   ro   rL   rN   j   s   
 













J

 

P



















	
	






 
.

rN   rU   rB   r   r   rW   c              	   C  p   g }|j D ]-}t|tr||i f qz|\}}|||f W q ty2   ttd| Y qw ||_ dS )z9Convert string styled html_css_files to tuple styled one.zinvalid css_file: %r, ignoredN)html_css_filesr   rR   r   r   r   r   r%   )rU   r   r  r  r   r   rK   rK   rL   convert_html_css_files     


r  c              	   C  r  )z8Convert string styled html_js_files to tuple styled one.zinvalid js_file: %r, ignoredN)html_js_filesr   rR   r   r   r   r   r%   )rU   r   r  r  r   r   rK   rK   rL   convert_html_js_files  r  r  r  rR   rG  r  r  rj   r@   c                 C  sh   |d }| d}|rt|s|d| dd|d< | d}|r0t|s2|d| dd|d< dS dS dS )zSet up relative resource paths.rO  r5  z_static/Tr[  r3  N)r  r*   )rU   r  rG  r  rj   rO  r5  r3  rK   rK   rL   setup_resource_paths  s   

r  c                 C  sP   | j jdkrd S | j j}|d u rtd}t||| jjvr&ttd| d S )NrO   zEMany math_renderers are registered. But no math_renderer is selected.z"Unknown math_renderer %r is given.)r1  r  r   r%   r!   r   r   )rU   r   r   rK   rK   rL   validate_math_renderer  s   r  c                 C     |j dd D ]K}tt| j|}t|s'ttd| |j 	| qt
| jd t
|d krRt| j|ft| jkrRttd| |j 	| qdS )zCheck html_extra_paths setting.Nz'html_extra_path entry %r does not existr   z0html_extra_path entry %r is placed inside outdir)r  r   normpathr   r
  existsr   r   r%   r   
splitdriver   
commonpath)rU   r   r  r  rK   rK   rL   validate_html_extra_path(     
r  c                 C  r  )z Check html_static_paths setting.Nz(html_static_path entry %r does not existr   z1html_static_path entry %r is placed inside outdir)r  r   r  r   r
  r  r   r   r%   r   r  r   r  )rU   r   r  static_pathrK   rK   rL   validate_html_static_path9  r  r  c                 C  N   |j r!tt| j|j s#t|j s%ttd|j  d|_ dS dS dS dS )zCheck html_logo setting.zlogo file %r does not existN)	rT  r   r   r   r
  r*   r   r   r%   rU   r   rK   rK   rL   validate_html_logoJ     
r  c                 C  r  )zCheck html_favicon setting.zfavicon file %r does not existN)	rU  r   r   r   r
  r*   r   r   r%   r  rK   rK   rL   validate_html_faviconU  r  r  c                 C  sf   i }|j  D ]\}}t|tr|g||< q|sdS td}dtt|}|j |B }t|||f )zSupport removed in Sphinx 2.NzValues in 'html_sidebars' must be a list of strings. At least one pattern has a string value: %s. Change to `html_sidebars = %r`.z, )	rA  rm  r   rR   r%   r   mapreprr!   )rU   r   rm  r:  rB  r   bad_patternsfixedrK   rK   rL   $error_on_html_sidebars_string_values`  s   


r  _appc                 C  s   |j rtd}t|dS )zError on HTML 4.z`HTML 4 is no longer supported by Sphinx. ("html4_writer=True" detected in configuration options)N)html4_writerr%   r!   )r  r   r   rK   rK   rL   error_on_html_4r  s   r  rD   c                 C  sT  |  t | ddd | dg d | di d | ddd dt | d	d
d d | dd dtth | dd dt | dd dt | dg d | dg d | dg d | dg d | dd dt | jdddthd | di d | di d | jdddtthd | ddd | ddd | ddd | ddd | ddd | d dd | d!d"d | d#d$d | d%d dt | d&d dt | d'dd | d(dd | d)dd | d*i d | d+d,d | d-dd | d.d/d | d0d dt | d1i d | d2d$d$ | d3dd | d4d$d | d5d6dtd7d6 | d8d d9 | d:dd | d; | d< | j	d=t
d>d? | j	d=td>d? | j	d=td>d? | j	d=td>d? | j	d=td>d? | j	d=td>d? | j	d=td>d? | j	d=td>d? | 	d@t | 	d<t | dA | dB dCdddDS )ENr   	alabasterrO   html_theme_pathr   rb  c                 S  s   t d| j| jf S )Nz%s %s documentation)r$   r  r  )crK   rK   rL   rQ    s    zsetup.<locals>.<lambda>rc  c                 S  rj  r   )rb  r   rK   rK   rL   rQ    rk  r   rT  rU  r  r  r  r  rR  rS  F)typesrA  r  rM  Thtml_permalinkshtml_permalinks_icon   ¶html_use_indexr  rg  rh  ri  z.txtra  rQ   r   r   rd  re  rf  rn  ro  r  rK  html_secnumber_suffixz. r>  r?  r@  r#  rq  html_codeblock_linenos_styleinlinetablehtml_math_rendererrV   r  r  ri  zconfig-initedr   r   zbuilder-initedzsphinx.ext.mathjaxzsphinx.builders.html.transformsbuiltin)r  parallel_read_safeparallel_write_safe)add_builderrN   add_config_valuerR   r   rJ  r*  r   	add_eventconnectr  r  r  r  r  r  r  r  r  r  setup_extension)rU   rK   rK   rL   setup|  s   




r  z1sphinx.builders.html._assets._CascadingStyleSheetr   z(sphinx.builders.html._assets._JavaScript)
Stylesheet
JavaScriptz+dict[str, tuple[Any, str, tuple[int, int]]]_DEPRECATED_OBJECTSr   r   c                 C  sN   | t vrdtd| }t|ddlm} t |  \}}}|t| ||d |S )Nzmodule z has no attribute r   r   r   )r  r   rt  sphinx.deprecationr   )r   r   r   deprecated_objectr   r   rK   rK   rL   __getattr__  s   r  )rF   rG   rH   rG   )rU   rB   r   r   rH   rW   )rU   rB   r  rR   rG  rR   r  r  rj   r@   rH   rW   )rU   rB   rH   rW   )r  rB   r   r   rH   rW   )rU   rB   rH   rD   )r   rR   rH   r   )r  
__future__r   r  rO   r`  r   rer   r   rC  r   pathlibr   typingr   r   urllib.parser   docutils.readers.doctreerh   r	   docutils.corer
   docutils.frontendr   docutils.ior   r   docutils.utilsr   r   r   r   r   r+  sphinx.buildersr   sphinx.builders.html._assetsr   r   r    sphinx.builders.html._build_infor   sphinx.configr   r   r  r   sphinx.domainsr   r   !sphinx.environment.adapters.assetr   (sphinx.environment.adapters.indexentriesr   #sphinx.environment.adapters.toctreer   r    sphinx.errorsr!   r"   sphinx.highlightingr#   sphinx.localer$   r%   r=  r&   sphinx.themingr'   sphinx.utilr(   sphinx.util._timestampsr)   sphinx.util._urir*   sphinx.util.consoler+   sphinx.util.displayr,   r-   sphinx.util.docutilsr.   sphinx.util.fileutilr/   sphinx.util.i18nr0   sphinx.util.inventoryr1   sphinx.util.matchingr2   r3   r4   sphinx.util.osutilr5   r6   r7   r8   r9   r:   sphinx.writers.htmlr;   sphinx.writers.html5r<   collections.abcr=   r>   r?   docutils.nodesr@   docutils.readersrA   sphinx.applicationrB   sphinx.environmentrC   sphinx.util.typingrD   r  	getLoggerr   r   compiler_  tuplerR   typer   rJ  rE   r  rM   rN   r  r  r  r  r  r  r  r  r  r  r  r  r  rK   rK   rK   rL   <module>   s     


         











X
