HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sphinx/builders/__pycache__/_epub_base.cpython-310.pyc
o

�$�ar�@s�dZddlZddlZddlZddlmZddlmZmZmZm	Z	m
Z
mZddlm
Z
mZmZddlmZddlmZmZddlmZdd	lmZdd
lmZmZddlmZddlmZm Z dd
l!m"Z"ddl#m$Z$ddl%m&Z&m'Z'zddl(m)Z)Wne*y�dZ)Ynwe�+e,�Z-dZ.dZ/dZ0dZ1dZ2dZ3ddd�Z4dddddddd d!d"d#�
Z5d$Z6e�7d%�Z8Gd&d'�d'e	�Z9Gd(d)�d)e	�Z:Gd*d+�d+e	�Z;Gd,d-�d-e	�Z<d6d/e=d0e=d1e=fd2d3�Z>e>Z?Gd4d5�d5e�Z@dS)7z�
    sphinx.builders._epub_base
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    Base class of epub2/epub3 builders.

    :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
�N)�path)�Any�Dict�List�
NamedTuple�Set�Tuple)�ZIP_DEFLATED�
ZIP_STORED�ZipFile)�nodes)�Element�Node)�smartquotes)�addnodes)�	BuildInfo�StandaloneHTMLBuilder)�__)�logging�status_iterator)�copy_asset_file)�format_date)�copyfile�	ensuredir)�Imagezepub-cover.xhtmlztoctree-l%dz
 [%(uri)s]z#%d�	Footnoteszlink-targetzTable of Contents�Cover)�toc�coverzapplication/xhtml+xmlztext/css�	image/png�	image/gif�
image/svg+xml�
image/jpegzapplication/x-font-otfzapplication/x-font-ttfzapplication/font-woff)
�.xhtmlz.cssz.pngz.gif�.svgz.jpgz.jpegz.otfz.ttfz.woff)r$z
([^#:]*#)(.*)c@�&eZdZUeed<eed<eed<dS)�ManifestItem�href�id�
media_typeN��__name__�
__module__�__qualname__�str�__annotations__�r0r0�</usr/lib/python3/dist-packages/sphinx/builders/_epub_base.pyr&T�
r&c@seZdZUeed<eed<dS)�Spine�idref�linearN)r+r,r-r.r/�boolr0r0r0r1r3Zs
r3c@r%)�Guide�type�title�uriNr*r0r0r0r1r7_r2r7c@s:eZdZUeed<eed<eed<eed<eeed<dS)�NavPoint�navpoint�	playorder�text�refuri�childrenN)r+r,r-r.r/�intrrr0r0r0r1r;es
r;�en�t�language�returncCs2|�dd�}t�|�}t�||�}|�dd�}|S)Nz&quot;�")�replacer�educateDashesOldSchool�
educateQuotes)rCrDr0r0r1�sphinx_smarty_pantsns

rJc
s�eZdZdZdZgd�ZdZdZdZdZ	dZ
dZdZe
ZeZeZeZeZeZeZdZdZdV�fdd	�Zdefd
d�Zde e!e"ffdd
�Z#de!de!fdd�Z$de%de&e"e!e'fde&e"e!e'ffdd�Z(de&e"e!e'fddfdd�Z)dVdd�Z*de&e"e!e'fddfdd�Z+de!de!de!fdd �Z,d!e-j.ddfd"d#�Z/dWd!e-j.d%e!ddfd&d'�Z0d(e!de-j.ddf�fd)d*�Z1d!e&e e!e&e e!e'ffddfd+d,�Z2d-e!de3fd.d/�Z4dVd0d1�Z5dV�fd2d3�Z6dVd4d5�Z7	6	dXd7e!d8e"d9e!d:e!d;e'ddf�fd<d=�
Z8dVd>d?�Z9dYdAe!ddfdBdC�Z:de"e!e'ffdDdE�Z;dVdFdG�Z<dZdHe"e!e'fdIe=dJe3de>fdKdL�Z?de&e"e!e'fde&e>fdMdN�Z@dIe=dOe&e>de"e!e'ffdPdQ�ZAdVdRdS�ZBdVdTdU�ZC�ZDS)[�EpubBuilderz�
    Builder that outputs epub files.

    It creates the metainfo files container.opf, toc.ncx, mimetype, and
    META-INF/container.xml.  Afterwards, all necessary files are zipped to an
    epub file.
    F)r!rr r"T�rENcs@t���d|_d|_d|_d|_i|_|�dd�|_g|_	dS)Nr#r�	use_index�epub)
�super�init�
out_suffix�link_suffixr=�tocid�id_cache�get_builder_configrM�refnodes��self��	__class__r0r1rP�s

zEpubBuilder.initcCst|j|jddg�S)N�htmlrN)r�config�tagsrWr0r0r1�create_build_info�szEpubBuilder.create_build_infocCs|jj|jjfS�N)r\�
epub_theme�epub_theme_optionsrWr0r0r1�get_theme_config�szEpubBuilder.get_theme_config�namecCs.|j�|�}|sd|j�d�}||j|<|S)zReturn a unique id for name.zepub-%drN)rT�get�env�new_serialno)rXrcr(r0r0r1�make_id�s

zEpubBuilder.make_id�doctree�resultc
Cs�t|tj�rS|�d�rS|d}|�d�s#|�d�s#|�d�s#|�d�r%|S|jjd}tddd	�D]}|j||vrP|�	|t
�|�tt
�|�
���d
��|Sq1|St|tj�rd|D]}|�||�}q[|S)z>Collect section titles, their depth in the toc and the refuri.r?zhttp://zhttps://zirc:zmailto:�classes�r�����levelr?r>)�
isinstancer�	referencerd�
startswith�parent�
attributes�range�toctree_template�appendr[�escape�ssp�astextr
�get_refnodes)rXrhrir?rjrn�elemr0r0r1rz�s0����
�zEpubBuilder.get_refnodesrcCsJt�}|D]}|d|vrtjtd�|dddd�q|�|d�qdS)Nr?zduplicated ToC entry found: %srN�duplicated_toc_entry�r8�subtype)�set�logger�warningr�add)rXr�appeared�noder0r0r1�check_refnodes�s��zEpubBuilder.check_refnodescCsl|jj|jj|ddd�}|�|g�|_t�|jj�}|r.|d7}|jD]
}||d|d<q#|�|j�dS)zwGet the total table of contents, containing the root_doc
        and pre and post files not managed by sphinx.
        FT��prune_toctrees�
includehidden�/r?N)	re�get_and_resolve_doctreer\�root_docrzrVr�dirname�
toc_add_files)rXrh�
master_dir�itemr0r0r1�get_toc�s�
zEpubBuilder.get_tocrVc
Cs�|�ddt�|jj|j�tt�|jj|jj�	���d��t
|jj�D]\}}|�ddt�|�tt�|��d��q%|jjD]\}}|�
dt�|�tt�|��d��q@dS)zDAdd the root_doc, pre and post files to a list of refnodes.
        r�rmN)�insertr[rwr\r�rQrxre�titlesry�reversed�epub_pre_files�epub_post_filesrv)rXrV�filer>r0r0r1r��s(��
�
��zEpubBuilder.toc_add_files�prefix�fragmentcCs||�dd�S)z;Return a href/id attribute with colons replaced by hyphens.�:�-)rG)rXr�r�r0r0r1�fix_fragmentszEpubBuilder.fix_fragment�treecs�dtddf�fdd�}|�tj�D],}d|vr/�j�|d�}|r/��|�d�|�d��|d<d	|vr=��d
|d	�|d	<q|�tj�D]}||�|j	dd�}t
|tj�rZ||�qD|�tj�D]}||�qadS)
z�Replace colons with hyphens in href and id attributes.

        Some readers crash because they interpret the part as a
        transport protocol specification.
        r�rENcs<g}|dD]}��d|�}||vr|�|�q||d<dS)zUpdate IDs of given *node*.�idsrLN)r�rv)r��new_ids�node_id�new_idrWr0r1�update_node_ids
�z+EpubBuilder.fix_ids.<locals>.update_node_idr?r���refidrLT)�ascend)
r
�traverserrp�	refuri_re�matchr��group�target�	next_noderor�desc_signature)rXr�r�rp�mr�r�r�r0rWr1�fix_ids	s$	��
�zEpubBuilder.fix_ids�inline�	show_urlscCs�dtjdtdtjfdd�}dtjdtdtdtjfdd�}d	tjdtttffd
d�}|dkr0d
S|dkrFt|�	tj��d}||�\}}d}	t|�	tj
��D]}
|
�dd�}|�d�se|�d�se|�d�r�||
�
�vr�|
j�|
�d}|dkr�|jd|i}t�||�}
|
d�|j�|
j�||
�qN|dkr�t|	}|	d7}	|||�}|
j�||�||||�}|�||�|dd|d<|�|dd�|d7}qNd
S)z+Add visible link targets for external links�doc�labelrEcSs(t�d�}|�t�|��|�|�|S)z.Create a footnote_reference node with childrenz[#]_)r�footnote_referencerv�Text�note_autofootnote_ref)r�r��footnote_refr0r0r1�make_footnote_ref-s

z8EpubBuilder.add_visible_links.<locals>.make_footnote_refr:cSsNt�|�}t��}|�t�|��|�|�|�dt�d|��|�|�|S)z$Create a footnote node with childrenrrL)r�footnote�	paragraphrvr�r�r��note_autofootnote)r�r�r:r��parar0r0r1�
make_footnote4s


z4EpubBuilder.add_visible_links.<locals>.make_footnoter�cSs�t|�tj��}|r|d}|j|j�|�dfS|�tj�D]}t|�dkr:|��t	kr:|j|j�|�dfSqt|�tj
��d}t��}|�t�t	��|�|�||�|�dfS)zfFind or create a spot to place footnotes.

            The function returns the tuple (parent, index).rlr�r)
�listr�rr�rr�index�rubric�lenry�FOOTNOTES_RUBRIC_NAME�documentrvr�)r��fns�fnr�r��rubr0r0r1�
footnote_spot>s�
z4EpubBuilder.add_visible_links.<locals>.footnote_spot�noNr�rr�r?rLzhttp:zhttps:zftp:r�rjr�r�)rr�r.r�r�rr
rAr�r�rprdrqryrrr��link_target_templater�rv�css_link_target_classr��FOOTNOTE_LABEL_TEMPLATE�add_backref)rXr�r�r�r�r�r��fn_spot�fn_idx�nrr�r:�idx�linkr�r�r�r0r0r1�add_visible_links*sB
�
��zEpubBuilder.add_visible_links�docnamecs,|�|�|�||jj�t��||�dS)z�Write one document file.

        This method is overwritten in order to fix fragment identifiers
        and to add visible external links.
        N)r�r�r\�epub_show_urlsrO�	write_doc)rXr�rhrYr0r1r�ns
zEpubBuilder.write_doccCs�|D][\}}|D]T\}\}}}t|�D]\}\}	}
|j�|
�}|r1|	|�|�d�|�d��f||<q|D]'\}}
t|
�D]\}\}	}
|j�|
�}|rZ|	|�|�d�|�d��f|
|<q<q4qqdS)z'Fix href attributes for genindex pages.r�r�N)�	enumerater�r�r�r�)rXr��key�columns�	entryname�links�subitems�key_�i�ismainr�r��subentryname�
subentrylinksr0r0r1�fix_genindexxs*��������zEpubBuilder.fix_genindex�filenamecCst�|�d}|tvS)z=Does the filename extension indicate a vector graphic format?rl)r�splitext�VECTOR_GRAPHICS_EXTENSIONS)rXr��extr0r0r1�is_vector_graphics�szEpubBuilder.is_vector_graphicsc	Cs�tt�|j|j��t|jtd�dt|j�|j	j
�D]�}|j|}zt�t�|j
|��}WnOty||�|�sFt�td�t�|j
|��ztt�|j
|�t�|j|j|��Wn tyy}zt�td�t�|j
|�|�WYd}~nd}~wwYqw|jjr�|jdvr�|��}|jjdkr�|j\}}|jj}||kr�|||}|�||ftj�}z|�t�|j|j|��Wqty�}zt�td�t�|j
|�|�WYd}~qd}~wwdS)	z�Copy images using Pillow, the Python Imaging Library.
        The method tries to read and write the files with Pillow, converting
        the format and resizing the image if necessary/possible.
        zcopying images... �brownz-cannot read image file %r: copying it insteadzcannot copy image file %r: %sN)�Przcannot write image file %r: %s)rr�join�outdir�imagedirr�imagesrr��app�	verbosityr�open�srcdir�OSErrorr�r�r�rr\�epub_fix_images�mode�convert�epub_max_image_width�size�resize�BICUBIC�save)	rX�src�dest�img�err�width�height�nw�nhr0r0r1�copy_image_files_pil�sT�


��
����


����z EpubBuilder.copy_image_files_pilcsT|jr(|jjs|jjr!tst�td��t��	�dS|�
�dSt��	�dSdS)zzCopy image files to destination directory.
        This overwritten method can use Pillow to convert image files.
        z&Pillow not found - copying image filesN)r�r\r�r�rr�r�rrO�copy_image_filesrrWrYr0r1r�s�zEpubBuilder.copy_image_filescCsdSr_r0rWr0r0r1�copy_download_files�szEpubBuilder.copy_download_files�	page.html�pagename�addctx�templatename�outfilename�	event_argcsL|�d�rd|vr|jsdS|�|d�|j|d<t��|||||�dS)z�Create a rendered page.

        This method is overwritten for genindex pages in order to fix href link
        attributes.
        �genindex�genindexentriesN�doctype)rqrMr�rrO�handle_page)rXrrrrr	rYr0r1r
�s
zEpubBuilder.handle_pagecCs(t�td��tt�|jd�|j�dS)z!Write the metainfo file mimetype.zwriting mimetype file...�mimetypeN)r��inforrrr��template_dirr�rWr0r0r1�build_mimetype�szEpubBuilder.build_mimetype�META-INF/container.xml�outnamecCs<t�td��t�|jd�}t|�tt�|jd�|�dS)z/Write the metainfo file META-INF/container.xml.z&writing META-INF/container.xml file...zMETA-INFz
container.xmlN)	r�rrrr�r�rrr)rXrr�r0r0r1�build_container�szEpubBuilder.build_containercCs�i}t�|jj�|d<t�|jj�|d<t�|jj�|d<t�|jj�|d<t�|jj�|d<t�|jj�|d<t�|jj	�|d<t�|jj
�|d<t�td	��|d
<g|d<g|d<g|d
<|S)zaCreate a dictionary with all metadata for the content.opf
        file properly escaped.
        r9�author�uid�lang�	publisher�	copyright�schemer(z%Y-%m-%d�date�manifest_items�spines�guides)r[rwr\�
epub_title�epub_author�epub_uid�
epub_language�epub_publisher�epub_copyright�epub_scheme�epub_identifierr)rX�metadatar0r0r1�content_metadata�szEpubBuilder.content_metadatacCs�t�td��|��}|j�tj�s|jtj7_t|j�}g|_	dddddddd	d
|j
jdg
|j
j|_
|jsC|j
�d|j�t�|j�D]e\}}}|��t|�D]W}t�||�|d
�}||j
vrhqVt�|�d}||jvr�|dvr�tjtd�|ddd�qV|�tjd�}tt�|�t�|�|��t�|j|��}	|d�|	�|j	�|�qVqIt�}
|jD],}d|dvr�q�|d|j
vr�q�t t�|�|d��d�}|d�|�|
�!|d�q�|j"D]#}
t t�|�|
d|j��d�}|d�|�|
�!|
d|j�q�|j�r*t t�|�d|j��d�}|d�|�|
�!d|j�|j	D]!}||
v�rM|�|j��rMt t�|�|��d�}|d�|��q-d
}|j
j#�r�|j
j#\}}|�tjd�}t�|�|��|d<|�r�t t�|�|j$��d�}|d�%d|�|j$|j	v�r�t�|j$�d}|j	�|j$�tt�|j$�t�|�|j$��t�|j|��}	|d�|	�t�|�|j
j&d�}|�'t�|j$�d||�|
�!|j$�d}d}|j
j(�r|j
j(D];\}}}|�)d�d}||j	v�r�|j	�|�|dk�rd}|dk�rd}|d�t*t�|�t�|�t�|����q�|�r6|�r6|d�t*d|j+dt�|j$���|�rS|j�rS|d�t*d|j+dt�|jdd���t,t�|j-d �|j|�d
S)!z�Write the metainfo file content.opf It contains bibliographic data,
        a file list and the spine (the reading order).
        zwriting content.opf file...z
.buildinfor�content.opf�toc.ncxrz	Thumbs.dbzehthumbs.dbz	.DS_Storez	nav.xhtml�.epubr
Nrl)z.jsz.xmlz!unknown mimetype for %s, ignoringrN�unknown_project_filesr}r�r�#r?TrrFr)�imager9rrz
content.opf_t).r�rrr(r��endswith�os�sepr��filesr\�
epub_basename�epub_exclude_files�
ignored_filesrMrvrQ�walk�sort�sortedrr�r��media_typesr�rGr&r[rwrgrrVr3r��domain_indices�
epub_cover�coverpage_namer��projectr
�
epub_guide�splitr7�guide_titlesrr)rXr'�olen�root�dirsr2r�r�r�r��
spinefiles�refnode�spinerrc�	html_tmplr.�ctx�auto_add_cover�auto_add_tocr8r:r9r�r0r0r1�
build_content�s�
��

�
��

 
�
��



�
��zEpubBuilder.build_contentr�rn�incrcCs@|r	|jd7_|jd7_td|j|j|d|dg�S)z;Create a new entry in the toc from the node at given level.r�z
navPoint%dr>r?)r=rSr;)rXr�rnrLr0r0r1�new_navpointcs�zEpubBuilder.new_navpointcCs|g}|�tddddg��d}d}|D]�}|dsq|d�d�d}||jvr)q|d|jjkr2q|d|krP|�||�}|��|d	j�|�|�|�nf|d|d
kr�|d
7}|ro|jj	ro|d	j�|�||d��|�||�}|d	j�|�|�|�n3|d|kr�|dt
|�kr�|��|dt
|�ks�|d}|�||�}|d	j�|�|�|�n�|}q|djS)z�Create the toc navigation structure.

        Subelements of a node are nested inside the navpoint.  For nested nodes
        the parent node is reinserted in the subnav.
        �dummyrrLNr>r?r-rnrlr�F)rvr;r?r5r\�
epub_tocdepthrM�popr@�epub_tocdupr�)rXr�navstackrn�lastnoder�r�r<r0r0r1�build_navpointslsF
�
zEpubBuilder.build_navpoints�	navpointscCs6i}|jj|d<t�|jj�|d<||d<||d<|S)z]Create a dictionary with all metadata for the toc.ncx file
        properly escaped.
        rr9rnrU)r\r!r[rwr)rXrnrUr'r0r0r1�toc_metadata�szEpubBuilder.toc_metadatacCs�t�td��|jjdkr%|jj|jj|ddd�}|�|g�}|�	|�n|j
}|�|�|�|�}t
dd�|j
D��}t||jj�}tt�|jd�|j|�||��dS)	z Write the metainfo file toc.ncx.zwriting toc.ncx file...�defaultFr�css�|]}|dVqdS)rnNr0)�.0r�r0r0r1�	<genexpr>�s�z(EpubBuilder.build_toc.<locals>.<genexpr>z	toc.ncx_tN)r�rrr\�
epub_tocscoperer�r�rzr�rVr�rT�max�minrOrrr�rr�rV)rXrhrVrUrnr0r0r1�	build_toc�s �


�zEpubBuilder.build_toccCs�|jjd}t�td�|�t�|j|�}t|dt	��8}|�
t�|jd�dt�dD]}|�
t�|j|�|t	�q*|jD]}|�
t�|j|�|t	�q<Wd�dS1sVwYdS)z~Write the epub file.

        It is a zip file with the mimetype file stored uncompressed as the first
        entry.
        r+zwriting %s file...�wr)rr)r*N)
r\r3r�rrrr�r�rr	�writer
r2)rXr�
epub_filenamerNr�r0r0r1�
build_epub�s
�"�zEpubBuilder.build_epub)rEN)r�)rNN)r)T)Er+r,r-�__doc__�
copysource�supported_image_types�supported_remote_images�add_permalinks�allow_sharp_as_current_path�embedded�download_support�html_scaled_image_link�search�COVERPAGE_NAMEr<�TOCTREE_TEMPLATEru�LINK_TARGET_TEMPLATEr��CSS_LINK_TARGET_CLASSr��GUIDE_TITLESr@�MEDIA_TYPESr9�	REFURI_REr�rrrPrr^rr.rrbrgrrrrzr�r�r�r�rr�r�r�r�r�r6r�rrrr
rrr(rKrAr;rMrTrVr]ra�
__classcell__r0r0rYr1rK{sn	.	

!D*

'
����

$o"	",
rK)rB)Arbr[r0�rer�typingrrrrrr�zipfiler	r
r�docutilsr�docutils.nodesr
r�docutils.utilsr�sphinxr�sphinx.builders.htmlrr�
sphinx.localer�sphinx.utilrr�sphinx.util.fileutilr�sphinx.util.i18nr�sphinx.util.osutilrr�PILr�ImportError�	getLoggerr+r�rlrmrnr�r�rorprqr��compilerrr&r3r7r;r.rJrxrKr0r0r0r1�<module>sh
 �
	��