ó
öÀ„\c           @   sÊ  d  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 m	 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 d d l m Z d d l m Z d d l m Z d d l m Z m Z y d d l m  Z  Wn; e! k
 rWy d d l  Z  WqXe! k
 rSd Z  qXXn Xe# r“d d l$ m% Z% m& Z& m' Z' m( Z( d d l) m* Z* n  e j+ e, ƒ Z- d Z. d Z/ d Z0 d Z1 d Z2 d Z3 i d d 6d d 6Z4 i
 d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d' d) 6d* d+ 6d, d- 6d. d/ 6Z5 dF Z6 e j7 d0 ƒ Z8 e d1 d2 d3 d4 g ƒ Z9 e d5 d6 d7 g ƒ Z: e d8 d9 d: d; g ƒ Z; e d< d= d> d? d@ dA g ƒ Z< dB dC „ Z= e= Z> dD e f dE „  ƒ  YZ? d S(G   sÚ   
    sphinx.builders._epub_base
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    Base class of epub2/epub3 builders.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t
   namedtuple(   t   path(   t   ZIP_DEFLATEDt
   ZIP_STOREDt   ZipFile(   t   nodes(   t   smartquotes(   t   addnodes(   t	   BuildInfot   StandaloneHTMLBuilder(   t   __(   t   logging(   t   status_iterator(   t   copy_asset_file(   t   format_date(   t	   ensuredirt   copyfile(   t   Image(   t   Anyt   Dictt   Listt   Tuple(   t   Sphinxu   epub-cover.xhtmlu   toctree-l%du
    [%(uri)s]u   #%du	   Footnotesu   link-targetu   Table of Contentst   tocu   Covert   covers   application/xhtml+xmls   .xhtmls   text/csss   .csss	   image/pngs   .pngs	   image/gifs   .gifs   image/svg+xmls   .svgs
   image/jpegs   .jpgs   .jpegs   application/x-font-otfs   .otfs   application/x-font-ttfs   .ttfs   application/font-woffs   .woffs   ([^#:]*#)(.*)t   ManifestItemt   hreft   idt
   media_typet   Spinet   idreft   lineart   Guidet   typet   titlet   urit   NavPointt   navpointt	   playordert   textt   refurit   childrent   enc         C   sI   |  j  d d ƒ }  t j |  ƒ }  t j |  | ƒ }  |  j  d d ƒ }  |  S(   Ns   &quot;t   "(   t   replaceR   t   educateDashesOldSchoolt   educateQuotes(   t   tt   language(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   sphinx_smarty_pantsb   s
    t   EpubBuilderc           B   sŽ  e  Z d  Z e Z d d d d g Z e Z e Z e Z e	 Z
 e Z e Z e Z e	 Z e Z e Z e Z e Z e Z e Z e Z d Z d Z d „  Z d „  Z  d „  Z! d	 „  Z" d
 „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d d „ Z) d „  Z* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ d d# d# d „ Z1 d „  Z2 d „  Z3 d „  Z4 d „  Z5 e	 d „ Z6 d „  Z7 d  „  Z8 d! „  Z9 d" „  Z: RS($   sÐ   
    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.
    s   image/svg+xmls	   image/pngs	   image/gifs
   image/jpegt    c         C   sS   t  j |  ƒ d |  _ d |  _ d |  _ d |  _ i  |  _ |  j d d ƒ |  _ d  S(   Ns   .xhtmli    t	   use_indext   epub(	   R	   t   initt
   out_suffixt   link_suffixR&   t   tocidt   id_cachet   get_builder_configR4   (   t   self(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyR6   ˜   s    					c         C   s   t  |  j |  j d d g ƒ S(   Nt   htmlR5   (   R   t   configt   tags(   R<   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   create_build_info£   s    c         C   s   |  j  j |  j  j f S(   N(   R>   t
   epub_themet   epub_theme_options(   R<   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   get_theme_config§   s    c         C   sB   |  j  j | ƒ } | s> d |  j j d ƒ } | |  j  | <n  | S(   s   Return a unique id for name.s   epub-%dR5   (   R:   t   gett   envt   new_serialno(   R<   t   nameR   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   make_id¬   s
    c         C   s^   | j  d d ƒ } | j  d d ƒ } | j  d d ƒ } | j  d d ƒ } | j  d	 d
 ƒ } | S(   s?   Replace all characters not allowed in text an attribute values.t   &s   &amp;t   <s   &lt;t   >s   &gt;R+   s   &quot;s   's   &#39;(   R,   (   R<   RG   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   esc¶   s    c         C   s  t  | t j ƒ rò | j d ƒ rò | d } | j d ƒ sg | j d ƒ sg | j d ƒ sg | j d ƒ rk | S| j j d } xš t d d d	 ƒ D]] } |  j | | k rŽ | j	 i | d
 6|  j
 | ƒ d 6t |  j
 | j ƒ  ƒ ƒ d 6ƒ PqŽ qŽ Wn& x# | j D] } |  j | | ƒ } qü W| S(   s>   Collect section titles, their depth in the toc and the refuri.R(   s   http://s   https://s   irc:s   mailto:t   classesi   i    iÿÿÿÿt   levelR'   (   t
   isinstanceR   t	   referenceRD   t
   startswitht   parentt
   attributest   ranget   toctree_templatet   appendRL   t   sspt   astextR)   t   get_refnodes(   R<   t   doctreet   resultR(   RM   RN   t   elem(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyRY   Á   s     !
	 c         C   sž   |  j  j |  j j |  d t d t ƒ} |  j | g  ƒ |  _ t j	 |  j j ƒ } | rŠ | d 7} x& |  j D] } | | d | d <qk Wn  |  j
 |  j ƒ d S(   sy   Get the total table of contents, containing the master_doc
        and pre and post files not managed by sphinx.
        t   prune_toctreest   includehiddent   /R(   N(   RE   t   get_and_resolve_doctreeR>   t
   master_doct   Falset   TrueRY   t   refnodesR   t   dirnamet   toc_add_files(   R<   RZ   t
   master_dirt   item(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   get_tocÙ   s    	
c         C   s  | j  d i d d 6|  j |  j j |  j ƒ d 6t |  j |  j j |  j j j ƒ  ƒ ƒ d 6ƒ x] t	 |  j j
 ƒ D]I \ } } | j  d i d d 6|  j | ƒ d 6t |  j | ƒ ƒ d 6ƒ qs WxT |  j j D]F \ } } | j i d d 6|  j | ƒ d 6t |  j | ƒ ƒ d 6ƒ qÍ Wd S(   sF   Add the master_doc, pre and post files to a list of refnodes.
        i    i   RN   R(   R'   N(   t   insertRL   R>   Ra   R7   RW   RE   t   titlesRX   t   reversedt   epub_pre_filest   epub_post_filesRV   (   R<   Rd   t   fileR'   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyRf   é   s    	'	c         C   s   | | j  d d ƒ S(   s;   Return a href/id attribute with colons replaced by hyphens.t   :t   -(   R,   (   R<   t   prefixt   fragment(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   fix_fragment   s    c   
      C   så  x™ | j  t j ƒ D]… } d | k ro |  j j | d ƒ } | ro |  j | j d ƒ | j d ƒ ƒ | d <qo n  d | k r |  j d | d ƒ | d <q q WxÛ | j  t j ƒ D]Ç } xG t | d ƒ D]5 \ } } d | k rÆ |  j d | ƒ | d | <qÆ qÆ W| j	 d t
 ƒ } | r¯ t | t j ƒ r¯ xJ t | d ƒ D]5 \ } } d | k r:|  j d | ƒ | d | <q:q:Wq¯ q¯ Wxd | j  t j ƒ D]P } | j d } g  } x' | D] }	 | j |  j d |	 ƒ ƒ q­W| | j d <qWd	 S(
   sª   Replace colons with hyphens in href and id attributes.

        Some readers crash because they interpret the part as a
        transport protocol specification.
        R(   i   i   t   refidR3   t   idsRp   t   siblingsN(   t   traverseR   RP   t	   refuri_ret   matchRt   t   groupt   targett	   enumeratet	   next_nodeRc   RO   t   ElementR   t   desc_signatureRS   RV   (
   R<   t   treet   nodet   mt   it   node_idR~   Rv   t   newidsR   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   fix_ids  s,    .!!(t   inlinec         C   sç  d „  } d „  } d „  } | d k r+ d S| d k rh | j  t j ƒ d } | | ƒ \ } } d }	 n  xx| j  t j ƒ D]d}
 |
 j d	 d
 ƒ } | j d ƒ sÀ | j d ƒ sÀ | j d ƒ r{ | |
 j ƒ  k r{ |
 j j |
 ƒ d } | d k rD|  j	 i | d 6} t j
 | | ƒ } | d j |  j ƒ |
 j j | | ƒ qß| d k rßt |	 } |	 d 7}	 | | | ƒ } |
 j j | | ƒ | | | | ƒ } | j | | ƒ | d d | d <| j | d d ƒ | d 7} qßq{ q{ Wd S(   s+   Add visible link targets for external linksc         S   s6   t  j d ƒ } | j t  j | ƒ ƒ |  j | ƒ | S(   s.   Create a footnote_reference node with childrens   [#]_(   R   t   footnote_referenceRV   t   Textt   note_autofootnote_ref(   t   doct   labelt   footnote_ref(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   make_footnote_ref(  s    c         S   sk   t  j | ƒ } t  j ƒ  } | j t  j | ƒ ƒ | j | ƒ | j d t  j d | ƒ ƒ |  j | ƒ | S(   s$   Create a footnote node with childreni    R3   (   R   t   footnotet	   paragraphRV   RŠ   Rj   R   t   note_autofootnote(   RŒ   R   R#   R   t   para(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   make_footnote0  s    c         S   s  |  j  t j ƒ } | r? | d } | j | j j | ƒ d f Sxe |  j  t j ƒ D]Q } t | j ƒ d k rR | j d j ƒ  t	 k rR | j | j j | ƒ d f SqR W|  j  t j
 ƒ d } t j ƒ  } | j t j t	 ƒ ƒ | j | ƒ | | j | ƒ d f S(   sf   Find or create a spot to place footnotes.

            The function returns the tuple (parent, index).iÿÿÿÿi   i    (   Rx   R   R   RR   t   indext   rubrict   lenR)   RX   t   FOOTNOTES_RUBRIC_NAMEt   documentRV   RŠ   (   R   t   fnst   fnR‚   RŒ   t   rub(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   footnote_spot;  s    	
!t   noNR   i    i   R(   R3   s   http:s   https:s   ftp:Rˆ   R#   RM   Rv   Ru   (   Rx   R   R™   RP   RD   RQ   RX   RR   R•   t   link_target_templateRˆ   RV   t   css_link_target_classRj   t   FOOTNOTE_LABEL_TEMPLATEt   add_backref(   R<   R   t	   show_urlsR   R”   R   RŒ   t   fn_spott   fn_idxt   nrR‚   R#   t   idxt   linkR   RŽ   R   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   add_visible_links$  s:    				!

c         C   s:   |  j  | ƒ |  j | |  j j ƒ t j |  | | ƒ d S(   s•   Write one document file.

        This method is overwritten in order to fix fragment identifiers
        and to add visible external links.
        N(   R‡   R©   R>   t   epub_show_urlsR	   t	   write_doc(   R<   t   docnameRZ   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyR«   m  s    c      	   C   s*  x#| D]\ } } x| D]\ } \ } } } xi t  | ƒ D][ \ } \ }	 }
 |  j j |
 ƒ } | r< |	 |  j | j d ƒ | j d ƒ ƒ f | | <q< q< Wx€ | D]x \ } } xi t  | ƒ D][ \ } \ }	 }
 |  j j |
 ƒ } | r» |	 |  j | j d ƒ | j d ƒ ƒ f | | <q» q» Wq¢ Wq Wq Wd S(   s'   Fix href attributes for genindex pages.i   i   N(   R}   Ry   Rz   Rt   R{   (   R<   R   t   keyt   columnst	   entrynamet   linkst   subitemst   key_R„   t   ismainR¨   Rƒ   t   subentrynamet   subentrylinks(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   fix_genindexx  s    2c         C   s   t  j | ƒ d } | t k S(   s=   Does the filename extension indicate a vector graphic format?iÿÿÿÿ(   R   t   splitextt   VECTOR_GRAPHICS_EXTENSIONS(   R<   t   filenamet   ext(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   is_vector_graphics‹  s    c   	      C   sJ  t  t j |  j |  j ƒ ƒ x't |  j d d t |  j ƒ |  j j	 ƒ D]û} |  j | } y" t
 j t j |  j | ƒ ƒ } WnÄ t k
 rB|  j | ƒ sÃ t j t d ƒ t j |  j | ƒ ƒ n  y5 t t j |  j | ƒ t j |  j |  j | ƒ ƒ WqG t t f k
 r;} t j t d ƒ t j |  j | ƒ | ƒ qG XqG n X|  j j rp| j d	 k rp| j ƒ  } qpn  |  j j d k rØ| j \ } } |  j j } | | k rØ| | | } | j | | f t
 j ƒ } qØn  y& | j t j |  j |  j | ƒ ƒ WqG t t f k
 rA} t j t d ƒ t j |  j | ƒ | ƒ qG XqG Wd S(
   s²   Copy images using the PIL.
        The method tries to read and write the files with the PIL,
        converting the format and resizing the image if necessary/possible.
        s   copying images... t   browns-   cannot read image file %r: copying it insteads   cannot copy image file %r: %st   Pi    s   cannot write image file %r: %sN(   R½   (   R   R   t   joint   outdirt   imagedirR   t   imagesR—   t   appt	   verbosityR   t   opent   srcdirt   IOErrorR»   t   loggert   warningR
   R   t   OSErrorR>   t   epub_fix_imagest   modet   convertt   epub_max_image_widtht   sizet   resizet   BICUBICt   save(	   R<   t   srct   destt   imgt   errt   widtht   heightt   nwt   nh(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   copy_image_files_pil‘  s>    " !&c         C   sw   |  j  rs |  j j s! |  j j r] t sP t j t d ƒ ƒ t t	 |  ƒ j
 ƒ  qp |  j ƒ  qs t t	 |  ƒ j
 ƒ  n  d S(   s{   Copy image files to destination directory.
        This overwritten method can use the PIL to convert image files.
        s#   PIL not found - copying image filesN(   RÁ   R>   RÊ   RÍ   R   RÇ   RÈ   R
   t   superR2   t   copy_image_filesRÚ   (   R<   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyRÜ   ¸  s    	c         C   s   d  S(   N(    (   R<   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   copy_download_filesÇ  s    s	   page.htmlc         C   si   | j  d ƒ r< d | k r< |  j s( d S|  j | d ƒ n  |  j | d <t j |  | | | | | ƒ d S(   s…   Create a rendered page.

        This method is overwritten for genindex pages in order to fix href link
        attributes.
        t   genindext   genindexentriesNt   doctype(   RQ   R4   R¶   Rà   R	   t   handle_page(   R<   t   pagenamet   addctxt   templatenamet   outfilenamet	   event_arg(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyRá   Ë  s    	c         C   sB   t  j t d ƒ | ƒ t t j |  j d ƒ t j | | ƒ ƒ d S(   s!   Write the metainfo file mimetype.s   writing %s file...t   mimetypeN(   RÇ   t   infoR
   R   R   R¾   t   template_dir(   R<   R¿   t   outname(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   build_mimetypeÛ  s    c         C   s[   t  j t d ƒ | ƒ t j | | ƒ } t t j | ƒ ƒ t t j |  j d ƒ | ƒ d S(   s/   Write the metainfo file META-INF/container.xml.s   writing %s file...s   container.xmlN(	   RÇ   Rè   R
   R   R¾   R   Re   R   Ré   (   R<   R¿   Rê   R¹   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   build_containerâ  s    c         C   s	  i  } |  j  |  j j ƒ | d <|  j  |  j j ƒ | d <|  j  |  j j ƒ | d <|  j  |  j j ƒ | d <|  j  |  j j ƒ | d <|  j  |  j j ƒ | d <|  j  |  j j ƒ | d <|  j  |  j j	 ƒ | d <|  j  t
 d	 ƒ ƒ | d
 <g  | d <g  | d <g  | d <| S(   sa   Create a dictionary with all metadata for the content.opf
        file properly escaped.
        R"   t   authort   uidt   langt	   publishert	   copyrightt   schemeR   s   %Y-%m-%dt   datet   manifest_itemst   spinest   guides(   RL   R>   t
   epub_titlet   epub_authort   epub_uidt   epub_languaget   epub_publishert   epub_copyrightt   epub_schemet   epub_identifierR   (   R<   t   metadata(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   content_metadataê  s    


c         C   s¹  t  j t d ƒ | ƒ |  j ƒ  } | j t j ƒ sD | t j 7} n  t | ƒ } g  |  _ d d d d d d d d	 d
 |  j	 j
 d g
 |  j	 j |  _ |  j s· |  j j d |  j ƒ n  x8t j | ƒ D]'\ } } } | j ƒ  xt | ƒ D]ý } t j | | ƒ | }	 |	 |  j k rqí n  t j |	 ƒ d }
 |
 |  j k rw|
 d" k rí t  j t d ƒ |	 d d d d ƒqí qí n  |	 j t j d ƒ }	 t |  j |	 ƒ |  j |  j |	 ƒ ƒ |  j |  j |
 ƒ ƒ } | d j | ƒ |  j j |	 ƒ qí WqÇ Wt ƒ  } x‡ |  j D]| } d | d k r!qn  | d |  j k r:qn  t |  j |  j | d ƒ ƒ t ƒ } | d j | ƒ | j  | d ƒ qWxf |  j! D][ } t |  j |  j | d |  j ƒ ƒ t ƒ } | d j | ƒ | j  | d |  j ƒ qW|  j rGt |  j |  j d |  j ƒ ƒ t ƒ } | d j | ƒ | j  d |  j ƒ n  xd |  j D]Y } | | k rQ| j |  j ƒ rQt |  j |  j | ƒ ƒ t" ƒ } | d j | ƒ qQqQWd! } |  j	 j$ r/|  j	 j$ \ } } | j t j d ƒ } |  j |  j | ƒ ƒ | d <| r/t |  j |  j |  j% ƒ ƒ t ƒ } | d j& d | ƒ |  j% |  j k rÓt j |  j% ƒ d }
 |  j j |  j% ƒ t |  j |  j% ƒ |  j |  j |  j% ƒ ƒ |  j |  j |
 ƒ ƒ } | d j | ƒ n  i |  j | ƒ d 6|  j	 j' d 6} |  j( t j |  j% ƒ d | | ƒ | j  |  j% ƒ q/n  t } t } |  j	 j) rx· |  j	 j) D]¦ \ } } } | j* d ƒ d } | |  j k r˜|  j j | ƒ n  | d k r­t" } n  | d k rÂt" } n  | d j t+ |  j | ƒ |  j | ƒ |  j | ƒ ƒ ƒ qTWn  | r@| r@| d j t+ d |  j, d |  j |  j% ƒ ƒ ƒ n  | rŠ|  j rŠ| d j t+ d |  j, d |  j |  j d d ƒ ƒ ƒ n  t- t j |  j. d  ƒ t j | | ƒ | ƒ d! S(#   sƒ   Write the metainfo file content.opf It contains bibliographic data,
        a file list and the spine (the reading order).
        s   writing %s file...s
   .buildinfoRç   s   content.opfs   toc.ncxs   META-INF/container.xmls	   Thumbs.dbs   ehthumbs.dbs	   .DS_Stores	   nav.xhtmls   .epubRÞ   iÿÿÿÿs   .jss   .xmls!   unknown mimetype for %s, ignoringR!   R5   t   subtypet   unknown_project_filesR_   Rô   t   #R(   Rõ   i    R   t   imageR"   R   Rö   s   content.opf_tN(   s   .jss   .xml(/   RÇ   Rè   R
   R   t   endswitht   ost   sepR—   t   filesR>   t   epub_basenamet   epub_exclude_filest   ignored_filesR4   RV   R7   t   walkt   sortt   sortedR   R¾   R·   t   media_typesRÈ   R,   R   RL   RH   t   setRd   R   Rc   t   addt   domain_indicesRb   t   Nonet
   epub_covert   coverpage_nameRj   t   projectRá   t
   epub_guidet   splitR    t   guide_titlesR   Ré   (   R<   R¿   Rê   Rÿ   t   olent   roott   dirsR  R›   R¹   Rº   Rh   t
   spinefilest   refnodet   spineRè   RG   t	   html_tmplR  t   ctxt   auto_add_covert   auto_add_tocR!   R#   R"   Ro   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   build_contentþ  sÀ    				
	%,	(!$#		

!c         C   sX   | r |  j  d 7_  n  |  j d 7_ t |  j d |  j ƒ |  j  | d | d g  ƒ S(   s;   Create a new entry in the toc from the node at given level.i   s
   navPoint%dR'   R(   (   R&   R9   R$   RL   (   R<   R‚   RN   t   incr(    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   new_navpointp  s
    c         C   s  g  } | j  t d d d d g  ƒ ƒ d } d
 } xÂ| D]º} | d sN q8 n  | d j d ƒ d } | |  j k rz q8 n  | d |  j j k r– q8 n  | d | k ræ |  j | | ƒ } | j ƒ  | d j	 j  | ƒ | j  | ƒ n| d | d	 k rr| d	 7} | r<|  j j
 r<| d j	 j  |  j | | t ƒ ƒ n  |  j | | ƒ } | d j	 j  | ƒ | j  | ƒ nz | d | k  réx$ | d t | ƒ k  r¨| j ƒ  q…W| d } |  j | | ƒ } | d j	 j  | ƒ | j  | ƒ n ‚  | } q8 W| d j	 S(   s³   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.
        t   dummyR3   i    R'   R(   R  RN   iÿÿÿÿi   N(   RV   R$   R  R  R  R>   t   epub_tocdepthR&  t   popR)   t   epub_tocdupRb   R—   (   R<   R   t   navstackRN   t   lastnodeR‚   Ro   R%   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   build_navpointsz  sD    


&

c         C   sG   i  } |  j  j | d <|  j |  j  j ƒ | d <| | d <| | d <| S(   s]   Create a dictionary with all metadata for the toc.ncx file
        properly escaped.
        Rî   R"   RN   t	   navpoints(   R>   Rù   RL   R÷   (   R<   RN   R.  Rÿ   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   toc_metadata§  s    

c         C   sò   t  j t d ƒ | ƒ |  j j d k rq |  j j |  j j |  d t d t ƒ} |  j	 | g  ƒ } |  j
 | ƒ n	 |  j } |  j | ƒ } t d „  |  j Dƒ ƒ } t | |  j j ƒ } t t j |  j d ƒ t j | | ƒ |  j | | ƒ ƒ d S(   s    Write the metainfo file toc.ncx.s   writing %s file...t   defaultR]   R^   c         s   s   |  ] } | d  Vq d S(   RN   N(    (   t   .0Rh   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pys	   <genexpr>Â  s    s	   toc.ncx_tN(   RÇ   Rè   R
   R>   t   epub_tocscopeRE   R`   Ra   Rb   RY   Rf   Rd   R-  t   maxt   minR(  R   R   R¾   Ré   R/  (   R<   R¿   Rê   RZ   Rd   R.  RN   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt	   build_toc³  s    		c      	   C   sÒ   t  j t d ƒ | ƒ t j | | ƒ } t | d t ƒ ’ } | j t j | d ƒ d t ƒ x6 d d d g D]% } | j t j | | ƒ | t ƒ ql Wx0 |  j	 D]% } | j t j | | ƒ | t ƒ qŸ WWd QXd S(   s~   Write the epub file.

        It is a zip file with the mimetype file stored uncompressed as the first
        entry.
        s   writing %s file...t   wRç   u   META-INF/container.xmlu   content.opfu   toc.ncxN(
   RÇ   Rè   R
   R   R¾   R   R   t   writeR   R  (   R<   R¿   Rê   t   epub_filenameR5   R¹   (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt
   build_epubÈ  s    #N(;   t   __name__t
   __module__t   __doc__Rb   t
   copysourcet   supported_image_typest   supported_remote_imagest   add_permalinkst   allow_sharp_as_current_pathRc   t   embeddedt   download_supportt   html_scaled_image_linkt   searcht   default_html5_translatort   COVERPAGE_NAMER  t   TOCTREE_TEMPLATERU   t   LINK_TARGET_TEMPLATERŸ   t   CSS_LINK_TARGET_CLASSR    t   GUIDE_TITLESR  t   MEDIA_TYPESR  t	   REFURI_RERy   Ré   Rà   R6   R@   RC   RH   RL   RY   Ri   Rf   Rt   R‡   R©   R«   R¶   R»   RÚ   RÜ   RÝ   R  Rá   Rë   Rì   R   R$  R&  R-  R/  R5  R9  (    (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyR2   p   sb   						
						I				'						r
	-		(   s   .svg(@   R<  R  t   ret   collectionsR    R   t   zipfileR   R   R   t   docutilsR   t   docutils.utilsR   t   sphinxR   t   sphinx.builders.htmlR   R	   t   sphinx.localeR
   t   sphinx.utilR   R   t   sphinx.util.fileutilR   t   sphinx.util.i18nR   t   sphinx.util.osutilR   R   t   PILR   t   ImportErrorR  Rb   t   typingR   R   R   R   t   sphinx.applicationR   t	   getLoggerR:  RÇ   RG  RH  RI  R¡   R˜   RJ  RK  RL  R¸   t   compileRM  R   R   R    R$   R1   RW   R2   (    (    (    s9   lib/python2.7/site-packages/sphinx/builders/_epub_base.pyt   <module>
   sn   "	

	