
    e9                    `    d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
mZmZmZ  G d d      Zy)    )annotations)NoReturn)DeletedMessageErrorInvalidMessageErrorMessageBecameExtensionErrorUnknownMessageError)is_deleted_msgidis_deleted_symbolis_moved_msgidis_moved_symbolc                      e Zd ZdZddZddZddZd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dZy)MessageIdStorezpThe MessageIdStore store MessageId and make sure that there is a 1-1 relation
    between msgid and symbol.
    c                <    i | _         i | _        i | _        i | _        y N) _MessageIdStore__msgid_to_symbol _MessageIdStore__symbol_to_msgid_MessageIdStore__old_names_MessageIdStore__active_msgidsselfs    A/usr/lib/python3/dist-packages/pylint/message/message_id_store.py__init__zMessageIdStore.__init__   s"    13131357    c                ,    t        | j                        S r   )lenr   r   s    r   __len__zMessageIdStore.__len__#   s    4))**r   c                p    d}| j                   j                         D ]  \  }}|d| d| dz  } |dz  }|S )NzMessageIdStore: [
z  - z (z)
])r   items)r   resultmsgidsymbols       r   __repr__zMessageIdStore.__repr__&   sP    &!3399; 	2ME6UG2fXS11F	2#r   c                    	 | j                   |j                            S # t        $ r}d| d}t        |      |d }~ww xY wN'z%' is not stored in the message store.)r   upperKeyErrorr   )r   r!   emsgs       r   
get_symbolzMessageIdStore.get_symbol-   sJ    	2))%++-88 	2eWABC%c*1	2s    	?:?c                h    	 | j                   |   S # t        $ r}d| d}t        |      |d }~ww xY wr%   )r   r(   r   )r   r"   r)   r*   s       r   	get_msgidzMessageIdStore.get_msgid4   sD    	2))&11 	2fXBCC%c*1	2s    	1,1c                    | j                  ||       | j                  ||       |D ]*  \  }}| j                  ||       | j                  |||       , y r   )check_msgid_and_symboladd_msgid_and_symboladd_legacy_msgid_and_symbol)r   r!   r"   	old_names	old_msgid
old_symbols         r   register_message_definitionz*MessageIdStore.register_message_definition;   s\     	##E62!!%0%. 	K!Iz''	:>,,Y
EJ	Kr   c                @    || j                   |<   || j                  |<   y)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"   s      r   r0   z#MessageIdStore.add_msgid_and_symbolD   s$     )/u%).v&r   c                    || j                   |<   || j                  |<   | j                  j                  |g       }|j	                  |       || j                  |<   y)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"   	new_msgidexisting_old_namess        r   r1   z*MessageIdStore.add_legacy_msgid_and_symbolM   s[     )/u%).v&!--11%<!!),"4r   c                    | j                   j                  |      }| j                  j                  |      }||y |||k7  r| j                  |||       |r||k7  r| j	                  |||       y y y r   )r   r8   r   _raise_duplicate_msgid_raise_duplicate_symbol)r   r!   r"   existing_msgidexisting_symbols        r   r/   z%MessageIdStore.check_msgid_and_symbol[   s    %)%;%;%?%?%G&*&<&<&@&@&G"~'=%&++FE>J&8((H  9?r   c                p    ||g}|j                          d|  d}|d|d    d|d    dz  }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"   other_symbolsymbolserror_messages        r   r>   z&MessageIdStore._raise_duplicate_symbolg   sS     <(&ug-@A1WQZL
|;NOO!-00r   c           	     j    ||g}|j                          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   rB   rC   z?' at the same time. If you're creating an 'old_names' use 'old-z' as the old symbol.rD   )r"   r!   other_msgidmsgidsrH   s        r   r=   z%MessageIdStore._raise_duplicate_msgidp   s[     %vh 'q	{'&) -;;A(BVX 	
 "-00r   c                &   	 | j                   |   S # t        $ r Y nw xY wd}d}|dd j                         rF|j                         }| j                  j                  |      }|sPt        |      }|Ct        |      }n7|}| j                  j                  |      }|st        |      }|t        |      }|r|s-|t        ||      |t        ||      d| d}t        |      | j                  j                  ||g      }|| j                   |<   |S )zReturn msgids but the input can be a symbol.

        self.__active_msgids is used to implement a primitive cache for this function.
        NrC   zNo such message id or symbol 'z'.)r   r(   isdigitr'   r   r8   r	   r   r   r
   r   r   r   r   r   )r   msgid_or_symboldeletion_reasonmoved_reasonr!   r"   	error_msgidss           r   get_active_msgidsz MessageIdStore.get_active_msgids|   s6   
	''88 		
 12&&(#))+E++//6F"25"9"*#1%#8L$F**..?E"3F";"*#26#:LF*)/?KK'1/<PP88ILI%i00""55'203_-
s    	N)returnNone)rT   int)rT   str)r!   rW   rT   rW   )r"   rW   rT   rW   )r!   rW   r"   rW   r2   zlist[tuple[str, str]]rT   rU   )r!   rW   r"   rW   rT   rU   )r!   rW   r"   rW   r:   rW   rT   rU   )r!   rW   r"   rW   rF   rW   rT   r   )r"   rW   r!   rW   rJ   rW   rT   r   )rN   rW   rT   z	list[str])__name__
__module____qualname____doc__r   r   r#   r+   r-   r5   r0   r1   r/   staticmethodr>   r=   rS    r   r   r   r      s    8+22KK"%K2GK	K/55"%5255	5
I 1 1 	1 	1'r   r   N)
__future__r   typingr   pylint.exceptionsr   r   r   r   #pylint.message._deleted_message_idsr	   r
   r   r   r   r]   r   r   <module>rb      s-   
 #   L Lr   