B
    \-                 @   s  d Z ddlmZ ddlmZ ddlmZmZ ddlmZm	Z	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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m Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+ ddl,m-Z- e.e/Z0ddd Z1G dd de2Z3G dd de2Z4G dd de-Z5G dd deZ6e Z7e8e7e9e7 Z:edZ;e;dk	re<e;Z7e
dZ:G d d! d!e	Z=e= Z>d"d# Z?G d$d% d%e6Z@d&d' ZAdS )(z
    sphinx.builders.gettext
    ~~~~~~~~~~~~~~~~~~~~~~~

    The MessageCatalogBuilder class.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )unicode_literals)open)defaultdictOrderedDict)datetimetzinfo	timedelta)pathwalkgetenv)time)uuid4)	iteritemsStringIO)Builder)pairindextypes)
ThemeError)__)split_index_msgloggingstatus_iterator)bold)find_catalog)extract_messagestraverse_translatable_index)relpath	ensuredir
canon_path)Tagsa!  
# SOME DESCRIPTIVE TITLE.
# Copyright (C) %(copyright)s
# This file is distributed under the same license as the %(project)s package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: %(project)s %(version)s\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: %(ctime)s\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

   Nc               @   s    e Zd ZdZdd Zdd ZdS )Catalogz!Catalog of translatable messages.c             C   s   g | _ t | _d S )N)messagesr   metadata)self r$   6lib/python3.7/site-packages/sphinx/builders/gettext.py__init__E   s    zCatalog.__init__c             C   sN   t |dsd S || jkr.| j| g | j|< | j| |j|j|jf d S )Nuid)hasattrr"   r!   appendsourceliner'   )r#   msgoriginr$   r$   r%   addL   s    


zCatalog.addN)__name__
__module____qualname____doc__r&   r.   r$   r$   r$   r%   r    B   s   r    c               @   s   e Zd ZdZdd ZdS )	MsgOriginz3
    Origin holder for Catalog message origin.
    c             C   s   || _ || _t j| _d S )N)r*   r+   r   hexr'   )r#   r*   r+   r$   r$   r%   r&   ]   s    zMsgOrigin.__init__N)r/   r0   r1   r2   r&   r$   r$   r$   r%   r3   X   s   r3   c               @   s   e Zd ZdZdd ZdS )I18nTagszDummy tags module for I18nBuilder.

    To translate all text inside of only nodes, this class
    always returns True value even if no tags are defined.
    c             C   s   dS )NTr$   )r#   Z	conditionr$   r$   r%   eval_conditionj   s    zI18nTags.eval_conditionN)r/   r0   r1   r2   r6   r$   r$   r$   r%   r5   d   s   r5   c               @   sR   e Zd ZdZdZdZdZdZdd Zddd	Z	d
d Z
dd Zdd Zdd ZdS )I18nBuilderz
    General i18n builder.
    Zi18ntextNFc             C   s6   t |  | j| j| jjj t | _t	t
| _d S )N)r   initenvZset_versioning_methodversioning_methodconfiggettext_uuidr5   Ztagsr   r    catalogs)r#   r$   r$   r%   r9   y   s
    

zI18nBuilder.initc             C   s   dS )N r$   )r#   docnametypr$   r$   r%   get_target_uri   s    zI18nBuilder.get_target_uric             C   s   | j jS )N)r:   Z
found_docs)r#   r$   r$   r%   get_outdated_docs   s    zI18nBuilder.get_outdated_docsc             C   s   d S )Nr$   )r#   docnamesr$   r$   r%   prepare_writing   s    zI18nBuilder.prepare_writingc             C   s   d S )Nr$   )r#   r>   messager$   r$   r%   compile_catalogs   s    zI18nBuilder.compile_catalogsc             C   s   | j t|| jj }x t|D ]\}}||| qW d| jjjkrxbt|D ]V\}}xL|D ]D\}}}}	}
x4t	||D ]&}|dkr|t
 krqv||| qvW q\W qNW d S )NindexZpair)r>   r   r<   gettext_compactr   r.   r:   gettext_additional_targetsr   r   r   values)r#   r@   ZdoctreecatalogZnoder,   entriesrA   tidmainZkey_mr$   r$   r%   	write_doc   s    zI18nBuilder.write_doc)N)r/   r0   r1   r2   namer;   Zversioning_compareZuse_message_catalogr9   rB   rC   rE   rG   rQ   r$   r$   r$   r%   r7   o   s   
r7   SOURCE_DATE_EPOCHc                   s,   e Zd Z fddZdd Zdd Z  ZS )LocalTimeZonec                s   t t| j|| t| _d S )N)superrT   r&   tzdelta)r#   argskw)	__class__r$   r%   r&      s    zLocalTimeZone.__init__c             C   s   | j S )N)rV   )r#   dtr$   r$   r%   	utcoffset   s    zLocalTimeZone.utcoffsetc             C   s   t dS )Nr   )r   )r#   rZ   r$   r$   r%   dst   s    zLocalTimeZone.dst)r/   r0   r1   r&   r[   r\   __classcell__r$   r$   )rY   r%   rT      s   rT   c          	   C   s   t | sdS yzt| dddb}| }|d}|d}|d}|d}|d | |d | kp~||d  ||d  kS Q R X W n tk
r   Y nX dS )NTrzutf-8)encodingz"POT-Creation-Date:z"PO-Revision-Date:)r	   existsr   readrH   
ValueError)filepathZnew_contentZoldpotZold_contentZold_header_indexZnew_header_indexZold_body_indexZnew_body_indexr$   r$   r%   should_write   s    




"rd   c               @   sF   e Zd ZdZdZedZdd Zdd Zdd	 Z	dddZ
dd Zd
S )MessageCatalogBuilderz=
    Builds gettext-style message catalogs (.pot files).
    gettextz'The message catalogs are in %(outdir)s.c             C   s"   t |  |   | j|  d S )N)r7   r9   Zcreate_template_bridge	templates)r#   r$   r$   r%   r9      s    
zMessageCatalogBuilder.initc       	      C   sv   t  }xj| jjD ]^}t| jj|}xHt|D ]<\}}}x0|D ](}|dr>t	t||}|
| q>W q.W qW |S )Nz.html)setr<   Ztemplates_pathr	   joinappZsrcdirr
   endswithr   r.   )	r#   Ztemplate_filesZtemplate_pathZtmpl_abs_pathdirpathdirsfilesfnfilenamer$   r$   r%   _collect_templates   s    

z(MessageCatalogBuilder._collect_templatesc             C   s  t |  }|  tjttd| j dd ttdt| | j	j
j}xt|tddt|| jjD ]}yZt|ddd	}| }W d Q R X x2||D ]&\}}}t||}	| jd
 ||	 qW W ql tk
r }
 ztd||
f W d d }
~
X Y qlX qlW d S )Nzbuilding [%s]: r   )Znonlztargets for %d template fileszreading templates... Zpurpler^   zutf-8)r_   Zsphinxz%s: %r)listrq   sortloggerinfor   r   rR   lenrg   Zenvironmentextract_translationsr   rj   	verbosityr   ra   r3   r>   r.   	Exceptionr   )r#   rn   rw   templatefcontextr+   methr,   r-   excr$   r$   r%   _extract_from_template   s    

z,MessageCatalogBuilder._extract_from_templateNupdatec             C   s   |    t| ||| d S )N)r   r7   build)r#   rD   Zsummarymethodr$   r$   r%   r     s    zMessageCatalogBuilder.buildc       
   
      s~  t   t jj jj jjtt	t
dd}xBtt jtddt j jjdd D ]\}}tt jt| t j|d }t }|t|  x|jD ]}|j| } jjr|dd	 fd
d|D    jjr|dddd |D   |dddddd}|d|  qW |  }t!||rbt"|ddd}	|	| W d Q R X qbW d S )Nz%Y-%m-%d %H:%M%z)version	copyrightprojectZctimezwriting message catalogs... Z	darkgreenc             S   s   | d S )Nr   r$   )Ztextdomain__r$   r$   r%   <lambda>  s    z.MessageCatalogBuilder.finish.<locals>.<lambda>z.potz#: %s
z
#: c             3   s,   | ]$\}}}d t t| j|f V  qdS )z%s:%sN)r   r   outdir).0r*   r+   _)r#   r$   r%   	<genexpr>%  s   z/MessageCatalogBuilder.finish.<locals>.<genexpr>z# %s
z
# c             s   s   | ]\}}}|V  qd S )Nr$   )r   r   r'   r$   r$   r%   r   *  s    \z\\"z\"
z\n"
"zmsgid "%s"
msgstr ""

wzutf-8)r_   )#r7   finishdictr<   r   r   r   r   fromtimestamp	timestampltzZstrftimer   r   r>   r   rv   rj   rx   r   r	   ri   r   dirnamer   writePOHEADERr!   r"   gettext_locationr=   replacegetvaluerd   r   )
r#   data
textdomainrL   ZpofnoutputrF   Z	positionsZcontentZpofiler$   )r#   r%   r   	  sB    







zMessageCatalogBuilder.finish)Nr   )r/   r0   r1   r2   rR   r   Zepilogr9   rq   r   r   r   r$   r$   r$   r%   re      s   
re   c             C   s\   |  t | ddd | ddd | ddd | ddd | d	g d d
dddS )NrI   Trf   r   r=   FZgettext_auto_buildr:   rJ   Zbuiltin)r   Zparallel_read_safeZparallel_write_safe)Zadd_builderre   Zadd_config_value)rj   r$   r$   r%   setup9  s    
r   )Br2   Z
__future__r   codecsr   collectionsr   r   r   r   r   osr	   r
   r   r   Zuuidr   Zsixr   r   Zsphinx.buildersr   Zsphinx.domains.pythonr   Zsphinx.errorsr   Zsphinx.localer   Zsphinx.utilr   r   r   Zsphinx.util.consoler   Zsphinx.util.i18nr   Zsphinx.util.nodesr   r   Zsphinx.util.osutilr   r   r   Zsphinx.util.tagsr   Z	getLoggerr/   rt   r   objectr    r3   r5   r7   r   r   ZutcfromtimestamprV   Zsource_date_epochfloatrT   r   rd   re   r   r$   r$   r$   r%   <module>
   sH   

7
b