ó
öÀ„\c           @   sq  d  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	 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 e r)d d l m Z m Z m Z m Z d d l m Z d d l m Z d d l  m! Z! n  e j" e# ƒ Z$ d e f d „  ƒ  YZ% d e f d „  ƒ  YZ& d „  Z' d S(   sô   
    sphinx.environment.collectors.asset
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    The image collector for sphinx.environment.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   glob(   t   path(   t   nodes(   t   relative_path(   t	   iteritemst
   itervalues(   t   addnodes(   t   EnvironmentCollector(   t   __(   t   logging(   t   get_image_filename_for_languaget   search_image_for_language(   t   guess_mimetype(   t   Dictt   Listt   Sett   Tuple(   t   Sphinx(   t   BuildEnvironmentt   ImageCollectorc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s-   Image files collector for sphinx.environment.c         C   s   | j  j | ƒ d  S(   N(   t   imagest	   purge_doc(   t   selft   appt   envt   docname(    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyt	   clear_doc(   s    c         C   s   | j  j | | j  ƒ d  S(   N(   R   t   merge_other(   R   R   R   t   docnamest   other(    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyR   ,   s    c      
   C   s,  | j  j } x| j t j ƒ D]} i  } | | d <| d } | j d ƒ r^ | | d <q n% | j d ƒ d k rƒ | | d <q n  | j  j | | ƒ \ } } | j j	 rò t
 | | j  ƒ }	 |	 | k rò |	 } t t j | j d ƒ |	 ƒ } qò n  | | d <| j t j d ƒ rƒ| j j	 rgt | | j  ƒ }
 | j  j |
 | ƒ \ } } |  j | j  | | | ƒ n  |  j | j  | | | ƒ n
 | | d <x” t | ƒ D]† } | j  j | j | ƒ t j t j | j | ƒ t j ƒ s
t j t d	 ƒ | d
 | d d d d ƒqšn  | j  j j | | ƒ qšWq Wd S(   s   Process and rewrite image URIs.t
   candidatest   uris   data:t   ?s   ://iÿÿÿÿt   dummyt   *s   image file not readable: %st   locationt   typet   imaget   subtypet   not_readableN(   R   R   t   traverseR   R%   t
   startswitht   findt
   relfn2patht   configt   languageR   R   R   t   joint   srcdirt   endswitht   ost   extsepR
   t   collect_candidatesR   t   dependenciest   addt   accesst   R_OKt   loggert   warningR   R   t   add_file(   R   R   t   doctreeR   t   nodeR   t   imgurit   rel_imgpatht   full_imgpatht   i18n_full_imgpatht   i18n_imgurit   _t   full_i18n_imgpatht   imgpath(    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyt   process_doc0   sB    





$c      	   C   sù   i  } xµ t  | ƒ D]§ } t t j | j d ƒ | ƒ } y8 t | ƒ } | | k rn | j | g  ƒ j | ƒ n  Wq t t	 f k
 r¹ }	 t
 j t d ƒ | |	 f d | d d d d ƒq Xq Wx4 t | ƒ D]& \ }
 } t | d t ƒd	 | |
 <qË Wd  S(
   NR!   s   image file %s not readable: %sR#   R$   R%   R&   R'   t   keyi    (   R    R   R   R.   R/   R   t
   setdefaultt   appendt   OSErrort   IOErrorR8   R9   R   R   t   sortedt   len(   R   R   RD   R   R<   t   globbedt   filenamet   new_imgpatht   mimetypet   errRF   t   files(    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyR3   b   s    	 (   t   __name__t
   __module__t   __doc__R   R   RE   R3   (    (    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyR   %   s
   			2t   DownloadFileCollectorc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s0   Download files collector for sphinx.environment.c         C   s   | j  j | ƒ d  S(   N(   t   dlfilesR   (   R   R   R   R   (    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyR   v   s    c         C   s   | j  j | | j  ƒ d  S(   N(   RW   R   (   R   R   R   R   R   (    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyR   z   s    c      	   C   sè   xá | j  t j ƒ D]Í } | d } d | k r< | | d <q | j j | | j j ƒ \ } } | j j | j j j | ƒ t j	 | t j
 ƒ s¾ t j t d ƒ | d | d d d d	 ƒq n  | j j j | j j | ƒ | d
 <q Wd S(   s!   Process downloadable file paths. t	   reftargets   ://t   refuris   download file not readable: %sR#   R$   t   downloadR&   R'   RN   N(   R(   R   t   download_referenceR   R+   R   R4   R5   R1   R6   R7   R8   R9   R   RW   R:   (   R   R   R;   R<   t
   targetnamet   rel_filenameRN   (    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyRE   ~   s    
!(   RS   RT   RU   R   R   RE   (    (    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyRV   s   s   		c         C   s3   |  j  t ƒ |  j  t ƒ i d d 6t d 6t d 6S(   Nt   builtint   versiont   parallel_read_safet   parallel_write_safe(   t   add_env_collectorR   RV   t   True(   R   (    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyt   setup   s    ((   RU   R1   R    R   t   docutilsR   t   docutils.utilsR   t   sixR   R   t   sphinxR   t   sphinx.environment.collectorsR   t   sphinx.localeR   t   sphinx.utilR	   t   sphinx.util.i18nR
   R   t   sphinx.util.imagesR   t   Falset   typingR   R   R   R   t   sphinx.sphinxR   t   sphinx.environmentR   t	   getLoggerRS   R8   R   RV   Rd   (    (    (    sB   lib/python2.7/site-packages/sphinx/environment/collectors/asset.pyt   <module>
   s*   "N