o
    b2                     @   sl   d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	m
Z
 G dd deZG dd	 d	eZd
d ZdS )zHCheck source code is ascii only or has an encoding declaration (PEP 263)    N)IRawCheckerITokenChecker)BaseChecker)
OPTION_RGXMessagesHandlerMixInc                   @   s,   e Zd ZdZeZdZddiZdZdd Z	dS )	ByIdManagedMessagesCheckerzIchecks for messages that are enabled or disabled by id instead of symbol.miscellaneousZI0023)%suse-symbolic-message-insteadz1Used when a message is enabled or disabled by id. c           	      C   sd   t  }|D ]%\}}}}}||jkr+|rdj||d}ndj||d}| jd||d qt   dS )zHinspect the source file to find messages activated or deactivated by id.z;Id '{ident}' is used to disable '{symbol}' message emission)identsymbolz:Id '{ident}' is used to enable '{symbol}' message emissionr
   lineargsN)r   Zget_by_id_managed_msgsnameformatadd_messageZclear_by_id_managed_msgs)	selfmoduleZmanaged_msgsmod_nameZmsg_idZ
msg_symbollinenoZis_disabledtxtr   r   S/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/checkers/misc.pyprocess_module2   s   
z)ByIdManagedMessagesChecker.process_moduleN)
__name__
__module____qualname____doc__r   __implements__r   msgsoptionsr   r   r   r   r   r       s    r   c                       sn   e Zd ZdZeefZdZddddddifd	Zd
dddddffZ	 fddZ
dd Zdd Zdd Z  ZS )EncodingCheckerzWchecks for:
    * warning notes in the code like FIXME, XXX
    * encoding issues.
    r   )r	   fixmez5Used when a warning note as FIXME or XXX is detected.zACannot decode using encoding "%s", unexpected byte at position %dinvalid-encoded-datazSUsed when a source line cannot be decoded using the specified source file encoding.Z
maxversion)   r   )ZW0511ZW0512notescsvz<comma separated values>)ZFIXMEXXXTODOzAList of note tags to take in consideration, separated by a comma.)typemetavardefaulthelpc                    s4   t    tddttj| jj tj	| _
d S )Nz
#\s*(%s)\b|)superopenrecompilejoinmapescapeconfigr&   I_fixme_pattern)r   	__class__r   r   r0   l   s   

zEncodingChecker.openc              
   C   s   z| |W S  ty& } z| jd|||jd fd W Y d }~d S d }~w tye } z4|drLd|v rS||v rZ| jd|d|d W Y d }~d S W Y d }~d S W Y d }~d S W Y d }~d S d }~ww )Nr$      r   #Zcodingzsyntax-errorz/Cannot decode using encoding "{}", bad encoding)decodeUnicodeDecodeErrorr   r   LookupError
startswithr   )r   r   r   file_encodingexr   r   r   _check_encodingr   s$   *zEncodingChecker._check_encodingc                 C   sd   |j r|j }nd}| }t|D ]\}}| |d || qW d   dS 1 s+w   Y  dS )z0inspect the source file to find encoding problemascii   N)rA   stream	enumeraterC   )r   r   encodingrF   r   r   r   r   r   r      s   
"zEncodingChecker.process_modulec              	   C   s  | j jsdS dd |D }|D ]r}|jdd  }t|}|r\z#|ddd\}}dd |dD }t|t| j j@ rCW qW n t	y[   | j
d	|d |jd
 Y qw | jd|  }	|	r|	d}
| j
d|j |
 ||jd d qdS )z)inspect the source to find fixme problemsNc                 s   s     | ]}|j tjkr|V  qd S )N)r*   tokenizeCOMMENT).0Z
token_infor   r   r   	<genexpr>   s    
z1EncodingChecker.process_tokens.<locals>.<genexpr>rE   =c                 S   s   g | ]}|   qS r   )stripupper)rK   Z_valr   r   r   
<listcomp>   s    z2EncodingChecker.process_tokens.<locals>.<listcomp>,zbad-inline-option)r   r   r<   r#   r   )
col_offsetr   r   )r6   r&   stringlstripr   searchgroupsplitset
ValueErrorr   rN   r8   lowerindexstart)r   tokenscommentscommentZcomment_textZdisable_option_match_valuevaluesmatchZnoter   r   r   process_tokens   sD   
	
zEncodingChecker.process_tokens)r   r   r   r   r   r   r   r   r    r!   r0   rC   r   rd   __classcell__r   r   r9   r   r"   C   s.    r"   c                 C   s    |  t|  |  t|  dS )z-required method to auto register this checkerN)Zregister_checkerr"   r   )Zlinterr   r   r   register   s   rf   )r   rI   r1   Zpylint.interfacesr   r   Zpylint.checkersr   Zpylint.utilsr   r   r   r"   rf   r   r   r   r   <module>   s   #p