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: //usr/lib/python3.6/site-packages/ipapython/__pycache__/directivesetter.cpython-36.opt-1.pyc
3

�d[e��@s|ddlZddlZddlZddlZddlZddlmZmZe�Z	Gdd�d�Z
ddd	�Zd
d�Zddd
�Z
dd�Zdd�ZdS)�N)�unescape_seq�
escape_seqc@sBeZdZdZddd�Zdd�Zd	d
�Zeeefdd�Zd
d�Z	dS)�DirectiveSetterzgSafe directive setter

    with DirectiveSetter('/path/to/conf') as ds:
        ds.set(key, value)
    T� �#cCs0tjj|�|_||_||_||_d|_d|_dS)N)	�os�path�abspath�filename�quotes�	separator�comment�lines�stat)�selfr
rrr
�r�%/usr/lib/python3.6/directivesetter.py�__init__szDirectiveSetter.__init__c	Cs6tj|j�� }tj|j��|_t|�|_WdQRX|S)N)	�io�openr
r�fstat�filenor�listr)r�frrr�	__enter__szDirectiveSetter.__enter__cCs |dk	rd|_d|_dStjj|j�\}}tj||dd�\}}tj	|ddd���}x,|jD]"}	t
|	t�sp|	jd�}	|j
|	�qXWd|_tj|j�tj|jj��tj|j�|jj|jj�d|_|j�tj|j��WdQRXtj||j�tj	|tjtjB�}
ztj|
�Wdtj|
�XdS)NT)�prefix�dir�text�w)�mode�closefdzutf-8)rrrr�splitr
�tempfileZmkstemprr�
isinstance�str�decode�write�fchmodr�S_IMODE�st_mode�fchown�st_uid�st_gid�flush�fsync�rename�O_RDONLY�O_DIRECTORY�close)r�exc_typeZexc_valZexc_tbZ	directoryr�fd�namer�line�dirfdrrr�__exit__$s,

zDirectiveSetter.__exit__cCsH|tkr|j}|tkr|j}|tkr*|j}tt|||||j|��|_dS)zSet a single directive
        N)�	_SENTINELrrr
r�set_directive_linesr)r�	directive�valuerrr
rrr�setCszDirectiveSetter.setcCs8t|t�rt|j��}x|D]\}}|j||�qWdS)zISet multiple directives from a dict or list with key/value pairs
        N)r#�dict�sorted�itemsr=)rr@�k�vrrr�setitemsSs
zDirectiveSetter.setitemsN)Trr)
�__name__�
__module__�__qualname__�__doc__rrr8r9r=rCrrrrrs
rTrrcCs�tj|�}t|d��$}t|�}tt||||||��}	WdQRXt|d��}x|	D]}
|j|
�qPWWdQRXtj||j|j�dS)a�Set a name/value pair directive in a configuration file.

    A value of None means to drop the directive.

    Does not tolerate (or put) spaces around the separator.

    :param filename: input filename
    :param directive: directive name
    :param value: value of the directive
    :param quotes: whether to quote `value` in double quotes. If true, then
        any existing double quotes are first escaped to avoid
        unparseable directives.
    :param separator: character serving as separator between directive and
        value.  Correct value required even when dropping a directive.
    :param comment: comment character for the file to keep new values near
                    their commented-out counterpart
    �rNr)	rrrrr:r&�chownr+r,)r
r;r<rrr
�strrZ	new_linesr6rrr�
set_directive]s

rKc
cs�d}|dk	r0|rt|d�n|}dj|||dg�}|dkr<d}d}d}	tjdjtj|�|��}
tjd	j|tj|�|��}xd|D]\}|
j|�r�d
}d}	|dk	r�|Vq||	r�d
}d}	|V|Vq||j|�r�d
}	|Vq||Vq|W|r�|dk	r�|VdS)a!Set a name/value pair in a configuration (iterable of lines).

    Replaces the value of the key if found, otherwise adds it at
    end.  If value is ``None``, remove the key if found.

    Takes an iterable of lines (with trailing newline).
    Yields lines (with trailing newline).

    �N�"�
rz[ 	]+Fz
\s*{}\s*{}z\s*{}\s*{}\s*{}T)�quote_directive_value�join�re�compile�format�escape�match)
rrrArBrr
Znew_lineZv_quoted�foundZaddnextZmatcherZcmatcherr6rrrr:~s8





r:cCs�|dkrd}d}t|d��v}xn|D]f}|j�j|�r"|j�}tjdj||�|�}|r`|jd�}ntdj|���t	|j�d�}|jd�}Pq"WWdQRX|S)	a
    A rather inefficient way to get a configuration directive.

    :param filename: input filename
    :param directive: directive name
    :param separator: separator between directive and value

    :returns: The (unquoted) value if the directive was found, None otherwise
    rz[ 	]+NrHz{}\s*{}\s*(.*)�zMalformed directive: {}rM)
r�lstrip�
startswith�striprQrUrS�group�
ValueError�unquote_directive_value)r
r;r�resultr4r6rUr<rrr�
get_directive�s 

r_cCs2|j|�r|j|�r|Sdj|djt||��d�S)z�Quote a directive value
    :param value: string to quote
    :param quote_char: character which is used for quoting. All prior
        occurences will be escaped before quoting to avoid unparseable value.
    :returns: processed value
    z{quote}{value}{quote}rL)Zquoter<)rY�endswithrSrPr)r<�
quote_charrrrrO�s
rOcCs4djt||��}|j|�r0|j|�r0|dd�S|S)z�Unquote a directive value
    :param value: string to unquote
    :param quote_char: character to strip. All escaped occurences of
        `quote_char` will be uncescaped during processing
    :returns: processed value
    rLrW���)rPrrYr`)r<raZunescaped_valuerrrr]�s


r])Trr)r)rrrQrr"Zipapython.ipautilrr�objectr9rrKr:r_rOr]rrrr�<module>sM
 -
!