a
    I¢b±   ã                   @   s"  d dl mZmZmZ d dl mZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlm  mZ d dlmZmZ edd„ ƒZee_G dd„ deƒZed	kred
ƒZedƒ eejdddƒ edƒ eejdddƒ edƒ eejdddƒ edƒ eejdddƒ dS )é    )ÚdivisionÚabsolute_importÚprint_function)Ú
generatorsN)ÚnodeÚjoinc                 C   s   t dd|   |¡S )Nú )Úsep)r   Zformat_data)ÚchildrenÚdata© r   ú—/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/CoolProp-6.4.2.dev0-py3.9-macosx-10.14-x86_64.egg/CoolProp/BibtexParser.pyÚtoplevel   s    r   c                   @   sD   e Zd ZdZddd„Zg dfdd„Zdd	„ Zddd„Zddd„Zd
S )ÚBibTeXerClasszd
    A base class that defines all the variables needed
    to print a very basic bibliography.
    ú"../../../CoolPropBibTeXLibrary.bibc                 C   s   |   |¡ d S ©N)ÚloadLibrary)ÚselfÚfNamer   r   r   Ú__init__#   s    zBibTeXerClass.__init__Úlatexc                 C   sh  |du rt dƒ‚t|ƒdkr0tjjjj|d}ntjjj ¡ }d}|rÖtjjdd t	|dƒ&}| 
¡ }dd	„ |D ƒ}W d  ƒ n1 sŠ0    Y  |d
 }t	|dƒ }| d |¡¡ W d  ƒ n1 sÌ0    Y  tj	||d}	| |	¡| _W d  ƒ n1 s0    Y  |dkrd| jjD ]<}
| jj|
 }t |j¡D ]<\}}|  |¡|j|< |dkrBd|j|  d |j|< qB|j ¡ D ]Ô}tt|j| ƒƒD ]º}|  |j| |  ¡ ¡|j| | _|  |j| |  ¡ ¡|j| | _|  |j| |  ¡ ¡|j| | _|  |j| |  ¡ ¡|j| | _|  |j| |   ¡ ¡|j| | _!q qŠq$dS )a5  Open a BibTex file and do some initial parsing.
        The path to the file has to be provided, otherwise an exception is raised.

        Optionally, you can provide an array of keys to reduce the amount of
        processed entries immediately.

        By default, the Bibtex file gets scanned with the artificial "latex"
        encoding, which translates Latex commands to their unicode equivalents.
        If you need Latex output, you can skip this step by passing another
        codec to the "encoding" parameter, for example "ascii" or "utf-8".
        Nz,You have to provide a path to a bibtex file.r   )Zwanted_entriesF)ÚenableÚrc                 S   s   g | ]}|  ¡ r|  ¡ ‘qS r   )Ústrip)Ú.0Úlr   r   r   Ú
<listcomp>E   ó    z-BibTeXerClass.loadLibrary.<locals>.<listcomp>z.filtered.bibÚwÚ
©Úencodingr   ZTitleÚ{Ú})"Ú
ValueErrorÚlenÚpybtexZdatabaseÚinputZbibtexÚParserÚerrorsZset_strict_modeÚopenÚ	readlinesÚ
writelinesr   ÚcodecsÚparse_streamÚlibraryÚentriesÚsixÚ	iteritemsÚfieldsÚ
stripCurlsZpersonsÚkeysÚrangeÚfirstZ_firstZmiddleZ_middleZprelastZ_prelastÚlastÚ_lastZlineageZ_lineage)r   Úpathr5   r!   Z
bib_parserZoldLatexCodecÚfÚlinesÚcleanedÚstreamÚtagÚentryÚkeyÚvalueÚir   r   r   r   &   s<    ,.,

$$$$zBibTeXerClass.loadLibraryc                 C   sœ   t dƒdt dƒdi}t|tƒr nnz$| ¡ D ]}|  || ¡||< q*W n tyV   Y n0 t|tg ƒƒrŠtt|ƒƒD ]}|  || ¡||< qr|S | 	|¡}|S )zÎRemove curly brackets from processed Latex code

        A function that always returns unicode. It also tries to recurse into
        lists and dicts, but be careful this is not thoroughly tested.
        r"   Nr#   )
ÚordÚ
isinstanceÚstrr5   r4   ÚAttributeErrorÚtyper6   r%   Ú	translate)r   ÚtextÚtableÚkrC   Ústrippedr   r   r   r4   a   s    

zBibTeXerClass.stripCurlsNÚ	plaintextÚ
unsrtalphaFc                 C   s†   | j du rtdƒ‚tj d|¡}|ƒ }| j }|j||d}tj d|¡}	|	|d}
|r^||
fS t ¡ }|
 ||¡ | 	¡ }| 
¡  |S )ap  This function creates a formatted bibliography according to the
        defined parameters using Pybtex.
        Specify your desired output format using the "fmt" parameter. Supported
        formats are defined by Pybtex and the parameter is only passed on to the
        plugin search function: latex, html, plaintext and markdown.
        The "style" parameter is handled similarly. At the moment, Pybtex partly
        supports the styles: alpha, plain, unsrt and unsrtalpha.
        Use the objects parameter to obtain the formatted bibliography and the
        backend renderer instead of the unicode object.
        Nz No library has been loaded, yet.zpybtex.style.formatting)Z	citationszpybtex.backendsr    )r/   r$   r&   ZpluginZfind_pluginZformat_bibliographyÚioÚStringIOÚwrite_to_streamÚgetvalueÚclose)r   r5   ÚfmtÚstyleÚencÚobjectsZ	style_clsr   ÚbiblioZbackend_clsÚbackendr>   Úcontentsr   r   r   ÚgetBibliography{   s    

zBibTeXerClass.getBibliographyc                 C   s  |  d¡rdS | j|g|||dd\}}dd„ |_dd„ |_t ¡ }| ||¡ | ¡ }	| ¡  |rh|	S dd	d
d
dœ}
|	 	|
| ¡}|	|t
|
| ƒ d…  ¡ }	|	 dd¡ dd¡}	|dkrÖ|	 dd¡}	t |	d¡}	n |dkrö|	 dd¡}	|	 dd¡}	|	 dd¡}	|	S )a0  If you only want a single entry from your bibliography and not the
        whole thing, this function is for you.
        It uses Pybtex, but removes the prologue and the epilogue and optionally
        deletes the label.
        For the other parameters, have a look at :func:`getBibliography`.
        Ú__NT)r5   rU   rV   rW   rX   c                   S   s   d S r   r   r   r   r   r   Ú<lambda>©   r   z(BibTeXerClass.getEntry.<locals>.<lambda>c                   S   s   d S r   r   r   r   r   r   r^   ª   r   r#   z</dt>Ú])r   ÚhtmlÚmarkdownrN   r"   Ú r   z
\newblock r`   z<dd>z</dd>r   )Ú
startswithr\   Zwrite_prologueZwrite_epiloguerP   rQ   rR   rS   rT   Úindexr%   r   Úreplacer-   Úencode)r   rA   ÚlabelrU   rV   rW   rY   rZ   r>   r[   Zlabel_tableZend_of_labelr   r   r   ÚgetEntry›   s6    


üzBibTeXerClass.getEntry)r   )NrN   rO   NF)FrN   rO   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r4   r\   rh   r   r   r   r   r      s   
;
 r   Ú__main__r   z
Latex:zMulero-JPCRD-2012r   )rA   rU   z
HTML:r`   z

Markdown:ra   z
Text:rN   )Ú
__future__r   r   r   r   Zpybtex.pluginr&   Zpybtex.database.input.bibtexZpybtex.errorsrP   r-   Z
latexcodecÚosr1   Zpybtex.style.formattingrV   Z
formattingZpybtex.style.templater   r   r   Úobjectr   ri   ÚBÚprintrh   r   r   r   r   Ú<module>   s.   
 4
