HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/ipapython/__pycache__/directivesetter.cpython-39.opt-1.pyc
a

}�f��@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� �#cCs0tj�|�|_||_||_||_d|_d|_dS�N)	�os�path�abspath�filename�quotes�	separator�comment�lines�stat)�selfrrr
r�r�=/usr/lib/python3.9/site-packages/ipapython/directivesetter.py�__init__szDirectiveSetter.__init__cCsJt�|j��*}t�|���|_t|�|_Wd�n1s<0Y|Sr)	�io�openrr�fstat�filenor�listr)r�frrr�	__enter__s(zDirectiveSetter.__enter__c	Cs:|durd|_d|_dStj�|j�\}}tj||dd�\}}tj	|ddd���}|jD]"}	t
|	t�sn|	�d�}	|�
|	�qVd|_t�|��t�|jj��t�|��|jj|jj�d|_|��t�|���Wd�n1s�0Yt�||j�t�	|tjtjB�}
zt�|
�Wt�|
�nt�|
�0dS)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|tur|j}|tur|j}|tur*|j}tt|||||j|��|_dS)zSet a single directive
        N)�	_SENTINELrr
rr�set_directive_linesr)r�	directive�valuerr
rrrr�setCs�zDirectiveSetter.setcCs4t|t�rt|���}|D]\}}|�||�qdS)zISet multiple directives from a dict or list with key/value pairs
        N)r$�dict�sorted�itemsr>)rrA�k�vrrr�setitemsSs
zDirectiveSetter.setitemsN)Trr)
�__name__�
__module__�__qualname__�__doc__rrr9r:r>rDrrrrrs
�
rTrrc	Cs�t�|�}t|d��.}t|�}tt||||||��}	Wd�n1sH0Yt|d��$}|	D]}
|�|
�qbWd�n1s�0Yt�||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-)rr<r=rr
r�strrZ	new_linesr7rrr�
set_directive]s
�$*rLc
cs�d}|dur0|rt|d�n|}d�|||dg�}|dkr<d}d}d}	t�d�t�|�|��}
t�d	�|t�|�|��}|D]\}|
�|�r�d
}d}	|dur�|Vqz|	r�d
}d}	|V|Vqz|�|�r�d
}	|Vqz|Vqz|s�|dur�|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�"�
r�[ 	]+Fz
\s*{}\s*{}z\s*{}\s*{}\s*{}T)�quote_directive_value�join�re�compile�format�escape�match)
rr
rBrCrrZnew_lineZv_quoted�foundZaddnextZmatcherZcmatcherr7rrrr;~s:


�

r;cCs�|dkrd}|durdSd}t|d��r}|D]\}|���|�r,|��}t�d�||�|�}|r,|�d�}nq,t|��d�}|�d�}q�q,Wd�n1s�0Y|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
    rrPNrIz{}\s*{}\s*(.*)�rN)	r�lstrip�
startswith�striprSrWrU�group�unquote_directive_value)rr<r
�resultr5r7rWr=rrr�
get_directive�s&�
$r`cCs2|�|�r|�|�r|Sdj|d�t||��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}rM)�quoter=)r[�endswithrUrRr)r=�
quote_charrrrrQ�s�rQcCs4d�t||��}|�|�r0|�|�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
    rMrY���)rRrr[rb)r=rcZunescaped_valuerrrr^�s
�r^)Trr)r)rrrSrr#Zipapython.ipautilrr�objectr:rrLr;r`rQr^rrrr�<module>sM�
!-
$