Mini Shell

Direktori : /lib64/python3.6/site-packages/pyanaconda/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pyanaconda/__pycache__/simpleconfig.cpython-36.pyc

3

@��e��@svddlZddlZddlZddlZddlmZeejejd�Z	dd�Z
ddd�Zd	d
�Zdd�Z
Gd
d�de�ZdS)�N)�
upperASCIIz
@%_-+=:,./cCsdjtj|��S)N� )�join�shlex�split)�s�r�$/usr/lib64/python3.6/simpleconfig.py�unquotesr
FcCs4|s x|D]}|tkr
Pq
W|Sd|jdd�dS)z0 If always is set it returns a quoted value
    �"z\")�
_SAFECHARS�replace)r�always�crrr	�quote!s
rcCsbd}xXtt|��D]H}|r,||dkr,|S||dkr|||krJd}q|dkr||}qWdS)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�irrr	�find_comment-s
rcCsztjddtjj|�pddtjj|�d�}|j|�|j�tjj|�rVtj	|�j
}nd}tj|j|�tj
|j|�dS)N�wF�.)�mode�delete�dir�prefixi�)�tempfileZNamedTemporaryFile�os�path�dirname�basename�write�close�exists�stat�st_mode�chmod�name�rename)�filename�dataZtmpf�mrrr	�
write_tmpfileEs
r-c@sheZdZdZddd�Zdd�Zdd	d
�Zddd�Zd
d�Zdd�Z	dd�Z
dd�Zddd�Zdd�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.
    NTFcCs$||_||_||_||_|j�dS)N)r*�read_unquote�write_quote�always_quote�reset)�selfr*r/r0r1rrr	�__init__as
zSimpleConfigFile.__init__cCsg|_i|_dS)N)�_lines�info)r3rrr	r2iszSimpleConfigFile.resetcCsZ|p|j}t|��>}x6|D].}|jj|�|j|�\}}}|r||j|<qWWdQRXdS)z� passing filename will override the filename passed to init.

            save the lines into self._lines and the key/value pairs into
            self.info
        N)r*�openr5�append�
_parseliner6)r3r*�f�line�key�valueZ_commentrrr	�readms


zSimpleConfigFile.readc
CsN|p|j}|sdS|r&t|t|��n$t|d��}|jt|��WdQRXdS)zE passing filename will override the filename passed to init.
        Nr)r*r-�strr7r")r3r*Zuse_tmpZfobjrrr	r"{s
zSimpleConfigFile.writecGs$x|D]\}}||jt|�<qWdS)N)r6r)r3�argsr<r=rrr	�set�szSimpleConfigFile.setcGs.x(dd�|D�D]}||jkr|j|=qWdS)Ncss|]}t|�VqdS)N)r)�.0�krrr	�	<genexpr>�sz)SimpleConfigFile.unset.<locals>.<genexpr>)r6)r3�keysr<rrr	�unset�s
zSimpleConfigFile.unsetcCs|jjt|�d�S)N�)r6�getr)r3r<rrr	rH�szSimpleConfigFile.getcCs�|j�}d}t|�}|dk	r4||d�}|d|�}|jd�\}}}|j�}|j�}|jrbt|�}|dkr�|dkr�t|�||fSdd|fSdS)a� parse a line into a key, value and comment

            :param str line: Line to be parsed
            :returns: Tuple of key, value, comment
            :rtype: tuple

            Handle comments and optionally unquote quoted strings
            Returns (key, value, comment) or (None, None, comment)
            key is always UPPERCASE and comment may by "" if none was found.
        rGN�=)�stripr�	partitionr/r
r)r3r;r�commentZ
comment_indexr<�eq�valrrr	r9�szSimpleConfigFile._parselinerGcCsB|j|}|js|jr"t||j�}|r.d|}|d||dS)NrrI�
)r6r0r1r)r3r<rLr=rrr	�_kvpair�s
zSimpleConfigFile._kvpaircCs�g}d}xV|jD]L}|j|�\}}}|dkr6||7}q||jkrBq|j|�||j||�7}qWx$|jD]}||krh||j|�7}qhW|S)z� Return the file that was read, replacing existing keys with new values
            removing keys that have been deleted and adding new keys.
        rGN)r5r9r6r8rP)r3Zoldkeysrr;r<Z_valuerLrrr	�__str__�s


zSimpleConfigFile.__str__)NTTF)N)NT)rG)�__name__�
__module__�__qualname__�__doc__r4r2r>r"rArFrHr9rPrQrrrr	r.Ys



r.)F)rr�stringrZpyanaconda.core.utilr�	frozensetZ
ascii_lettersZdigitsrr
rrr-�objectr.rrrr	�<module>s