o
    g                     @   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ded	efd
dZded	efddZ	dedede
eeef  fddZdeded	dfddZdededed	dfddZdeded	dfddZedededefddZedededed	dfddZd ed	e
e f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   ]/home/ubuntu/cloudmapper/venv/lib/python3.10/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   s@   z| j |  W S  ty } zd| d}t||d }~ww N'z%' is not stored in the message store.)r
   upperKeyErrorr   )r   r   emsgr   r   r   
get_symbol   s   
zMessageIdStore.get_symbolr   c              
   C   s<   z| j | W S  ty } zd| d}t||d }~ww r   )r   r   r   )r   r   r   r    r   r   r   	get_msgid"   s   
zMessageIdStore.get_msgid	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#   	old_msgid
old_symbolr   r   r   register_message_definition)   s   z*MessageIdStore.register_message_definitionNc                 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	new_msgidc                 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*   existing_old_namesr   r   r   r&   :   s
   


z*MessageIdStore.add_legacy_msgid_and_symbolc                 C   sp   | j |}| j|}|d u r|d u rd S |d ur%||kr%| ||| |r4||kr6| ||| d S d S d S r	   )r   r+   r
   _raise_duplicate_msgid_raise_duplicate_symbol)r   r   r   existing_msgidexisting_symbolr   r   r   r$   G   s   z%MessageIdStore.check_msgid_and_symbolother_symbolc                 C   sB   ||g}|   d|  d}|d|d  d|d  d7 }t|)z+Raise an error when a symbol is duplicated.zMessage id 'z' cannot have both r   r   ' and '   z' as symbolic name.sortr   )r   r   r2   symbolserror_messager   r   r   r/   S   s
   z&MessageIdStore._raise_duplicate_symbolother_msgidc              	   C   s>   ||g}|   d|  d|d  d|d  d|  d	}t|)z*Raise an error when a msgid is duplicated.zMessage symbol 'z' cannot be used for 'r   r3   r4   z?' at the same time. If you're creating an 'old_names' use 'old-z' as the old symbol.r5   )r   r   r9   msgidsr8   r   r   r   r.   \   s   z%MessageIdStore._raise_duplicate_msgidmsgid_or_symbolc                 C   sz   |dd   }d}|r| }| j|}n| j|}|}|du s+|du s+|r+|s5d| d}t|| j||gS )z,Return msgids but the input can be a symbol.r4   NzNo such message id or symbol 'z'.)isdigitr   r
   r+   r   r   r   )r   r;   is_msgidr   r   	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.   r?   r   r   r   r   r      s<    
	
r   N)	typingr   r   r   r   pylint.exceptionsr   r   r   r   r   r   r   <module>   s   