a
    e	g3                     @   sJ   d dl mZ d dl mZ d dlZd dlmZ d dlmZ G dd dZdS )    )BytesIO)StringION)lexer)	parsetreec                   @   s,   e Zd ZdZdd Zdd Zedd ZdS )	MessageExtractorTc                 c   s4   t j| | jd d }| | E d H  d S )Nencoding)input_encoding)r   ZLexerreadconfigparseextract_nodesZget_children)selffileobjZtemplate_node r   S/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/mako/ext/extract.pyprocess_file   s    
zMessageExtractor.process_filec                 c   s`  g }d}| j d pd}ttd td| j d }|D ]"}d }|r\t|tjr\|j	 s\q6t|tj
r|j	 }|r|| |j| q6|D ]&}	||	rd}|| |j| qq6t|tjr|jj}
|j}nt|tjr|jj}
|j}nt|tjr|jj}
|j}nt|tjr(|jj}
ntt|tjrD|j}
|j}nXt|tjrh|jr`d}q6|j}
n4t|tjrd}|jj}
nt|tjr6|jj}
nq6|r|d d |jd	 k rg }d
d |D }t|
tr| jr|
 |d}
d}| jrt!d|
 }
nt"d|
 }
| #|
|jd	 |D ]}|V  d}q&|rBg }d}|r6| $|E d H  q6d S )NFr   asciiz\s+zcomment-tagsTr      c                 S   s   g | ]}|d  qS )r   r   ).0commentr   r   r   
<listcomp>[   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Code
Expressionstr	use_bytesencoder   r   Z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      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   r4   r   r&   z   s    

zMessageExtractor._split_commentN)__name__
__module____qualname__r-   r   r   staticmethodr&   r   r   r   r   r      s
   br   )ior   r   r   Zmakor   r   r   r   r   r   r   <module>   s
   