3

T'íc*ã@s<dZddlZddlmZddlmZmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZddlmZmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZeje ƒZ!Gdd„deƒZ"dddœZ#dddœZ$dddœZ%dZ&dZ'Gdd„dej(ƒZ)eddœdd„Z*eeddœd d!„Z+eee,efdœd"d#„Z-dS)$z5Build epub3 files.

Originally derived from epub.py.
éN)Úpath)ÚAnyÚDictÚListÚ
NamedTupleÚSetÚTuple)Úpackage_dir)ÚSphinx)Ú
_epub_base)ÚENUMÚConfig)Ú__)ÚloggingÚxmlname_checker)Úcopy_asset_file)Úformat_date)Ú
make_filenamec@seZdZUeeeedS)ÚNavPointN)	Ú__name__Ú
__module__Ú__qualname__ÚstrÚtextÚrefurirrÚchildren©rrú7/tmp/pip-build-gk9425m9/sphinx/sphinx/builders/epub3.pyrs
rZltrÚrtl)Ú
horizontalÚverticalr rzvertical-rlz
horizontal-tb)r rz<!DOCTYPE html>zU<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">cs¸eZdZdZdZedƒZdZej	e
ddƒZeZ
eZdZdd	œd
d„Zed	œ‡fdd
„Zeeddœ‡fdd„Zeeeefeedœdd„Zeeedœdd„Zdd	œdd„Z‡ZS)ÚEpub3BuilderzÙ
    Builder that outputs epub3 files.

    It creates the metainfo files content.opf, nav.xhtml, toc.ncx, mimetype,
    and META-INF/container.xml. Afterwards, all necessary files are zipped to
    an epub file.
    ÚepubzThe ePub file is in %(outdir)s.FZ	templatesZepub3TN)ÚreturncCs<|jƒ|jƒ|jƒ|jƒ|jƒ|jƒ|jƒdS)z/Create the metainfo files and finally the epub.N)Zget_tocZbuild_mimetypeZbuild_containerZ
build_contentÚbuild_navigation_docZ	build_tocZ
build_epub)ÚselfrrrÚ
handle_finishFszEpub3Builder.handle_finishcs†|jj}tƒjƒ}tj|jjƒ|d<tj|jjƒ|d<tj	|ƒ|d<t
j	|ƒ|d<tjtdƒƒ|d<tj|jjƒ|d<|jj
|d<|S)	zaCreate a dictionary with all metadata for the content.opf
        file properly escaped.
        ÚdescriptionZcontributorZpage_progression_directionZibook_scroll_axisz%Y-%m-%dT%H:%M:%SZÚdateÚversionÚepub_version)ÚconfigÚepub_writing_modeÚsuperÚcontent_metadataÚhtmlÚescapeÚepub_descriptionÚepub_contributorÚPAGE_PROGRESSION_DIRECTIONSÚgetÚIBOOK_SCROLL_AXISrr)r*)r%Úwriting_modeÚmetadata)Ú	__class__rrr.Ps
zEpub3Builder.content_metadata)Údocnamesr#csJtƒj|ƒ|jj}tj|ƒ|jd<|j|jd<|j|jd<d|jd<dS)NZtheme_writing_modeÚhtml_tagÚuse_meta_charsetTZskip_ua_compatible)	r-Úprepare_writingr+r,ÚTHEME_WRITING_MODESr4Z
globalcontextr:r;)r%r9r6)r8rrr<`szEpub3Builder.prepare_writing)Únavnodesr#cCsBg}|jtddgƒƒd}x|D]}|ds2q"|djdƒd}||jkrPq"|d|jjkrbq"t|d|dgƒ}|d|kr¦|jƒ|d	jj|ƒ|j|ƒq"|d|dkrÚ|d7}|d
jj|ƒ|j|ƒq"|d|kr,x|dt|ƒkr|jƒqêW|d}|djj|ƒ|j|ƒq"t	dƒ‚q"W|djS)acCreate the toc navigation structure.

        This method is almost same as build_navpoints method in epub.py.
        This is because the logical navigation structure of epub3 is not
        different from one of epub2.

        The difference from build_navpoints method is templates which are used
        when generating navigation documents.
        Úrrrú#Úleveléz+Should never reach here. It might be a bug.éÿÿÿÿrCrC)
ÚappendrÚsplitZ
ignored_filesr+Ú
epub_tocdepthÚpoprÚlenÚRuntimeError)r%r>ZnavstackrAÚnodeÚfileZnavpointrrrÚ
build_navlistis8

zEpub3Builder.build_navlist)Únavlistr#cCs6i}tj|jjƒ|d<tj|jdƒ|d<||d<|S)z_Create a dictionary with all metadata for the nav.xhtml file
        properly escaped.
        ÚlangZtocZ
toc_localerM)r/r0r+Ú
epub_languageZguide_titles)r%rMr7rrrÚnavigation_doc_metadata“s
z$Epub3Builder.navigation_doc_metadatacCs’tjtdƒƒ|jjdkrJ|jj|jj|ddd}|j|gƒ}|j	|ƒn|j
}|j|ƒ}tt
j|jdƒ|j|j|ƒƒd|jkrŽ|jjdƒdS)z"Write the metainfo file nav.xhtml.zwriting nav.xhtml file...ÚdefaultF)Zprune_toctreesZ
includehiddenznav.xhtml_tz	nav.xhtmlN)ÚloggerÚinforr+Ú
epub_tocscopeÚenvZget_and_resolve_doctreeZroot_docZget_refnodesZ
toc_add_filesÚrefnodesrLrrÚjoinÚtemplate_dirZoutdirrPÚfilesrD)r%ZdoctreerVrMrrrr$s


z!Epub3Builder.build_navigation_doc)rrrÚ__doc__ÚnamerÚepilogZsupported_remote_imagesrrWr	rXÚDOCTYPEÚdoctypeÚHTML_TAGr:r;r&rr.rrr<rrrrLrPr$Ú
__classcell__rr)r8rr!4s
	 *
r!)Úappr#cCsú|jjdkrdS|jjs&tjtdƒƒtƒj|jj	ƒsDtjtdƒƒ|jj
sZtjtdƒƒ|jjsptjtdƒƒ|jjs†tjtdƒƒ|jj
sœtjtdƒƒ|jjs²tjtdƒƒ|jjsÈtjtd	ƒƒ|jjsÞtjtd
ƒƒ|jjsötjtdƒƒdS)Nr"zHconf value "epub_language" (or "language") should not be empty for EPUB3z2conf value "epub_uid" should be XML NAME for EPUB3zGconf value "epub_title" (or "html_title") should not be empty for EPUB3z6conf value "epub_author" should not be empty for EPUB3z;conf value "epub_contributor" should not be empty for EPUB3z;conf value "epub_description" should not be empty for EPUB3z9conf value "epub_publisher" should not be empty for EPUB3zIconf value "epub_copyright" (or "copyright")should not be empty for EPUB3z:conf value "epub_identifier" should not be empty for EPUB3z2conf value "version" should not be empty for EPUB3)Zbuilderr[r+rOrRÚwarningrrÚmatchÚepub_uidÚ
epub_titleÚepub_authorr2r1Úepub_publisherÚepub_copyrightÚepub_identifierr))rarrrÚvalidate_config_values³s,
rj)rar+r#cCszg}xj|jD]`}t|tƒr*|j|ifƒqy|\}}|j||fƒWqtk
rjtjtdƒ|ƒwYqXqW||_dS)z?This converts string styled epub_css_files to tuple styled one.zinvalid css_file: %r, ignoredN)Úepub_css_filesÚ
isinstancerrDÚ	ExceptionrRrbr)rar+rkÚentryÚfilenameÚattrsrrrÚconvert_epub_css_filesÚs
rqcCsâ|jtƒ|jddd„dƒ|jdddƒ|jdddƒ|jdidƒ|jd	d
d„dƒ|jddd„dƒ|jd
dd„dƒ|jddd„dƒ|jddd„dƒ|jdddƒ|jdddƒ|jdddƒ|jdfdƒ|jdfdƒ|jdgdƒ|jdgdƒ|jddd„dƒ|jdgdƒ|jdd dƒ|jd!d"dƒ|jd#d$dƒ|jd%d&dƒ|jd'd(dƒ|jd)d*dƒ|jd+d,d„dƒ|jd-ddƒ|jd.ddƒ|jd/d0dtd0d1ƒƒ|jd2td3d4|jd5tƒd6d"d"d7œS)8NZ
epub_basenamecSs
t|jƒS)N)rÚproject)r%rrrÚ<lambda>ïszsetup.<locals>.<lambda>r*g@r"Z
epub_themeZepub_theme_optionsrecSs|jS)N)rr)r%rrrrsósrfcSs|jS)N)Úauthor)r%rrrrsôsrOcSs
|jpdS)NÚen)Úlanguage)r%rrrrsõsrgcSs|jS)N)rt)r%rrrrsösrhcSs|jS)N)Ú	copyright)r%rrrrs÷sriÚunknownZepub_schemerdrUZ
epub_coverZ
epub_guideZepub_pre_filesZepub_post_filesrkcSs|jS)N)Zhtml_css_files)r+rrrrsÿsZepub_exclude_filesrFéZepub_tocdupTrTrQZepub_fix_imagesFZepub_max_image_widthrZepub_show_urlsÚinlineZepub_use_indexcSs|jS)N)Zhtml_use_index)r%rrrrssr1r2r,rr z
config-initedi )Úpriorityzbuilder-initedÚbuiltin)r)Zparallel_read_safeZparallel_write_safe)Zadd_builderr!Zadd_config_valuerÚconnectrqrj)rarrrÚsetupësF

r~).rZr/ÚosrÚtypingrrrrrrZsphinxr	Zsphinx.applicationr
Zsphinx.buildersrZ
sphinx.configrr
Z
sphinx.localerZsphinx.utilrrZsphinx.util.fileutilrZsphinx.util.i18nrZsphinx.util.osutilrÚ	getLoggerrrRrr3r5r=r]r_ZEpubBuilderr!rjrqrr~rrrrÚ<module>s4 
	'