U
    \ªShq  ã                   @  sâ  d Z ddlmZ ddlZddlZddl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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 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'm(Z( zddl)m*Z* W n e+k
r   dZ*Y nX e ,e-¡Z.dZ/dZ0dZ1dZ2dZ3dZ4dddœZ5dddd d!d"d#d#d$d%d&d'œZ6d(Z7e 8d)¡Z9G d*d+„ d+e	ƒZ:G d,d-„ d-e	ƒZ;G d.d/„ d/e	ƒZ<G d0d1„ d1e	ƒZ=d9d3d3d3d4œd5d6„Z>e>Z?G d7d8„ d8eƒZ@dS ):z#Base class of epub2/epub3 builders.é    )ÚannotationsN)Úpath)ÚAnyÚ
NamedTuple)Úquote)ÚZIP_DEFLATEDÚ
ZIP_STOREDÚZipFile)Únodes)ÚElementÚNode)Úsmartquotes)Úaddnodes)Ú	BuildInfoÚStandaloneHTMLBuilder)Ú__)Úlogging)Ústatus_iterator)Úcopy_asset_file)Úformat_date)ÚcopyfileÚ	ensuredir)ÚImagezepub-cover.xhtmlztoctree-l%dz
 [%(uri)s]z#%dZ	Footnoteszlink-targetzTable of ContentsZCover)ÚtocÚcoverzapplication/xhtml+xmlztext/cssú	image/pngz
image/webpú	image/gifúimage/svg+xmlú
image/jpegzfont/otfzfont/ttfz	font/woff)ú.xhtmlz.cssz.pngz.webpz.gifú.svgz.jpgz.jpegz.otfz.ttfz.woff)r    z([^#:]*#)(.*)c                   @  s&   e Zd ZU ded< ded< ded< dS )ÚManifestItemÚstrÚhrefÚidÚ
media_typeN©Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r+   r+   úM/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/builders/_epub_base.pyr!   Q   s   
r!   c                   @  s   e Zd ZU ded< ded< dS )ÚSpiner"   ZidrefÚboolZlinearNr&   r+   r+   r+   r,   r-   W   s   
r-   c                   @  s&   e Zd ZU ded< ded< ded< dS )ÚGuider"   ÚtypeÚtitleÚuriNr&   r+   r+   r+   r,   r/   \   s   
r/   c                   @  s6   e Zd ZU ded< ded< ded< ded< ded< d	S )
ÚNavPointr"   ÚnavpointÚintÚ	playorderÚtextÚrefuriz	list[Any]ÚchildrenNr&   r+   r+   r+   r,   r3   b   s
   
r3   Úenr"   )ÚtÚlanguageÚreturnc                 C  s2   |   dd¡} t | ¡} t | |¡} |   dd¡} | S )Nz&quot;ú")Úreplacer   ZeducateDashesOldSchoolZeducateQuotes)r;   r<   r+   r+   r,   Úsphinx_smarty_pantsk   s
    
r@   c                      s*  e Zd ZdZdZddddgZdZdZdZdZ	dZ
dZdZeZeZeZeZeZeZeZdZdZd	d
œ‡ fdd„Zdd
œdd„Zdd
œdd„Zdddœdd„Z ddddœdd„Z!dd	dœdd„Z"d	d
œdd „Z#dd	d!œd"d#„Z$dddd$œd%d&„Z%d'd	d(œd)d*„Z&dad'dd	d,œd-d.„Z'dd'd	d/œ‡ fd0d1„Z(d2d	d(œd3d4„Z)dd5d6œd7d8„Z*d	d
œd9d:„Z+d	d
œ‡ fd;d<„Z,d	d
œd=d>„Z-dbddAddBdCd	dDœ‡ fdEdF„Z.d	d
œdGdH„Z/dcdd	dJœdKdL„Z0dMd
œdNdO„Z1d	d
œdPdQ„Z2dddMdRd5dSdTœdUdV„Z3ddWdœdXdY„Z4dRdWdMdZœd[d\„Z5d	d
œd]d^„Z6d	d
œd_d`„Z7‡  Z8S )eÚ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.
    Fr   r   r   r   TÚ ÚNone)r=   c                   s@   t ƒ  ¡  d| _d| _d| _d| _i | _|  dd¡| _g | _	d S )Nr   r   Ú	use_indexÚepub)
ÚsuperÚinitÚ
out_suffixZlink_suffixr6   ÚtocidÚid_cacheZget_builder_configrD   Úrefnodes©Úself©Ú	__class__r+   r,   rG   ž   s    
zEpubBuilder.initr   c                 C  s   t | j| jddgƒS )NÚhtmlrE   )r   ÚconfigÚtagsrL   r+   r+   r,   Úcreate_build_info©   s    zEpubBuilder.create_build_infoztuple[str, dict]c                 C  s   | j j| j jfS ©N)rQ   Z
epub_themeZepub_theme_optionsrL   r+   r+   r,   Úget_theme_config¬   s    zEpubBuilder.get_theme_configr"   )Únamer=   c                 C  s.   | j  |¡}|s*d| j d¡ }|| j |< |S )zReturn a unique id for name.zepub-%drE   )rJ   ÚgetÚenvZnew_serialno)rM   rV   r$   r+   r+   r,   Úmake_id°   s
    
zEpubBuilder.make_idr   zlist[dict[str, Any]])ÚdoctreeÚresultr=   c              
   C  sª   t |tjƒr„| d¡r„|d }| d¡r,|S |jjd }tdddƒD ]<}| j| |krD| 	|t
 |¡tt
 | ¡ ¡ƒdœ¡  q¦qDn"t |tjƒr¦|D ]}|  ||¡}q”|S )z>Collect section titles, their depth in the toc and the refuri.r8   )zhttp://zhttps://zirc:zmailto:Úclassesé   r   éÿÿÿÿ©Úlevelr8   r7   )Ú
isinstancer
   Ú	referencerW   Ú
startswithÚparentÚ
attributesÚrangeÚtoctree_templateÚappendrP   ÚescapeÚsspÚastextr   Úget_refnodes)rM   rZ   r[   r8   r\   r`   Úelemr+   r+   r,   rl   ¹   s"    
ýzEpubBuilder.get_refnodes)r
   r=   c                 C  sJ   t ƒ }|D ]:}|d |kr6tjtdƒ|d ddd q
| |d ¡ q
d S )Nr8   zduplicated ToC entry found: %srE   Zduplicated_toc_entry©r0   Úsubtype)ÚsetÚloggerÚwarningr   Úadd)rM   r
   ZappearedÚnoder+   r+   r,   Úcheck_refnodesÑ   s    üzEpubBuilder.check_refnodesc                 C  sl   | j j| jj| ddd}|  |g ¡| _t | jj¡}|r\|d7 }| jD ]}||d  |d< qF|  | j¡ dS )zwGet the total table of contents, containing the root_doc
        and pre and post files not managed by sphinx.
        FT©Zprune_toctreesZincludehiddenú/r8   N)	rX   Úget_and_resolve_doctreerQ   Úroot_docrl   rK   r   ÚdirnameÚtoc_add_files)rM   rZ   Z
master_dirÚitemr+   r+   r,   Úget_tocÞ   s     þ
zEpubBuilder.get_toc)rK   r=   c              
   C  s°   |  ddt | jj| j ¡tt | jj| jj  	¡ ¡ƒdœ¡ t
| jjƒD ],\}}|  ddt |¡tt |¡ƒdœ¡ qJ| jjD ]*\}}| dt |¡tt |¡ƒdœ¡ q€dS )zDAdd the root_doc, pre and post files to a list of refnodes.
        r   é   r_   N)ÚinsertrP   ri   rQ   ry   rH   rj   rX   Útitlesrk   ÚreversedZepub_pre_filesZepub_post_filesrh   )rM   rK   Úfiler7   r+   r+   r,   r{   í   s&    ÿýý
ýzEpubBuilder.toc_add_files)ÚprefixÚfragmentr=   c                 C  s   ||  dd¡ S )z;Return a href/id attribute with colons replaced by hyphens.ú:ú-)r?   )rM   rƒ   r„   r+   r+   r,   Úfix_fragment  s    zEpubBuilder.fix_fragmentúnodes.document©Útreer=   c                   sÒ   dddœ‡ fdd„}|  tj¡D ]X}d|kr\ˆ j |d ¡}|r\ˆ  | d¡| d¡¡|d< d	|kr ˆ  d
|d	 ¡|d	< q |  tj¡D ],}||ƒ |jdd}t	|tj
ƒr†||ƒ q†|  tj¡D ]}||ƒ qÀdS )zªReplace colons with hyphens in href and id attributes.

        Some readers crash because they interpret the part as a
        transport protocol specification.
        r   rC   )rt   r=   c                   s<   g }| d D ]"}ˆ   d|¡}||kr| |¡ q|| d< dS )zUpdate IDs of given *node*.ÚidsrB   N)r‡   rh   )rt   Znew_idsZnode_idZnew_idrL   r+   r,   Úupdate_node_id  s    z+EpubBuilder.fix_ids.<locals>.update_node_idr8   r~   é   ÚrefidrB   T)ZascendN)Úfindallr
   rb   Ú	refuri_reÚmatchr‡   ÚgroupÚtargetÚ	next_nodera   r   r   Údesc_signature)rM   rŠ   rŒ   rb   Úmr“   r”   r•   r+   rL   r,   Úfix_ids  s    	
zEpubBuilder.fix_idsÚinline)rŠ   Ú	show_urlsr=   c                 C  sj  ddddœdd„}dddddœd	d
„}dddœdd„}|dkrBdS |dkrjt | tj¡ƒ}||ƒ\}}d}	t| tj¡ƒD ]ê}
|
 dd¡}| d¡rz||
 ¡ krz|
j	 
|
¡d }|dkrò| jd|i }t ||¡}|d  | j¡ |
j	 ||¡ qz|dkrzt|	 }|	d7 }	|||ƒ}|
j	 ||¡ ||||ƒ}| ||¡ |d d |d< | |d d ¡ |d7 }qzdS )z+Add visible link targets for external linksrˆ   r"   znodes.footnote_reference)ÚdocÚlabelr=   c                 S  s(   t  d¡}| t  |¡¡ |  |¡ |S )z.Create a footnote_reference node with childrenz[#]_)r
   Zfootnote_referencerh   ÚTextZnote_autofootnote_ref)rš   r›   Úfootnote_refr+   r+   r,   Úmake_footnote_ref+  s    

z8EpubBuilder.add_visible_links.<locals>.make_footnote_refznodes.footnote)rš   r›   r2   r=   c                 S  sN   t  |¡}t  ¡ }| t  |¡¡ | |¡ | dt  d|¡¡ |  |¡ |S )z$Create a footnote node with childrenr   rB   )r
   ÚfootnoteZ	paragraphrh   rœ   r   r›   Znote_autofootnote)rš   r›   r2   rŸ   Úparar+   r+   r,   Úmake_footnote2  s    


z4EpubBuilder.add_visible_links.<locals>.make_footnoteztuple[Element, int]r‰   c                 S  sº   t |  tj¡ƒ}|r2|d }|j|j |¡d fS |  tj¡D ]6}t|ƒdkr>| ¡ t	kr>|j|j |¡d f  S q>t
|  tj¡ƒ}t ¡ }| t t	¡¡ | |¡ || |¡d fS )zfFind or create a spot to place footnotes.

            The function returns the tuple (parent, index).r^   r~   )Úlistr   r
   rŸ   rd   ÚindexZrubricÚlenrk   ÚFOOTNOTES_RUBRIC_NAMEÚnextÚdocumentrh   rœ   )rŠ   ZfnsÚfnrt   rš   Zrubr+   r+   r,   Úfootnote_spot<  s    
z4EpubBuilder.add_visible_links.<locals>.footnote_spotÚnoNrŸ   r~   r8   rB   )zhttp:zhttps:zftp:r˜   r2   r\   r‹   r   rŽ   )r¦   r   r
   r§   r¢   rb   rW   rc   rk   rd   r£   Úlink_target_templater˜   rh   Úcss_link_target_classr   ÚFOOTNOTE_LABEL_TEMPLATEZadd_backref)rM   rŠ   r™   rž   r¡   r©   rš   Zfn_spotZfn_idxÚnrrt   r2   ÚidxÚlinkr›   r   rŸ   r+   r+   r,   Úadd_visible_links(  s8    

zEpubBuilder.add_visible_links)ÚdocnamerZ   r=   c                   s,   |   |¡ |  || jj¡ tƒ  ||¡ dS )z•Write one document file.

        This method is overwritten in order to fix fragment identifiers
        and to add visible external links.
        N)r—   r±   rQ   Zepub_show_urlsrF   Ú	write_doc)rM   r²   rZ   rN   r+   r,   r³   k  s    
zEpubBuilder.write_docz'list[tuple[str, list[tuple[str, Any]]]]c                 C  sÀ   |D ]¶\}}|D ]¨\}\}}}t |ƒD ]<\}\}}	| j |	¡}
|
r&||  |
 d¡|
 d¡¡f||< q&|D ]N\}}t |ƒD ]<\}\}}	| j |	¡}
|
rx||  |
 d¡|
 d¡¡f||< qxqhqqdS )z'Fix href attributes for genindex pages.r~   r   N)Ú	enumerater   r‘   r‡   r’   )rM   rŠ   Ú_keyÚcolumnsZ
_entrynameÚlinksZsubitemsÚiZismainr°   r–   Z_subentrynameZsubentrylinksr+   r+   r,   Úfix_genindexu  s    ÿ
ÿzEpubBuilder.fix_genindexr.   )Úfilenamer=   c                 C  s   t  |¡d }|tkS )z=Does the filename extension indicate a vector graphic format?r^   )r   ÚsplitextÚVECTOR_GRAPHICS_EXTENSIONS)rM   rº   Úextr+   r+   r,   Úis_vector_graphics‡  s    zEpubBuilder.is_vector_graphicsc           	      C  sÎ  t t | j| j¡ƒ t| jtdƒdt| jƒ| j	j
ƒD ]’}| j| }zt t | j|¡¡}W n¢ tk
rþ   |  |¡st tdƒt | j|¡¡ z&tt | j|¡t | j| j|¡ƒ W n> tk
rô } z t tdƒt | j|¡|¡ W 5 d}~X Y nX Y q4Y nX | jjr|jdkr| ¡ }| jjdkrj|j\}}| jj}||krjt|| | ƒ}| ||ftj¡}z| t | j| j|¡¡ W q4 tk
rÆ } z t tdƒt | j|¡|¡ W 5 d}~X Y q4X q4dS )	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.
        zcopying images... Zbrownz-cannot read image file %r: copying it insteadzcannot copy image file %r: %sN)ÚPr   zcannot write image file %r: %s)r   r   ÚjoinÚoutdirZimagedirr   Úimagesr   r¤   ZappÚ	verbosityr   ÚopenÚsrcdirÚOSErrorr¾   rq   rr   r   rQ   Úepub_fix_imagesÚmodeÚconvertÚepub_max_image_widthÚsizeÚroundÚresizeZBICUBICÚsave)	rM   ÚsrcÚdestZimgÚerrÚwidthÚheightÚnwZnhr+   r+   r,   Úcopy_image_files_pilŒ  sN     ÿ



ÿÿ
 ÿ




 ÿz EpubBuilder.copy_image_files_pilc                   sL   | j rH| jjs| jjr>ts4t tdƒ¡ tƒ  	¡  qH|  
¡  n
tƒ  	¡  dS )zzCopy image files to destination directory.
        This overwritten method can use Pillow to convert image files.
        z&Pillow not found - copying image filesN)rÂ   rQ   rÇ   rÊ   r   rq   rr   r   rF   Úcopy_image_filesrÕ   rL   rN   r+   r,   rÖ   ³  s    
zEpubBuilder.copy_image_filesc                 C  s   d S rT   r+   rL   r+   r+   r,   Úcopy_download_filesÁ  s    zEpubBuilder.copy_download_filesú	page.htmlNÚdictz
str | Noner   )ÚpagenameÚaddctxÚtemplatenameÚoutfilenameÚ	event_argr=   c                   sL   |  d¡r*d|kr*| jsdS |  |d ¡ | j|d< tƒ  |||||¡ dS )z…Create a rendered page.

        This method is overwritten for genindex pages in order to fix href link
        attributes.
        ÚgenindexZgenindexentriesNÚdoctype)rc   rD   r¹   rà   rF   Úhandle_page)rM   rÚ   rÛ   rÜ   rÝ   rÞ   rN   r+   r,   rá   Ä  s    
zEpubBuilder.handle_pagec                 C  s(   t  tdƒ¡ tt | jd¡| jƒ dS )z!Write the metainfo file mimetype.zwriting mimetype file...ÚmimetypeN)rq   Úinfor   r   r   rÀ   Útemplate_dirrÁ   rL   r+   r+   r,   Úbuild_mimetypeÒ  s    zEpubBuilder.build_mimetypeúMETA-INF/container.xml)Úoutnamer=   c                 C  s<   t  tdƒ¡ t | jd¡}t|ƒ tt | jd¡|ƒ dS )z/Write the metainfo file META-INF/container.xml.z&writing META-INF/container.xml file...zMETA-INFzcontainer.xmlN)	rq   rã   r   r   rÀ   rÁ   r   r   rä   )rM   rç   rÁ   r+   r+   r,   Úbuild_container×  s    zEpubBuilder.build_containerzdict[str, Any]c                 C  sÆ   i }t  | jj¡|d< t  | jj¡|d< t  | jj¡|d< t  | jj¡|d< t  | jj¡|d< t  | jj¡|d< t  | jj	¡|d< t  | jj
¡|d< t  td	d
d¡|d< g |d< g |d< g |d< |S )zaCreate a dictionary with all metadata for the content.opf
        file properly escaped.
        r1   ÚauthorÚuidÚlangZ	publisherÚ	copyrightÚschemer$   z%Y-%m-%dr:   )r<   ÚdateÚmanifest_itemsÚspinesÚguides)rP   ri   rQ   Ú
epub_titleZepub_authorÚepub_uidZepub_languageZepub_publisherZepub_copyrightZepub_schemeZepub_identifierr   )rM   Úmetadatar+   r+   r,   Úcontent_metadataÞ  s    zEpubBuilder.content_metadatac                 C  sÔ  t  tdƒ¡ |  ¡ }| j tj¡s4|  jtj7  _t| jƒ}g | _	dddddddd	d
| j
jd g
| j
j | _| js†| j d| j ¡ t | j¡D ]Ð\}}}| ¡  t|ƒD ]´}t ||¡|d… }|| jkrÐq¬t |¡d }|| jkr
|dkr¬t jtdƒ|ddd q¬| tjd¡}tt t|ƒ¡t |  |¡¡t | j| ¡ƒ}	|d  |	¡ | j	 |¡ q¬q’tƒ }
| j D ]b}d|d kr†qp|d | jkršqpt!t |  |d ¡¡dƒ}|d  |¡ |
 "|d ¡ qp| j#D ]H}t!t |  |d | j ¡¡dƒ}|d  |¡ |
 "|d | j ¡ qÚ| jrft!t |  d| j ¡¡dƒ}|d  |¡ |
 "d| j ¡ | j	D ]B}||
krl| | j¡rlt!t |  |¡¡dƒ}|d  |¡ qld}| j
j$r¼| j
j$\}}| tjd¡}t |  |¡¡|d< |r¼t!t |  | j%¡¡dƒ}|d  &d|¡ | j%| j	kr‚t | j%¡d }| j	 | j%¡ tt | j%¡t |  | j%¡¡t | j| ¡ƒ}	|d  |	¡ t |¡| j
j'dœ}|  (t | j%¡d ||¡ |
 "| j%¡ d}d}| j
j)rN| j
j)D ]v\}}}| *d¡d }|| j	kr| j	 |¡ |dkrd}|dkr"d}|d  t+t |¡t |¡t |¡ƒ¡ qÖ|r~|r~|d  t+d| j,d t | j%¡ƒ¡ |r¸| j r¸|d  t+d| j,d t | j d d ¡ƒ¡ 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).
        zwriting content.opf file...z
.buildinforâ   úcontent.opfútoc.ncxræ   z	Thumbs.dbzehthumbs.dbz	.DS_Storez	nav.xhtmlú.epubrß   Nr^   )z.jsz.xmlz!unknown mimetype for %s, ignoringrE   Zunknown_project_filesrn   rw   rï   ú#r8   Trð   r   Fr   )Úimager1   r   rñ   zcontent.opf_t)/rq   rã   r   rõ   rÁ   ÚendswithÚosÚsepr¤   ÚfilesrQ   Úepub_basenameZepub_exclude_filesÚignored_filesrD   rh   rH   ÚwalkÚsortÚsortedr   rÀ   r»   Úmedia_typesrr   r?   r!   rP   ri   r   rY   rp   rK   r-   rs   Zdomain_indicesZ
epub_coverÚcoverpage_namer   Úprojectrá   Z
epub_guideÚsplitr/   Úguide_titlesr   rä   )rM   rô   ZolenÚrootÚdirsrþ   r¨   rº   r½   r|   Z
spinefilesZrefnodeZspinerã   rV   Z	html_tmplrú   ÚctxZauto_add_coverZauto_add_tocr0   r2   r1   r‚   r+   r+   r,   Úbuild_contentñ  sÜ    
    
ýü
 ÿþ

 

þ  ÿ


þ

þþzEpubBuilder.build_contentr5   r3   )rt   r`   Úincrr=   c                 C  s@   |r|  j d7  _ |  jd7  _td| j | j |d |d g ƒS )z;Create a new entry in the toc from the node at given level.r~   z
navPoint%dr7   r8   )r6   rI   r3   )rM   rt   r`   r  r+   r+   r,   Únew_navpoint`  s      ÿzEpubBuilder.new_navpointzlist[NavPoint]c                 C  sx  g }|  tddddg ƒ¡ d}d}|D ]D}|d s6q&|d  d¡d }|| jkrTq&|d | jjkrfq&|d |kr¢|  ||¡}| ¡  |d	 j  |¡ |  |¡ nÆ|d |d
 kr
|d
7 }|râ| jj	râ|d	 j  |  ||d¡¡ |  ||¡}|d	 j  |¡ |  |¡ n^|d |k rf|d t
|ƒk r6| ¡  q|d }|  ||¡}|d	 j  |¡ |  |¡ n‚ |}q&|d jS )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.
        Údummyr   rB   Nr7   r8   rù   r`   r^   r~   F)rh   r3   r  r   rQ   Úepub_tocdepthr  Úpopr9   Zepub_tocdupr¤   )rM   r
   Znavstackr`   Zlastnodert   r‚   r4   r+   r+   r,   Úbuild_navpointsi  sD    

zEpubBuilder.build_navpoints)r`   Ú	navpointsr=   c                 C  s6   i }| j j|d< t | j j¡|d< ||d< ||d< |S )z]Create a dictionary with all metadata for the toc.ncx file
        properly escaped.
        rê   r1   r`   r  )rQ   ró   rP   ri   rò   )rM   r`   r  rô   r+   r+   r,   Útoc_metadata•  s    zEpubBuilder.toc_metadatac                 C  sª   t  tdƒ¡ | jjdkrJ| jj| jj| ddd}|  |g ¡}|  	|¡ n| j
}|  |¡ |  |¡}tdd„ | j
D ƒƒ}t|| jjƒ}tt | jd¡| j|  ||¡ƒ dS )	z Write the metainfo file toc.ncx.zwriting toc.ncx file...ÚdefaultFrv   c                 s  s   | ]}|d  V  qdS )r`   Nr+   )Ú.0r|   r+   r+   r,   Ú	<genexpr>¯  s     z(EpubBuilder.build_toc.<locals>.<genexpr>z	toc.ncx_tN)rq   rã   r   rQ   Zepub_tocscoperX   rx   ry   rl   r{   rK   ru   r  ÚmaxÚminr  r   r   rÀ   rä   rÁ   r  )rM   rZ   rK   r  r`   r+   r+   r,   Ú	build_toc   s"     þ


ÿzEpubBuilder.build_tocc              	   C  s¤   | j jd }t tdƒ|¡ t | j|¡}t|dt	ƒd}| 
t | jd¡dt¡ dD ]}| 
t | j|¡|t	¡ qT| jD ]}| 
t | j|¡|t	¡ qxW 5 Q R X dS )z~Write the epub file.

        It is a zip file with the mimetype file stored uncompressed as the first
        entry.
        rø   zwriting %s file...Úwrâ   )ræ   rö   r÷   N)rQ   rÿ   rq   rã   r   r   rÀ   rÁ   r	   r   Úwriter   rþ   )rM   rç   Zepub_filenamerE   rº   r+   r+   r,   Ú
build_epub´  s    
zEpubBuilder.build_epub)r˜   )rØ   NN)ræ   )T)9r'   r(   r)   Ú__doc__Z
copysourceZsupported_image_typesZsupported_remote_imagesZadd_permalinksZallow_sharp_as_current_pathZembeddedZdownload_supportZhtml_scaled_image_linkÚsearchÚCOVERPAGE_NAMEr  ÚTOCTREE_TEMPLATErg   ÚLINK_TARGET_TEMPLATEr«   ÚCSS_LINK_TARGET_CLASSr¬   ÚGUIDE_TITLESr  ÚMEDIA_TYPESr  Ú	REFURI_REr   rä   rà   rG   rS   rU   rY   rl   ru   r}   r{   r‡   r—   r±   r³   r¹   r¾   rÕ   rÖ   r×   rá   rå   rè   rõ   r  r  r  r  r  r  Ú__classcell__r+   r+   rN   r,   rA   x   sf   	ÿ	!C
'    ÿo	,rA   )r:   )Ar  Ú
__future__r   rP   rü   Úrer   Útypingr   r   Úurllib.parser   Úzipfiler   r   r	   Zdocutilsr
   Zdocutils.nodesr   r   Zdocutils.utilsr   Zsphinxr   Zsphinx.builders.htmlr   r   Zsphinx.localer   Zsphinx.utilr   Zsphinx.util.displayr   Zsphinx.util.fileutilr   Zsphinx.util.i18nr   Zsphinx.util.osutilr   r   ZPILr   ÚImportErrorÚ	getLoggerr'   rq   r   r!  r"  r­   r¥   r#  r$  r%  r¼   Úcompiler&  r!   r-   r/   r3   r@   rj   rA   r+   r+   r+   r,   Ú<module>   sl   

	þõ
	