
    e                        d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZ ddlmZ ej                  dk\  rddlZnddlZe	rddlmZ ee
eef   ee   f   Z G d	 d
      Z G d d      Zy)z Configuration file parser class.    )annotationsN)Path)TYPE_CHECKINGDictListTuple)_parse_rich_type_value)      )PyLinterc                  d    e Zd ZdZedd       Zedd       Zedd       Ze	 	 	 	 	 	 d	d       Zy)
_RawConfParser6Class to parse various formats of configuration files.c                t   t        j                  d      }t        | d      5 }|j                  |       ddd       i }g }t        j                  |       }|j                         D ]@  }|r|j                  d      s||   j                         D ]  \  }}|||<   |d| |gz  } B ||fS # 1 sw Y   yxY w)zfParse and handle errors of an ini configuration file.

        Raises ``configparser.Error``.
        )#;)inline_comment_prefixes	utf_8_sig)encodingNpylint--)	configparserConfigParseropen	read_filer   _ini_file_with_sectionssections
startswithitems)		file_pathparserfpconfig_contentoptionsini_file_with_sectionssectionoptionvalues	            B/usr/lib/python3/dist-packages/pylint/config/config_file_parser.pyparse_ini_filez_RawConfParser.parse_ini_file   s     **:N)k2 	!bR 	! *,!/!G!G	!R( 	2G%g.@.@.J!'!6!6!8 2).v&bM5112	2 w&&	! 	!s   B..B7c                @    d| j                   v ryd| j                   v ryy)z&Return whether the file uses sections.z	setup.cfgTztox.iniF)parts)r    s    r)   r   z&_RawConfParser._ini_file_with_sections5   s%     )//)	'    c                   t        | d      5 }t        j                  |      }ddd       	 d   d   }i }g }|j	                         D ]b  \  }}t        |t              r3|j	                         D ]  \  }}	t        |	      }	|	||<   |d| |	gz  }! It        |      }|||<   |d| |gz  }d ||fS # 1 sw Y   xY w# t        $ r i g fcY S w xY w)zkParse and handle errors of a toml configuration file.

        Raises ``tomllib.TOMLDecodeError``.
        rb)modeNtoolr   r   )r   tomllibloadKeyErrorr   
isinstancedictr	   )
r    r"   contentsections_valuesr#   r$   optvaluesconfigr(   s
             r)   parse_toml_filez_RawConfParser.parse_toml_file>   s    )$' 	'2ll2&G	'	%foh7O *,*002 		0KC&$'%+\\^ 6MFE259E-2N6*"VHu55G6
 07&,s#bJ//		0 w&&'	' 	'  	r6M	s   B2B> 2B;>CCc                   | !|rt        dt        j                         i g fS t        t        j
                  j                  |             j                         } | j                         st        d|  d      |rt        d|  t        j                         | j                  dk(  rt        j                  |       S t        j                  |       S )z{Parse a config file and return str-str pairs.

        Raises ``tomllib.TOMLDecodeError``, ``configparser.Error``.
        z1No config file found, using default configuration)filezThe config file z doesn't exist!zUsing config file z.toml)printsysstderrr   ospath
expandvars
expanduserexistsOSErrorsuffixr   r<   r*   )r    verboses     r)   parse_config_filez _RawConfParser.parse_config_fileY   s     Gcjj r6M++I67BBD	!,YKGHH&yk2Dw&!11)<<,,Y77r-   N)r    r   returnPylintConfigFileData)r    r   rK   bool)r    Path | NonerI   rM   rK   rL   )	__name__
__module____qualname____doc__staticmethodr*   r   r<   rJ    r-   r)   r   r      sk    @' '*   ' '4 88)-8	8 8r-   r   c                       e Zd ZdZddZddZy)_ConfigurationFileParserr   c                     || _         || _        y )N)verbose_modelinter)selfrI   rY   s      r)   __init__z!_ConfigurationFileParser.__init__w   s    #r-   c                    	 t         j                  || j                        S # t        j                  t
        j                  f$ r5}| j                  j                  ddt        |             i g fcY d}~S d}~ww xY w)z-Parse a config file and return str-str pairs.zconfig-parse-errorr   )lineargsN)
r   rJ   rX   r   Errorr2   TOMLDecodeErrorrY   add_messagestr)rZ   r    es      r)   rJ   z*_ConfigurationFileParser.parse_config_file{   sh    	!33It?P?PQQ""G$;$;< 	KK##$8qs1v#Nr6M	s   " #A:*A5/A:5A:N)rI   rM   rY   r   rK   None)r    rN   rK   rL   )rO   rP   rQ   rR   r[   rJ   rT   r-   r)   rV   rV   t   s    @r-   rV   )rR   
__future__r   r   rB   r@   pathlibr   typingr   r   r   r   pylint.config.utilsr	   version_infor2   tomlipylint.lintr   rb   rL   r   rV   rT   r-   r)   <module>rl      so   
 ' "  	 
  3 3 6w$T#s(^T#Y67 U8 U8p r-   