ó
öÀ„\c           @   s—  d  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	 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 d d l m Z m Z d d l m Z d d l m Z d d l m Z e rGd d l m  Z  m! Z! m" Z" m# Z# d d l$ m% Z% n  e j& e' ƒ Z( e j) d ƒ Z* d Z+ d „  Z, d e f d „  ƒ  YZ- d „  Z. d S(   sá   
    sphinx.builders.qthelp
    ~~~~~~~~~~~~~~~~~~~~~~

    Build input files for the Qt collection generator.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   path(   t   nodes(   t	   text_type(   t   addnodes(   t   package_dir(   t   StandaloneHTMLBuilder(   t   string_classes(   t   IndexEntries(   t   __(   t   force_decodet   logging(   t   make_filename(   t
   htmlescape(   t   SphinxRenderer(   t   Anyt   Dictt   Listt   Tuple(   t   SphinxsB   (?P<title>.+) (\((class in )?(?P<id>[\w\.]+)( (?P<descr>\w+))?\))$s*   <section title="%(title)s" ref="%(ref)s"/>c         K   s+   t  j j t d d |  ƒ } t j | | ƒ S(   Nt	   templatest   qthelp(   t   osR    t   joinR   R   t   render_from_file(   t   filenamet   kwargst   pathname(    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt   render_file0   s    t   QtHelpBuilderc           B   s¤   e  Z d  Z d Z e d ƒ Z e Z d d d d g Z e Z	 e
 Z e Z e Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   sN   
    Builder that also outputs Qt help project, contents and index files.
    R   sÝ   You can now run "qcollectiongenerator" with the .qhcp project file in %(outdir)s, like this:
$ qcollectiongenerator %(outdir)s/%(project)s.qhcp
To view the help file:
$ assistant -collectionFile %(outdir)s/%(project)s.qhcs   image/svg+xmls	   image/pngs	   image/gifs
   image/jpegc         C   s#   t  j |  ƒ d |  _ d |  _ d  S(   Ns   .html(   R   t   initt
   out_suffixt   link_suffix(   t   self(    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyR   Q   s    	c         C   s   |  j  j |  j  j f S(   N(   t   configt   qthelp_themet   qthelp_theme_options(   R    (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt   get_theme_configY   s    c         C   s   |  j  |  j |  j j ƒ d  S(   N(   t	   build_qhpt   outdirR!   t   qthelp_basename(   R    (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt   handle_finish]   s    c         C   so  t  j t d ƒ ƒ |  j j |  j j |  d t ƒ} d „  } g  } x- | j | ƒ D] } | j	 |  j
 | ƒ ƒ qS WxM |  j D]B \ } } }	 }
 t i | j d 6d | d 6} | j d% | ƒ q} Wg  } xC | D]; } t | t ƒ sþ | j t | d  ƒ ƒ qÐ | j | ƒ qÐ Wd	 j | ƒ } g  } t |  j ƒ j |  d
 t ƒ} xP | D]H \ } } x9 | D]1 \ } \ } } } | j	 |  j | | | ƒ ƒ q\WqIWd	 j | ƒ } |  j j r¿|  j j } n d | |  j j f } t j d d | ƒ } t j d d | ƒ j d ƒ } | j ƒ  } t j t j | | d ƒ d d ƒ w } t  d d | d |  j j! d |  j j d |  j j" d | d |  j j d | d | d |  j# | ƒ ƒ	} | j$ | ƒ Wd  QXd t% j | d |  j& |  j j ƒ ƒ } d t% j | d d ƒ } t  j t d ƒ ƒ t j t j | | d  ƒ d d ƒ > } t  d! d | d |  j j' d" | d# | ƒ} | j$ | ƒ Wd  QXd  S(&   Ns   writing project file...t   prune_toctreesc         S   s   t  |  t j ƒ o d |  k S(   Nt   toctree(   t
   isinstanceR   t   compact_paragraph(   t   node(    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt	   istoctreei   s    t   titles   %s.htmlt   reft    i   u   
t   group_entriess   org.sphinx.%s.%ss   [^a-zA-Z0-9.\-]t    s   \.+t   .s   .qhpt   ws   utf-8s   project.qhpt   outnamet   versiont   projectt	   namespacet
   master_doct   sectionst   keywordst   filess	   qthelp://t   docs
   index.htmls"   writing collection project file...s   .qhcps   project.qhcpt   homepaget	   startpages       s                   ((   t   loggert   infoR   t   envt   get_and_resolve_doctreeR!   R:   t   Falset   traverset   extendt	   write_toct   domain_indicest   section_templatet	   localnamet   appendR+   R   R	   t   NoneR   R   t   create_indext   build_keywordst   qthelp_namespaceR7   t   ret   subt   stript   lowert   codecst   openR    R   t
   html_titleR8   t   get_project_filest   writet	   posixpatht   get_target_urit   html_short_title(   R    R&   R6   t   tocdocR.   R;   R-   t	   indexnamet   indexclst   contentt   collapset   itemt   new_sectionst   sectionR<   t   indext   keyt   groupR/   t   refst   subitemst   key_t   nspacet   ft   bodyR?   R@   (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyR%   a   s\    		$(	(c         C   sŽ   t  | t j ƒ s t St | j ƒ d k r/ t St  | j d t j ƒ sL t St  | j d d t j ƒ sm t St  | j d t j	 ƒ sŠ t St
 S(   Ni   i    i   (   R+   R   t	   list_itemRE   t   lent   childrenR   R,   t	   referencet   bullet_listt   True(   R    R-   (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt	   isdocnode¨   s    i   c   	      C   s  g  } |  j  | ƒ rÈ | j d d } | d } t | j ƒ  ƒ j d d ƒ } d i | d 6| d 6} | j d | | ƒ x2 | j d
 D]# } | j |  j | | d
 ƒ ƒ q‰ W| j d | d ƒ n9t | t	 j
 ƒ rx$| D] } | j |  j | | ƒ ƒ qá Wnú t | t	 j ƒ rƒ| d } t | j ƒ  ƒ j d d ƒ } t i | d 6| d 6} d | | } | j | j d d ƒ ƒ n~ t | t	 j ƒ rÂxi | D] } | j |  j | | ƒ ƒ qœWn? t | t j ƒ rx* | D] } | j |  j | | ƒ ƒ qÛWn  | S(   Ni    t   refurit   "s   &quot;s)   <section title="%(title)s" ref="%(ref)s">R/   R0   R1   i   i   s
   </section>u    t   asciit   xmlcharrefreplaces       s       u       (   Rt   Rp   R   t   astextt   replaceRL   RG   RH   R+   R   Rn   Rq   RJ   t   encodeRr   R   R,   (	   R    R-   t   indentlevelt   partst   refnodet   linkR/   Rb   t   subnode(    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyRH   ¶   s6    
! 
  c   
      C   sß   t  j | ƒ } | ri | j ƒ  } | d } | j d ƒ } | j d ƒ rV | d  } n  d | | f } n d  } t | d t ƒ} t | d d t ƒ} | r· d d
 | | | f }	 n d d | | f }	 |	 j d d ƒ |	 S(   NR/   t   ids   ()iþÿÿÿs   %s.%st   quotei   R1   i   s%   <keyword name="%s" id="%s" ref="%s"/>s   <keyword name="%s" ref="%s"/>Rw   Rx   s               s               (	   t
   _idpatternt   matcht	   groupdictt   gett   endswithRM   R   Rs   R{   (
   R    t   nameR0   t   matchobjR…   t	   shortnameR   t   nameattrt   refattrRb   (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt   keyword_itemÖ   s     
c         C   sÅ   g  } t  | ƒ d k r8 | j |  j | | d ƒ ƒ nK t  | ƒ d k rƒ x6 t | ƒ D]% \ } } | j |  j | | ƒ ƒ qW Wn  | rÁ x5 | D]* } | j |  j | d | d g  ƒ ƒ q Wn  | S(   Ni   i    (   Ro   RL   R   t	   enumerateRG   RO   (   R    R/   Rh   Ri   R<   t   iR0   t   subitem(    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyRO   í   s      +c         C   sù   | j  t j ƒ s" | t j 7} n  t | ƒ } g  } t j | d ƒ } t j | |  j ƒ } x— t j | ƒ D]† \ } } } | j | | f ƒ }	 x_ t	 | ƒ D]Q }
 |	 r¸ |
 j  d ƒ sÇ |
 j  d ƒ rœ t j | |
 ƒ | } | j
 | ƒ qœ qœ Wqk W| S(   Nt   _statics   .jss   .html(   R‡   R   t   sepRo   R    R   t   imagedirt   walkt
   startswitht   sortedRL   (   R    R&   t   olent   project_filest	   staticdirt	   imagesdirt   roott   dirsR=   t   resourcedirt   fnR   (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyRX     s    %(   t   __name__t
   __module__t   __doc__Rˆ   R   t   epilogRE   t
   copysourcet   supported_image_typest   add_permalinksRs   t   embeddedt   download_supportt   searchR   R$   R(   R%   Rt   RH   R   RO   RX   (    (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyR   6   s&   						G	 		c         C   s…   |  j  d ƒ |  j t ƒ |  j d d „  d  ƒ |  j d d  d t ƒ |  j d d d ƒ |  j d i  d ƒ i d	 d
 6t d 6t d 6S(   Ns   sphinx.builders.htmlR'   c         S   s   t  |  j ƒ S(   N(   R   R8   (   R    (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt   <lambda>  s    RP   t   htmlR"   t   nonavR#   t   builtinR7   t   parallel_read_safet   parallel_write_safe(   t   setup_extensiont   add_builderR   t   add_config_valueRM   R   Rs   (   t   app(    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt   setup  s    (/   R¡   RU   R   RZ   RQ   R    t   docutilsR   t   sixR   t   sphinxR   R   t   sphinx.builders.htmlR   t   sphinx.configR   t(   sphinx.environment.adapters.indexentriesR   t   sphinx.localeR   t   sphinx.utilR	   R
   t   sphinx.util.osutilR   t   sphinx.util.pycompatR   t   sphinx.util.templateR   RE   t   typingR   R   R   R   t   sphinx.applicationR   t	   getLoggerRŸ   RA   t   compileRƒ   RJ   R   R   R³   (    (    (    s5   lib/python2.7/site-packages/sphinx/builders/qthelp.pyt   <module>
   s6   "		à