%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/utils/ |
Current File : //lib/python2.7/site-packages/salt/utils/configparser.pyo |
� ���^c @@ s� d Z d d l m Z m Z m Z d d l Z d d l Z d d l m Z d d l Ty d d l m Z Wn e k r� e Z n Xd e e f d � � YZ d S( u Custom configparser classes i ( t absolute_importt print_functiont unicode_literalsN( t six( t *( t OrderedDictt GitConfigParserc B@ s� e Z d Z d Z d Z d e e d � Z d � Z e d � Z e d � Z d d � Z d � Z d d � Z d � Z d � Z RS( u� Custom ConfigParser which reads and writes git config files. READ A GIT CONFIG FILE INTO THE PARSER OBJECT >>> import salt.utils.configparser >>> conf = salt.utils.configparser.GitConfigParser() >>> conf.read('/home/user/.git/config') MAKE SOME CHANGES >>> # Change user.email >>> conf.set('user', 'email', 'myaddress@mydomain.tld') >>> # Add another refspec to the "origin" remote's "fetch" multivar >>> conf.set_multivar('remote "origin"', 'fetch', '+refs/tags/*:refs/tags/*') WRITE THE CONFIG TO A FILEHANDLE >>> import salt.utils.files >>> with salt.utils.files.fopen('/home/user/.git/config', 'w') as fh: ... conf.write(fh) >>> u DEFAULTu i c C@ s t t | � j | | | � d S( uM Changes default value for allow_no_value from False to True N( t superR t __init__( t selft defaultst dict_typet allow_no_value( ( s; /usr/lib/python2.7/site-packages/salt/utils/configparser.pyR 3 s c C@ s� d } d } d } d } x�t r�t j j j | j � � } | sF Pn | d } | j � d k s | d d k rx q n | j d d � d j � d k r� | d d k r� q n | j | j � r� d | t | j � } n | j j | � } | r_| j d � } | | j k r"| j | } n4 | | j k r=| j } n | j � } | | j | <d } q | d k r�t t j j j | � | t j j j | � � � q | j j | j � � } | r�| j d d d � \ } } } | j | j � � } | d k rd } n | r�| d k rad | k ra| j d � } | d k ra| | d j � ra| | } qan | j � } | d k r�d } q�n | j | | | � q | s�t | � } n | j | t | � � q W| r�| � n d S( u� Makes the following changes from the RawConfigParser: 1. Strip leading tabs from non-section-header lines. 2. Treat 8 spaces at the beginning of a line as a tab. 3. Treat lines beginning with a tab as options. 4. Drops support for continuation lines. 5. Multiple values for a given option are stored as a list. 6. Keys and values are decoded to the system encoding. i i u u #;u remu rRu u headeru optionu viu valueu =u :u ;i����u ""u ''N( u =u :( u ""u ''( t Nonet Truet saltt utilst stringutilst to_unicodet readlinet stript splitt lowert startswitht SPACEINDENTt lent SECTCREt matcht groupt _sectionst DEFAULTSECTt _defaultst _dictt MissingSectionHeaderErrort to_strt _optcret lstript optionxformt rstript findt isspacet _add_optiont ParsingErrort appendt repr( R t fpt fpnamet cursectt optnamet linenot et linet mot sectnamet vit optvalt pos( ( s; /usr/lib/python2.7/site-packages/salt/utils/configparser.pyt _read; sd "2 c C@ s� | j | j k s | r} t | t � } | rC | rC t d � � n | sU | g } n t d � | D� � s} t d � � q} n d S( u� Based on the string-checking code from the SafeConfigParser's set() function, this enforces string values for config options. u7 option value cannot be a list unless allow_list is Truec s@ s! | ] } t | t j � Vq d S( N( t isinstanceR t string_types( t .0t x( ( s; /usr/lib/python2.7/site-packages/salt/utils/configparser.pys <genexpr>� s u option values must be stringsN( R# t OPTCRER: t listt TypeErrort all( R t valuet allow_listt is_list( ( s; /usr/lib/python2.7/site-packages/salt/utils/configparser.pyt _string_check� s c C@ sA t t | � j | | � } | r= t | t � r= | g } n | S( u� Adds an optional "as_list" argument to ensure a list is returned. This is helpful when iterating over an option which may or may not be a multivar. ( R R t getR: R? ( R t sectiont optiont as_listt ret( ( s; /usr/lib/python2.7/site-packages/salt/utils/configparser.pyRF � s u c C@ s- | j | � t t | � j | | | � d S( u� This is overridden from the RawConfigParser merely to change the default value for the 'value' argument. N( RE R R t set( R RG RH RB ( ( s; /usr/lib/python2.7/site-packages/salt/utils/configparser.pyRK � s c C@ s� t | t � r | | | <n� t | t j � r� y | | j | � Wq� t k r` | | | <q� t k r� | | g | | <| | j | � q� Xn t d t | � j � � d S( Nu- Expected str or list for option value, got %s( R: R? R R; R+ t KeyErrort AttributeErrorR@ t typet __name__( R t sectdictt keyRB ( ( s; /usr/lib/python2.7/site-packages/salt/utils/configparser.pyR) � s c C@ s� | j | d t �| s) | | j k r5 | j } n@ y | j | } Wn, t k rt t t j j j | � � � n X| j | � } | j | | | � d S( uY This function is unique to the GitConfigParser. It will add another value for the option if it already exists, converting the option's value to a list if applicable. If "value" is a list, then any existing values for the specified section and option will be replaced with the list being passed. RC N( RE R R R R RL t NoSectionErrorR R R R"