U
    e1!                     @   s   d dl mZ d dlZeeZeddddddd	d
ddddddgZeddddddddddddgZG dd de	Z
G dd  d eZG d!d" d"eZG d#d$ d$eZd%d& ZdS )'    )OrderedDictNZarticlebookZbookletZ
conferenceZinbookZincollectionZinproceedingsZmanualZmastersthesisZmiscZ	phdthesisZproceedingsZ
techreportZunpublished)janJanuary)febFebruary)marMarch)aprApril)mayMay)junJune)julJuly)augAugust)sep	September)octOctober)novNovember)decDecemberc                   @   s   e Zd ZdS )UndefinedStringN)__name__
__module____qualname__ r    r    v/mounts/lovelace/software/anaconda3/envs/qiime2-shotgun-2023.9/lib/python3.8/site-packages/bibtexparser/bibdatabase.pyr   )   s   r   c                   @   sb   e Zd ZdZdd Zdd Zdd Zedd	 Zd
d Z	e
e	Zdd Ze fddZdd ZdS )BibDatabasezY
    Bibliographic database object that follows the data structure of a BibTeX file.
    c                 C   s,   g | _ i | _g | _t | _g | _dg| _d S )N_FROM_CROSSREF)entries_entries_dictcommentsr   stringsZ	preambles_not_updated_by_crossrefselfr    r    r!   __init__2   s    zBibDatabase.__init__c                 C   s   | j t d S N)r'   updateCOMMON_STRINGSr)   r    r    r!   load_common_stringsE   s    zBibDatabase.load_common_stringsc                 C   s   | j S )zGet a list of bibtex entries.

        :returns: BibTeX entries
        :rtype: list
        .. deprecated:: 0.5.6
           Use :attr:`entries` instead.
        )r$   r)   r    r    r!   get_entry_listH   s    zBibDatabase.get_entry_listc                 C   s0   g }|D ]}| t| |d  qt|S )N )appendstrgetlowertuple)entryfieldsresultfieldr    r    r!   entry_sort_keyR   s    zBibDatabase.entry_sort_keyc                 C   s(   t  | _| jD ]}|| j|d < q| jS )zReturn a dictionary of BibTeX entries, where dict key is the BibTeX entry key.
        
        This method re-creates the dict every time it is called,
        hence subsequent calls should be avoided with large databases.
        ID)dictr%   r$   r*   r7   r    r    r!   get_entry_dictY   s    
zBibDatabase.get_entry_dictc                 C   s4   zt | j| W S  tk
r.   t|Y nX d S r,   )BibDataStringExpressionexpand_if_expressionr'   KeyErrorr   )r*   namer    r    r!   expand_stringf   s    zBibDatabase.expand_stringc                    s    d j krd S  d jkr:td d  d  d S  d |krhtdd| d  d  d S j d  }d|kr| d  || | d   fdd| D } 	| j 
 d  t|  d<  d= d S )	Nr<   	_crossrefz(Crossref reference %s for %s is missing.z)Circular crossref dependency: %s->%s->%s.z->c                    s,   i | ]$\}}|   kr|jkr||qS r    )keysr(   ).0ZbibfieldZbibvaluer7   r*   r    r!   
<dictcomp>   s
   
 z@BibDatabase._add_missing_from_crossref_entry.<locals>.<dictcomp>r#   )_crossref_updatedentries_dictloggererrorjoinadd _add_missing_from_crossref_entryremoveitemsr-   r2   sortedrF   )r*   r7   dependenciesZcrossref_entryZfrom_crossrefr    rH   r!   rP   m   s6    
z,BibDatabase._add_missing_from_crossref_entryc                 C   s(   g | _ | jD ]}d|kr| | qdS )z:Resolve crossrefs and update entries accordingly.
        rE   N)rJ   r$   rP   r>   r    r    r!   add_missing_from_crossref   s    
z%BibDatabase.add_missing_from_crossrefN)r   r   r   __doc__r+   r/   r0   staticmethodr;   r?   propertyrK   rD   setrP   rU   r    r    r    r!   r"   -   s   

"r"   c                   @   sJ   e Zd ZdZdd Zdd Zdd Zdd	 Ze fd
dZ	e
dd ZdS )BibDataStringz
    Represents a bibtex string.

    This object enables maintaining string expressions as list of strings
    and BibDataString. Can be interpolated from Bibdatabase.
    c                 C   s   || _ | | _d S r,   )_bibdatabaser5   rC   )r*   bibdatabaserC   r    r    r!   r+      s    zBibDataString.__init__c                 C   s   t |to| j|jkS r,   )
isinstancerZ   rC   r*   otherr    r    r!   __eq__   s    zBibDataString.__eq__c                 C   s   d | j S )NzBibDataString({}))formatrC   __repr__r)   r    r    r!   rb      s    zBibDataString.__repr__c                 C   s   | j | jS )zI
        Query value from string name.

        :returns: string
        )r[   rD   rC   r)   r    r    r!   	get_value   s    zBibDataString.get_valuec                 C   s   t dS )z~Recursively tracks strings on which the expression depends.

        :param kown_dependencies: dependencies to ignore
        N)NotImplementedError)r*   Zknown_dependenciesr    r    r!   get_dependencies   s    zBibDataString.get_dependenciesc                 C   s   t | tr|  S | S dS )z
        Eventually replaces a bibdatastring by its value.

        :param string_or_bibdatastring: the parsed token
        :type string_expr: string or BibDataString
        :returns: string
        N)r]   rZ   rc   )Zstring_or_bibdatastringr    r    r!   rD      s    	
zBibDataString.expand_stringN)r   r   r   rV   r+   r`   rb   rc   rY   re   rW   rD   r    r    r    r!   rZ      s   rZ   c                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
e	dd ZdS )r@   a  
    Represents a bibtex string expression.

    String expressions are sequences of regular strings and bibtex strings.
    This object enables maintaining string expressions as list of strings.
    The expression are represented as lists of regular strings and
    BibDataStrings. They can be interpolated from Bibdatabase.

    BibDataStringExpression(e)

    :param e: list of strings and BibDataStrings
    c                 C   s
   || _ d S r,   expr)r*   
expressionr    r    r!   r+      s    z BibDataStringExpression.__init__c                 C   s   t |to| j|jkS r,   )r]   r@   rg   r^   r    r    r!   r`      s    zBibDataStringExpression.__eq__c                 C   s   d | j S )NzBibDataStringExpression({}))ra   rg   rb   r)   r    r    r!   rb      s    z BibDataStringExpression.__repr__c                 C   s   d dd | jD S )zf
        Replaces bibdatastrings by their values in the expression.

        :returns: string
        r1   c                 S   s   g | ]}t |qS r    )rZ   rD   rG   sr    r    r!   
<listcomp>   s     z5BibDataStringExpression.get_value.<locals>.<listcomp>)rN   rg   r)   r    r    r!   rc      s    z!BibDataStringExpression.get_valuec                    s    fdd| j D | _ dS )z
        Maps a function on strings in expression, keeping unchanged
        BibDataStrings.

        :param fun: function from strings to strings
        c                    s"   g | ]}t |tr|n |qS r    )r]   rZ   ri   funr    r!   rk      s   z<BibDataStringExpression.apply_on_strings.<locals>.<listcomp>Nrf   )r*   rm   r    rl   r!   apply_on_strings   s    
z(BibDataStringExpression.apply_on_stringsc                 C   s   t | tr|  S | S dS )z
        Eventually replaces a BibDataStringExpression by its value.

        :param string_or_expression: the object to expand
        :type string_expr: string or BibDataStringExpression
        :returns: string
        N)r]   r@   rc   )Zstring_or_expressionr    r    r!   rA      s    	
z,BibDataStringExpression.expand_if_expressionc                 C   s.   t | dkr"t| d ts"| d S t| S dS )zABuild expression only if tokens are not a regular value.
           r   N)lenr]   rZ   r@   )tokensr    r    r!   expression_if_needed   s    z,BibDataStringExpression.expression_if_neededN)r   r   r   rV   r+   r`   rb   rc   rn   rW   rA   rr   r    r    r    r!   r@      s   

r@   c                 C   s"   t | ttfr|  S t| S d S r,   )r]   rZ   r@   rc   r3   )Ztext_string_or_expressionr    r    r!   as_text	  s
    rs   )collectionsr   logging	getLoggerr   rL   rY   ZSTANDARD_TYPESr.   rB   r   objectr"   rZ   r@   rs   r    r    r    r!   <module>   sJ   
k0A