o x[h¤ ã@s*ddlmZddlmZGdd„dƒZdS)é)ÚStringIO)Ú chop_commentc@sDeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)Ú HostsConfcCs||_d|_dS©N)Ú_textÚ _contents)ÚselfÚtext©r úA/usr/lib/python3/dist-packages/cloudinit/distros/parsers/hosts.pyÚ__init__s zHostsConf.__init__cCs |jdur| |j¡|_dSdSr)rÚ_parser)rr r r Úparses ÿzHostsConf.parsecCsV| ¡g}|jD]\}}|dkr(|\}}t|ƒr(|d|kr(| |dd…¡q |S)NÚoptionré)rrÚlenÚappend)rÚipÚoptionsÚ line_typeÚ componentsÚpiecesÚ_tailr r r Ú get_entrys€zHostsConf.get_entrycCsv| ¡g}|jD],\}}|dkr| ||f¡q |\}}t|ƒr(|d|kr(q t|ƒr5| |t|ƒf¡q ||_dS)Nrr)rrrrÚlist)rrÚ n_entriesrrrrr r r Ú del_entries"s€ zHostsConf.del_entriescGs,| ¡|j d||gt|ƒdff¡dS)NrÚ)rrrr)rrÚcanonical_hostnameÚaliasesr r r Ú add_entry1sÿzHostsConf.add_entrycCsxg}| ¡D]3}t| ¡ƒs| d|gf¡qt| ¡dƒ\}}t|ƒs-| d|gf¡q| d| d¡|gf¡q|S)NÚblankú#Ú all_commentr)Ú splitlinesrÚstriprrÚsplit)rÚcontentsÚentriesÚlineÚheadÚtailr r r r 7s  zHostsConf._parsecCs˜| ¡tƒ}|jD]=\}}|dkr| d|d¡q |dkr*| d|d¡q |dkrG|\}}dd„|Dƒ}d |¡}| d ||f¡q | ¡S) Nr!z%s rr#rcSsg|]}t|ƒ‘qSr )Ústr)Ú.0Úpr r r Ú Nsz%HostsConf.__str__..ú z%s%s )rrrÚwriteÚjoinÚgetvalue)rr'rrrr+r r r Ú__str__Ds €zHostsConf.__str__N) Ú__name__Ú __module__Ú __qualname__r rrrr r r4r r r r rs  rN)ÚiorÚcloudinit.distros.parsersrrr r r r Ús