a
    =a                     @   s:   d dl mZmZmZmZ d dlmZmZ G dd dZdS )    )DictListOptionalTuple)InvalidMessageErrorUnknownMessageErrorc                   @   s   e Zd ZdZdd Zdd Zdd Zeedd	d
ZeedddZ	eee
eeef  dddZeeddddZeeeddddZeeddddZeeeedddZeeeeddddZee
e d d!d"ZdS )#MessageIdStorezgThe MessageIdStore store MessageId and make sure that there is a 1-1 relation between msgid and symbol.c                 C   s   i | _ i | _i | _d S N) _MessageIdStore__msgid_to_symbol _MessageIdStore__symbol_to_msgid_MessageIdStore__old_namesself r   >lib/python3.9/site-packages/pylint/message/message_id_store.py__init__   s    zMessageIdStore.__init__c                 C   s
   t | jS r	   )lenr
   r   r   r   r   __len__   s    zMessageIdStore.__len__c                 C   s:   d}| j  D ]\}}|d| d| d7 }q|d7 }|S )NzMessageIdStore: [
z  - z (z)
])r
   items)r   resultmsgidsymbolr   r   r   __repr__   s
    zMessageIdStore.__repr__)r   returnc              
   C   sL   z| j | W S  tyF } z"d| d}t||W Y d }~n
d }~0 0 d S N'z%' is not stored in the message store.)r
   KeyErrorr   )r   r   emsgr   r   r   
get_symbol   s
    zMessageIdStore.get_symbol)r   r   c              
   C   sL   z| j | W S  tyF } z"d| d}t||W Y d }~n
d }~0 0 d S r   )r   r   r   )r   r   r   r   r   r   r   	get_msgid"   s
    zMessageIdStore.get_msgid)r   r   	old_namesc                 C   sD   |  || | || |D ]"\}}|  || | ||| qd S r	   )check_msgid_and_symboladd_msgid_and_symboladd_legacy_msgid_and_symbol)r   r   r   r"   Z	old_msgidZ
old_symbolr   r   r   register_message_definition)   s
    z*MessageIdStore.register_message_definitionN)r   r   r   c                 C   s   || j |< || j|< dS )zAdd valid message id.

        There is a little duplication with add_legacy_msgid_and_symbol to avoid a function call,
        this is called a lot at initialization.N)r
   r   )r   r   r   r   r   r   r$   2   s    
z#MessageIdStore.add_msgid_and_symbol)r   r   	new_msgidr   c                 C   s:   || j |< || j|< | j|g }|| || j|< dS )zAdd valid legacy message id.

        There is a little duplication with add_msgid_and_symbol to avoid a function call,
        this is called a lot at initialization.N)r
   r   r   getappend)r   r   r   r'   Zexisting_old_namesr   r   r   r%   :   s
    


z*MessageIdStore.add_legacy_msgid_and_symbolc                 C   sd   | j |}| j|}|d u r,|d u r,d S |d urJ||krJ| ||| ||kr`| ||| d S r	   )r   r(   r
   _raise_duplicate_msgid_raise_duplicate_symbol)r   r   r   Zexisting_msgidZexisting_symbolr   r   r   r#   G   s    z%MessageIdStore.check_msgid_and_symbol)r   r   other_symbolc                 C   sF   ||g}|   d|  d}|d|d  d|d  d7 }t|dS )	z+Raise an error when a symbol is duplicated.zMessage id 'z' cannot have both r   r   ' and '   z' as symbolic name.Nsortr   )r   r   r,   Zsymbolserror_messager   r   r   r+   S   s
    z&MessageIdStore._raise_duplicate_symbol)r   r   other_msgidr   c              	   C   sB   ||g}|   d|  d|d  d|d  d|  d	}t|dS )	z*Raise an error when a msgid is duplicated.zMessage symbol 'z' cannot be used for 'r   r-   r.   z?' at the same time. If you're creating an 'old_names' use 'old-z' as the old symbol.Nr/   )r   r   r2   Zmsgidsr1   r   r   r   r*   \   s    z%MessageIdStore._raise_duplicate_msgid)msgid_or_symbolr   c                 C   sv   |dd   }|r*| }| j|}n| j|}|}|du sR|du sR|rR|sfd| d}t|| j||gS )z,Return msgids but the input can be a symbol.r.   NzNo such message id or symbol 'z'.)isdigitupperr
   r(   r   r   r   )r   r3   Zis_msgidr   r   Z	error_msgr   r   r   get_active_msgidsh   s    z MessageIdStore.get_active_msgids)__name__
__module____qualname____doc__r   r   r   strr    r!   r   r   r&   r$   r%   r#   staticmethodr+   r*   r6   r   r   r   r   r      s$   		r   N)	typingr   r   r   r   Zpylint.exceptionsr   r   r   r   r   r   r   <module>   s   