File: //usr/lib/python3.6/site-packages/ipapython/__pycache__/directivesetter.cpython-36.pyc
3
�d[e� � @ s| d dl Z d dlZd dlZd dlZd dlZd dlmZmZ e� Z G dd� d�Z
ddd �Zd
d� Zddd
�Z
dd� Zdd� ZdS )� N)�unescape_seq�
escape_seqc @ sB e Zd ZdZddd�Zdd� Zd d
� Zeeefdd�Zd
d� Z dS )�DirectiveSetterzgSafe directive setter
with DirectiveSetter('/path/to/conf') as ds:
ds.set(key, value)
T� �#c C s0 t jj|�| _|| _|| _|| _d | _d | _d S )N) �os�path�abspath�filename�quotes� separator�comment�lines�stat)�selfr
r r r
� r �%/usr/lib/python3.6/directivesetter.py�__init__ s zDirectiveSetter.__init__c C s6 t j| j�� }tj|j� �| _t|�| _W d Q R X | S )N) �io�openr
r �fstat�filenor �listr )r �fr r r � __enter__ s zDirectiveSetter.__enter__c C s |d k rd | _ d | _d S tjj| j�\}}tj||dd�\}}tj |ddd���}x,| j D ]"} t
| t�sp| jd�} |j
| � qXW d | _ tj|j� tj| jj�� tj|j� | jj| jj� d | _|j� tj|j� � W d Q R X tj|| j� tj |tjtjB �}
ztj|
� W d tj|
� X d S )NT)�prefix�dir�text�w)�mode�closefdzutf-8)r r r r �splitr
�tempfileZmkstempr r �
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�dirfdr r r �__exit__$ s,
zDirectiveSetter.__exit__c C sH |t kr| j}|t kr| j}|t kr*| j}tt||||| j|��| _dS )zSet a single directive
N)� _SENTINELr r r
r �set_directive_linesr )r � directive�valuer r r
r r r �setC s zDirectiveSetter.setc C s8 t |t�rt|j� �}x|D ]\}}| j||� qW dS )zISet multiple directives from a dict or list with key/value pairs
N)r# �dict�sorted�itemsr= )r r@ �k�vr r r �setitemsS s
zDirectiveSetter.setitemsN)Tr r )
�__name__�
__module__�__qualname__�__doc__r r r8 r9 r= rC r r r r r s
r Tr r c C s� t j| �}t| d��$}t|�}tt||||||��} W dQ R X t| d��}x| D ]}
|j|
� qPW W dQ R X t j| |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 ) r r r r r: r&