B
    `                 @   s@   d dl Z d dlmZ d dlmZ d dlmZ G dd deZdS )    N)compat)lexer)	parsetreec               @   s(   e Zd Zdd Zdd Zedd ZdS )MessageExtractorc             c   s>   t j| | jd d }x| | D ]
}|V  q,W d S )Nencoding)input_encoding)r   ZLexerreadconfigparseextract_nodesZget_children)selffileobjZtemplate_node	extracted r   X/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/mako/ext/extract.pyprocess_file   s    zMessageExtractor.process_filec             c   sf  g }d}| j d pd}ttd td| j d }x,|D ]"}d }|r`t|tjr`|j	 s`q:t|tj
r|j	 }|r|| |j| q:x.|D ]&}	||	rd}|| |j| qW q:t|tjr|jj}
|j}nt|tjr|jj}
|j}nt|tjr|jj}
|j}nt|tjr0|jj}
ntt|tjrL|j}
|j}nXt|tjrp|jrhd}q:|j}
n4t|tjrd}|jj}
nt|tjr:|jj}
nq:|r|d d |jd	 k rg }d
d |D }t|
tjr|
 |d}
d}t!t"d|
 }
x(| #|
|jd	 |D ]}|V  d}qW |r:g }d}|r:x| $|D ]}|V  qNW q:W d S )NFr   asciiz\s+zcomment-tagsTr      c             S   s   g | ]}|d  qS )r   r   ).0commentr   r   r   
<listcomp>Z   s    z2MessageExtractor.extract_nodes.<locals>.<listcomp>backslashreplace
)%r	   listfilterresplit
isinstancer   TextcontentstripCommenttextextend_split_commentlineno
startswithZDefTagZfunction_declcodenodesZBlockTagZ	body_declZCallTagZPageTagZCallNamespaceTagZ
expressionZControlLineZisendZCodeZ
Expressionr   	text_typeencodeZbyte_bufferbZprocess_pythonr   )r   r)   Ztranslator_commentsZin_translator_commentsr   Zcomment_tagsnodeZchild_nodesvalueZcomment_tagr(   Ztranslator_stringsZused_translator_commentsmessager   r   r   r   r      s    







zMessageExtractor.extract_nodesc                s    fddt | D S )zzReturn the multiline comment at lineno split into a list of
        comment line numbers and the accompanying comment linec                s   g | ]\}} | |fqS r   r   )r   indexline)r&   r   r   r   {   s   z3MessageExtractor._split_comment.<locals>.<listcomp>)	enumerate
splitlines)r&   r   r   )r&   r   r%   v   s    
zMessageExtractor._split_commentN)__name__
__module____qualname__r   r   staticmethodr%   r   r   r   r   r      s   `r   )r   Zmakor   r   r   objectr   r   r   r   r   <module>   s   