o
    v&iI                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 g d	Z
d
dlmZ d
dlmZ d
dlmZ d
dlmZ edZedZG dd dZG dd dZdS )zdbrain-dead simple parser for ini-style files.
(C) Ronny Pfannschmidt, Holger Krekel -- MIT licensed
    N)Callable)Iterator)Mapping)Final)TypeVar)overload)	IniConfig
ParseErrorCOMMENTCHARSiscommentline   )_parse)r
   )r   )r	   _D_Tc                   @   s  e Zd ZU ed ed< ee ed< dddeddfddZdededB fdd	Ze	d
ededB fddZ
e	d
edeegef dedB fddZ
e	d
edddeegef dedB fddZ
e	dd
ededddeeB fddZ
e	d
ededeegef deeB fddZ
		dd
ededB deegef dB deeB eB dB fddZ
d
edefddZdee fddZdeeeef  fddZdS )SectionWrapperr   confignamereturnNc                 C   s   || _ || _d S N)r   r   )selfr   r    r   X/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/iniconfig/__init__.py__init__   s   
zSectionWrapper.__init__c                 C   s   | j | j|S r   r   lineofr   r   r   r   r   r   r          zSectionWrapper.lineofkeyc                 C      d S r   r   r   r   r   r   r   get#      zSectionWrapper.getconvertc                 C   r   r   r   )r   r   r"   r   r   r   r    &      defaultc                 C   r   r   r   r   r   r$   r"   r   r   r   r    -      c                 C   r   r   r   r%   r   r   r   r    5   r!   c                 C   r   r   r   r%   r   r   r   r    8   r&   c                 C   s   | j j| j|||dS )N)r"   r$   )r   r    r   r%   r   r   r   r    A   s   c                 C   s   | j j| j | S r   )r   sectionsr   r   r   r   r   __getitem__I   s   zSectionWrapper.__getitem__c                 #   s@     j j ji }dtdtf fdd}t||dE d H  d S )Nr   r   c                    s    j  j| S r   r   r   r   r   r   r   O   r   z'SectionWrapper.__iter__.<locals>.lineofr)   )r   r'   r    r   strintsorted)r   sectionr   r   r*   r   __iter__L   s   zSectionWrapper.__iter__c                 c   s    | D ]	}|| | fV  qd S r   r   r   r   r   r   itemsT   s   zSectionWrapper.itemsr   NN)__name__
__module____qualname__r   __annotations__r+   r   r,   r   r   r    r   r   r   r(   r   r/   tupler0   r   r   r   r   r      sf   
 "
r   c                   @   sn  e Zd ZU ee ed< eeeeeef f  ed< eeeeedB f ef  ed< 		d(ddddee	j
e B dedB ded	eeeeef f dB deeeedB f ef dB d
dfddZe		d(ddddee	j
e B dedB dededed
d fddZd)dededB d
edB fddZededed
edB fddZedededeegef d
edB fddZedededddeegef d
edB f
ddZe	d)dedededdd
eeB f
ddZededededeegef d
eeB f
ddZ		d*dedededB deegef dB d
eeB eB dB f
d dZded
efd!d"Zd
ee fd#d$Zd%ed
efd&d'ZdS )+r   pathr'   N_sourcesutf-8)	_sectionsr8   dataencodingr:   r   c          	      C   s   t || _|d ur|d ur|}|}n*|d u r2t| j|d}| }W d    n1 s-w   Y  tj| j|dd\}}|| _|| _d S )Nr<   F)strip_inline_comments)	osfspathr7   openreadr   parse_ini_datar8   r'   )	r   r7   r;   r<   r:   r8   sections_datasourcesfpr   r   r   r   ^   s   	


zIniConfig.__init__TFr>   strip_section_whitespacer>   rH   c          
      C   sj   t |}|du r#t||d}| }W d   n1 sw   Y  tj||||d\}}	| |||	dS )a  Parse an INI file.

        Args:
            path: Path to the INI file (used for error messages)
            data: Optional INI content as string. If None, reads from path.
            encoding: Encoding to use when reading the file (default: utf-8)
            strip_inline_comments: Whether to strip inline comments from values
                (default: True). When True, comments starting with # or ; are
                removed from values, matching the behavior for section comments.
            strip_section_whitespace: Whether to strip whitespace from section and key names
                (default: False). When True, strips Unicode whitespace from section and key names,
                addressing issue #4. When False, preserves existing behavior for backward compatibility.

        Returns:
            IniConfig instance with parsed configuration

        Example:
            # With comment stripping (default):
            config = IniConfig.parse("setup.cfg")
            # value = "foo" instead of "foo # comment"

            # Without comment stripping (old behavior):
            config = IniConfig.parse("setup.cfg", strip_inline_comments=False)
            # value = "foo # comment"

            # With section name stripping (opt-in for issue #4):
            config = IniConfig.parse("setup.cfg", strip_section_whitespace=True)
            # section names and keys have Unicode whitespace stripped
        Nr=   rG   )r7   r:   r8   )r?   r@   rA   rB   r   rC   )
clsr7   r;   r<   r>   rH   r@   rF   rD   rE   r   r   r   parse}   s   
'

zIniConfig.parser.   r   c                 C   s$   | j ||f}|d u rd S |d S )Nr   )r8   r    )r   r.   r   linenor   r   r   r      s   zIniConfig.lineofc                 C   r   r   r   )r   r.   r   r   r   r   r       r#   zIniConfig.getr"   c                 C   r   r   r   )r   r.   r   r"   r   r   r   r       r&   r$   c                 C   r   r   r   r   r.   r   r$   r"   r   r   r   r          c                 C   r   r   r   rL   r   r   r   r       s   c                 C   r   r   r   rL   r   r   r   r       rM   c                 C   s>   z	| j | | }W n ty   | Y S w |d ur||S |S r   )r'   KeyError)r   r.   r   r$   r"   valuer   r   r   r       s   c                 C   s   || j vr	t|t| |S r   )r'   rN   r   r   r   r   r   r(      s   

zIniConfig.__getitem__c                 c   s(    t | j| jdD ]}t| |V  q	d S )Nr)   )r-   r'   r   r   r   r   r   r   r/      s   zIniConfig.__iter__argc                 C   s
   || j v S r   )r'   )r   rP   r   r   r   __contains__   s   
zIniConfig.__contains__)Nr9   r   r1   )r2   r3   r4   r   r+   r5   r   r6   r,   r?   PathLiker   classmethodboolrJ   r   r   r    r   r   r   r   r(   r   r/   rQ   r   r   r   r   r   Y   s   
  
 6
r   )__doc__r?   collections.abcr   r   r   typingr   r   r   __all__ r   r
   r   
exceptionsr	   r   r   r   r   r   r   r   r   <module>   s"    A