HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/awscli/customizations/configure/__pycache__/writer.cpython-310.pyc
o

.&�a�"�@s0ddlZddlZddlmZGdd�de�ZdS)�N�)�SectionNotFoundErrorc@sbeZdZe�d�Ze�d�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zddd�Z
dd�ZdS)�ConfigFileWriterz^\s*\[(?P<header>[^]]+)\]z7(?P<option>[^:=][^:=]*)\s*(?P<vi>[:=])\s*(?P<value>.*)$cCs�|�dd�}tj�|�s|�|�|�|||�dSt|d��}|��}Wd�n1s.wYz)|�|||�t|d��}|�	d�
|��Wd�WdS1sUwYWdStym|�|||�YdSw)a�Update config file with new values.

        This method will update a section in a config file with
        new key value pairs.

        This method provides a few conveniences:

        * If the ``config_filename`` does not exist, it will
          be created.  Any parent directories will also be created
          if necessary.
        * If the section to update does not exist, it will be created.
        * Any existing lines that are specified by ``new_values``
          **will not be touched**.  This ensures that commented out
          values are left unaltered.

        :type new_values: dict
        :param new_values: The values to update.  There is a special
            key ``__section__``, that specifies what section in the INI
            file to update.  If this key is not present, then the
            ``default`` section will be updated with the new values.

        :type config_filename: str
        :param config_filename: The config filename where values will be
            written.

        �__section__�defaultN�r�w�)�pop�os�path�isfile�_create_file�_write_new_section�open�	readlines�_update_section_contents�write�joinr)�self�
new_values�config_filename�section_name�f�contents�r�H/usr/lib/python3/dist-packages/awscli/customizations/configure/writer.py�
update_configs 

�&��zConfigFileWriter.update_configcCsjtj�|�d}tj�|�st�|�t�t�|tjtjBd�d��	Wd�dS1s.wYdS)Nri�r)	rr�split�isdir�makedirs�fdopenr�O_WRONLY�O_CREAT)rr�dirnamerrrrFs

��"�zConfigFileWriter._create_filecCsbt|d��"}|�d|�g}|jd||d�|�d�|��Wd�dS1s*wYdS)N�az[%s]
r��line_numberrrr	)rr�_insert_new_valuesr)rrrrrrrrrrOs�"�z#ConfigFileWriter._write_new_sectioncCsZtt|��D]"}||}|���d�rq|j�|�}|dur(|�||�r(|Sqt|��)N)�#�;)�range�len�strip�
startswith�
SECTION_REGEX�search�_matches_sectionr)rrr�i�line�matchrrr�_find_section_startXs��z$ConfigFileWriter._find_section_startc
Cs8|��}|�||�}|}|d}|t|�kr�||}|j�|�dur,|j|||d�dS|j�|�}|durv|}|�d���}	|	|vrvt	||	t
�s\||	}
d|	|
f}|||<||	=n|�||||	t|�d��t|�d�����}dS|d7}|t|�ks|r�|d�
d�s�|�d�|j|d||d�dSdS)Nrr&z%s = %s
����
)�copyr5r,r/r0r(�OPTION_REGEX�groupr-�
isinstance�dict�_update_subattributes�lstrip�endswith�append)rrrr�section_start_line_num�last_matching_line�jr3r4�key_name�option_value�new_linerrrrdsN��
��


��z)ConfigFileWriter._update_section_contentscCs�|d7}t|t|��D]X}||}|j�|�}|durJt|�d��t|�d����}|�d���}	|	|vrJ||	}
dd||	|
f}|||<||	=||ksV|j�|�durc|�|d||d�|Sq||krp|�|||d�|S)Nr�
%s%s = %s
� �    )	r+r,r9r0r:r>r-r/r()r�indexr�values�starting_indentr2r3r4�current_indentrDrErFrrrr=�s6����z&ConfigFileWriter._update_subattributesr	cCs�g}t|���D]9\}}t|t�r4|d}|�d||f�t|���D]\}	}
|�d||	|
f�q$n
|�d|||f�||=q|�|dd�|��dS)NrIz%s%s =
rGrr	)�list�itemsr;r<r@�insertr)rr'rr�indent�new_contents�key�value�	subindent�subkey�subvalrrrr(�s


��z#ConfigFileWriter._insert_new_valuescCs\|�d�}|�d�d|k}t|�dkr,|�d�d|dd�|dd��fk}|p+|S|S)NrHrz[%s]rz	[%s "%s"])rr:r,r)rr4r�parts�unquoted_match�quoted_matchrrrr1�s

�z!ConfigFileWriter._matches_sectionN)r	)�__name__�
__module__�__qualname__�re�compiler/r9rrrr5rr=r(r1rrrrrs
�+		1
r)rr^r	r�objectrrrrr�<module>s