HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/awscli/customizations/configure/__pycache__/writer.cpython-36.pyc
3

�T_�"�@s0ddlZddlZddlmZGdd�de�ZdS)�N�)�SectionNotFoundErrorc@sbeZdZejd�Zejd�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�|jdd�}tjj|�s4|j|�|j|||�dSt|d��}|j�}WdQRXy8|j|||�t|d��}|j	dj
|��WdQRXWn"tk
r�|j|||�YnXdS)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.

        Z__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�/usr/lib/python3.6/writer.py�
update_configs
zConfigFileWriter.update_configc	CsTtjj|�d}tjj|�s&tj|�tjtj|tjtjBd�d��WdQRXdS)Nri�r)	r
r�split�isdir�makedirs�fdopenr�O_WRONLY�O_CREAT)rr�dirnamerrrr
Fs

zConfigFileWriter._create_filecCsLt|d��8}|jd|�g}|jd||d�|jdj|��WdQRXdS)N�az[%s]
r)�line_numberrrr)rr�_insert_new_valuesr)rrrrrrrrrrOsz#ConfigFileWriter._write_new_sectioncCs^xPtt|��D]@}||}|j�jd�r*q|jj|�}|dk	r|j||�r|SqWt|��dS)N�#�;)r'r()�range�len�strip�
startswith�
SECTION_REGEX�search�_matches_sectionr)rrr�i�line�matchrrr�_find_section_startXsz$ConfigFileWriter._find_section_startcCs2|j�}|j||�}|}|d}x�|t|�kr�||}|jj|�dk	rZ|j|||d�dS|jj|�}|dk	r�|}|jd�j�}	|	|kr�t	||	t
�s�||	}
d|	|
f}|||<||	=n4|j||||	t|jd��t|jd�j���}dS|d7}q"W|�r.|dj
d��s|jd�|j|d||d�dS)Nr)r%rrz%s = %s
�
���)�copyr3r*r-r.r&�OPTION_REGEX�groupr+�
isinstance�dict�_update_subattributes�lstrip�endswith�append)rrrrZsection_start_line_numZlast_matching_line�jr1r2�key_name�option_value�new_linerrrrdsB
"

z)ConfigFileWriter._update_section_contentscCs�|d7}x�t|t|��D]�}||}|jj|�}|dk	r�t|jd��t|jd�j��}|jd�j�}	|	|kr�||	}
dd||	|
f}|||<||	=||ks�|jj|�dk	r|j|d||d�PqW||kr�|j|||d�|S)Nrz
%s%s = %s
� z    )	r)r*r7r.r8r<r+r-r&)r�indexr�valuesZstarting_indentr0r1r2Zcurrent_indentr@rArBrrrr;�s*
z&ConfigFileWriter._update_subattributesrcCs�g}x�t|j��D]v\}}t|t�rn|d}|jd||f�xBt|j��D]\}	}
|jd||	|
f�qLWn|jd|||f�||=qW|j|ddj|��dS)Nz    z%s%s =
z
%s%s = %s
rr)�list�itemsr9r:r>�insertr)rr%rr�indentZnew_contents�key�valueZ	subindentZsubkeyZsubvalrrrr&�s


z#ConfigFileWriter._insert_new_valuescCs\|jd�}|jd�d|k}t|�dkrX|jd�d|ddj|dd��fk}|pV|S|S)NrCrz[%s]rz	[%s "%s"])rr8r*r)rr2r�partsZunquoted_matchZquoted_matchrrrr/�s

z!ConfigFileWriter._matches_sectionN)r)�__name__�
__module__�__qualname__�re�compiler-r7rr
rr3rr;r&r/rrrrrs
+		1
r)r
rPrr�objectrrrrr�<module>
s