o
    f?                     @   sf   d dl Z d dlZd dlmZ d dlZdZe de e de dgZdd ZG d	d
 d
ej	Z
dS )    N)StringIOz[a-zA-Z_]+[a-zA-Z0-9_]*z\$z\$[0-9#\?\-@\*]z\$\{.+\}c                 C   s   t D ]
}|| r dS qdS )NTF)SHELL_VAR_REGEXESsearch)textr r   D/usr/lib/python3/dist-packages/cloudinit/distros/parsers/sys_conf.py_contains_shell_variable$   s
   
r	   c                   @   s2   e Zd ZdZdd Zdd ZdddZd	d
 ZdS )SysConfa  A configobj.ConfigObj subclass specialised for sysconfig files.

    :param contents:
        The sysconfig file to parse, in a format accepted by
        ``configobj.ConfigObj.__init__`` (i.e. "a filename, file like object,
        or list of lines").
    c                 C   s   t jj| |ddd d S )NFT)interpolationwrite_empty_values)	configobj	ConfigObj__init__)selfcontentsr   r   r   r   4   s   
zSysConf.__init__c                 C   sJ   |   }t }t|ttfr| d| | S | t| | S )N
)writer   
isinstancelisttuplejoinstrgetvalue)r   r   out_contentsr   r   r   __str__9   s   zSysConf.__str__Fc                    s   t |tstd| t|dkrdS d }|d dv r.|d dv r.t|dkr- fdd}n0| d	r=| d
r=n!td|r^t	|r[td|rT fdd}n
 fdd}nt
j}|sb|S ||S )NzValue "%s" is not a stringr    )"'   c                         | |  S N_get_single_quotexr   r   r   <lambda>K       z SysConf._quote.<locals>.<lambda>z$()z	[\t\r\n ]z[\n\"']c                    r!   r"   )_get_triple_quoter%   r'   r   r   r(   Y   r)   c                    r!   r"   r#   r%   r'   r   r   r(   ]   r)   )r   r   
ValueErrorlenstrip
startswithendswithrer   r	   shlexquote)r   value	multiline	quot_funcr   r'   r   _quoteB   s.   



zSysConf._quotec                 C   s<   |  | |}|  | |}|  |}d||d||f S )Nz
%s%s%s%s%s=)_decode_elementr7   )r   indent_stringentry
this_entrycommentvalkeycmntr   r   r   _write_linee   s   
zSysConf._write_lineN)F)__name__
__module____qualname____doc__r   r   r7   rA   r   r   r   r   r
   +   s    
	#r
   )r1   r2   ior   r   SHELL_VAR_RULEcompiler   r	   r   r
   r   r   r   r   <module>   s   	