o
    UhD                     @   s2   d Z ddlmZ dd Zdd ZG dd dZd	S )
zMailmap file reader.    )Optionalc                 C   s>   |  dd\}}| }|d }|sd }|sd }||fS )N   <      >)rsplitstriprstrip)textnameemail r   c/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/mailmap.pyparse_identity   s   r   c                 c   sl    | D ]0}| dd }| }|sq| dd\}}|d7 }| r(t|}nd}t|}||fV  qdS )zRead a mailmap.

    Args:
      f: File-like object to read from
    Returns: Iterator over
        ((canonical_name, canonical_email), (from_name, from_email)) tuples
       #r   r   r   N)splitr   r   )flinecanonical_identityfrom_identityparsed_from_identityparsed_canonical_identityr   r   r   read_mailmap(   s   
r   c                   @   s<   e Zd ZdZddddZddddZdd	 Zed
d ZdS )Mailmapz#Class for accessing a mailmap file.Nreturnc                 C   s,   i | _ |r|D ]\}}| || qd S d S N)_table	add_entry)selfmapr   r   r   r   r   __init__C   s   zMailmap.__init__c                 C   sd   |du r	d\}}n|\}}|\}}|du r)|du r)|| j |df< || j d|f< dS || j ||f< dS )a   Add an entry to the mail mail.

        Any of the fields can be None, but at least one of them needs to be
        set.

        Args:
          canonical_identity: The canonical identity (tuple)
          from_identity: The from identity (tuple)
        N)NN)r   )r   r   r   	from_name
from_emailcanonical_namecanonical_emailr   r   r   r   I   s   

zMailmap.add_entryc                 C   s   t |tsd}t|}nd}|d|d f|d dffD ]}| j|}|dur9|d p.|d |d p5|d f} nq|r>|S |d d |d  d S )z$Lookup an identity in this mailmail.FTNr   r   s    <r   )
isinstancetupler   r   get)r   identity	was_tuplequeryr   r   r   r   lookup^   s   

zMailmap.lookupc                 C   s:   t |d}| t|W  d    S 1 sw   Y  d S )Nrb)openr   )clspathr   r   r   r   	from_pathr   s   
$zMailmap.from_pathr   )r   N)	__name__
__module____qualname____doc__r   r   r*   classmethodr/   r   r   r   r   r   @   s    r   N)r3   typingr   r   r   r   r   r   r   r   <module>   s
   