Mini Shell
3
@��e� � @ sv d dl Z d dlZd dlZd dlZd dlmZ eejej d �Z dd� Z
ddd�Zd d
� Zdd� Z
G d
d� de�ZdS )� N)�
upperASCIIz
@%_-+=:,./c C s dj tj| ��S )N� )�join�shlex�split)�s� r �$/usr/lib64/python3.6/simpleconfig.py�unquote s r
Fc C s4 |s x| D ]}|t kr
P q
W | S d| jdd� d S )z0 If always is set it returns a quoted value
�"z\")�
_SAFECHARS�replace)r �always�cr r r �quote! s
r c C sb d}xXt t| ��D ]H}| r,| | dkr,|S | | dkr| | |krJd}q|dkr| | }qW dS )a< Look for a # comment outside of a quoted string.
If there are no quotes, find the last # in the string.
:param str s: string to check for comment and quotes
:returns: index of comment or None
:rtype: int or None
Handles comments inside quotes and quotes inside quotes.
N�#z'")�range�len)r �q�ir r r �find_comment- s
r c C sz t jddtjj| �pddtjj| � d�}|j|� |j� tjj| �rVtj | �j
}nd}tj|j|� tj
|j| � d S )N�wF�.)�mode�delete�dir�prefixi� )�tempfileZNamedTemporaryFile�os�path�dirname�basename�write�close�exists�stat�st_mode�chmod�name�rename)�filename�dataZtmpf�mr r r �
write_tmpfileE s
r- c @ sh e Zd ZdZddd�Zdd� Zdd d
�Zddd�Zd
d� Zdd� Z dd� Z
dd� Zddd�Zdd� Z
dS )�SimpleConfigFilea5 Edit values in a configuration file without changing comments.
Supports KEY=VALUE lines and ignores everything else.
Supports adding new keys.
Supports deleting keys.
Preserves comment, blank lines and comments on KEY lines
Does not support duplicate key entries.
NTFc C s$ || _ || _|| _|| _| j� d S )N)r* �read_unquote�write_quote�always_quote�reset)�selfr* r/ r0 r1 r r r �__init__a s
zSimpleConfigFile.__init__c C s g | _ i | _d S )N)�_lines�info)r3 r r r r2 i s zSimpleConfigFile.resetc C sZ |p| j }t|��>}x6|D ].}| jj|� | j|�\}}}|r|| j|<