o
    x[h�  ã                   @   s<   d dl Z d dlZd dlmZ e e¡ZG dd„ deeƒZdS )é    N)ÚConfigSourcec                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú
ConfigFilez>ConfigFile module to load the content from a specified source.c                 C   s   |   |¡ d S )N)Ú_loadConfigFile)ÚselfÚfilename© r   úR/usr/lib/python3/dist-packages/cloudinit/sources/helpers/vmware/imc/config_file.pyÚ__init__   s   zConfigFile.__init__c                 C   sX   |  ¡ }|  ¡ }| d¡sd|v rd}nd}|r t d||¡ nt d|¡ || |< dS )z˜
        Inserts a Key Value pair.

        Keyword arguments:
        key -- The key to insert
        val -- The value to insert for the key

        ú-z|-FTzADDED KEY-VAL :: '%s' = '%s'z+ADDED KEY-VAL :: '%s' = '*****************'N)ÚstripÚ
startswithÚloggerÚdebug)r   ÚkeyÚvalÚcanLogr   r   r   Ú
_insertKey   s   	zConfigFile._insertKeyc                 C   sr   t  d|¡ t ¡ }t|_| |¡ |  ¡  | ¡ D ]}t  	d|¡ | 
|¡D ]\}}|  |d | |¡ q'qdS )a%  
        Parses properties from the specified config file.

        Any previously available properties will be removed.
        Sensitive data will not be logged in case the key starts
        from '-'.

        Keyword arguments:
        filename - The full path to the config file.
        zParsing the config file %s.zFOUND CATEGORY = '%s'ú|N)r   ÚinfoÚconfigparserÚConfigParserÚstrÚoptionxformÚreadÚclearÚsectionsr   Úitemsr   )r   r   ÚconfigÚcategoryr   Úvaluer   r   r   r   /   s   
ÿýzConfigFile._loadConfigFilec                    s   t ‡ fdd„| D ƒƒS )z–
        Return the total count of keys that start with the specified prefix.

        Keyword arguments:
        prefix -- prefix of the key
        c                    s   g | ]	}|  ˆ ¡r|‘qS r   )r   )Ú.0r   ©Úprefixr   r   Ú
<listcomp>O   s    z4ConfigFile.get_count_with_prefix.<locals>.<listcomp>)Úlen)r   r"   r   r!   r   Úget_count_with_prefixH   s   z ConfigFile.get_count_with_prefixN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r%   r   r   r   r   r      s    r   )	r   ÚloggingÚ2cloudinit.sources.helpers.vmware.imc.config_sourcer   Ú	getLoggerr&   r   Údictr   r   r   r   r   Ú<module>   s
   
