3 0Q=jS;ã@sBdZddlZddlZddlZddlZddlmZmZddlm Z m Z yddl m Z m Z Wn$ek r|ddlm Z m Z YnXddlZejddd�Zeed ƒs¦eje_ejZd9d:d;dd?d@dAdBdCdDdEddd d!gfd"œZd#dd$gZGd%d&„d&ƒZGd'd(„d(ƒZd)d*„Zd+d,„Zd-d.„ZdFd0d1„ZdGd2d3„ZdHd4d5„ZdId7d8„Z dS)Jzj This module includes the Config and Up2date Config classes use by the up2date agent to hold config info. éN)Úidn_ascii_to_punyÚidn_puny_to_unicode)ÚustrÚsstr)ÚurlsplitÚ urlunsplitzrhn-client-toolsT)ZfallbackÚugettextúUse a HTTP ProxyúRemote server URLú)https://xmlrpc.cln.cloudlinux.com/XMLRPC/ú&Remote server URL for access over IPv6ú.https://ipv6.xmlrpc.cln.cloudlinux.com/XMLRPC/úMirror list URLú>https://repo.cloudlinux.com/cloudlinux/mirrorlists/cln-mirrorsú#Whether or not debugging is enabledúLocation of system idú/etc/sysconfig/rhn/systemidú4Override the automatically determined system versionÚú;HTTP proxy in host:port format, e.g. squid.example.com:3128ú'The username for an authenticated proxyú.The password to use for an authenticated proxyú$To use an authenticated proxy or notúBNumber of attempts to make at network connections before giving upéú)The CA cert used to verify the ssl serverú'/usr/share/rhn/CLN-ORG-TRUSTED-SSL-CERTzDConfig options that can not be overwritten by a config update actionÚ sslCACertÚ serverURLÚdisallowConfChanges)Z enableProxyrÚ serverURLipv6Z mirrorURLÚdebugÚ systemIdPathZversionOverrideÚ httpProxyÚ proxyUserÚ proxyPasswordZenableProxyAuthZnetworkRetriesrrr"ZtmpDirc@sleZdZdZddd„Zddd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„ZdS)Ú ConfigFilez;class for handling persistent config options for the clientNcCsi|_||_|jr|jƒdS)N)ÚdictÚfileNameÚload)ÚselfÚfilename©r,ú/usr/lib/python3.6/config.pyÚ__init__BszConfigFile.__init__c CsÜ|r ||_|jdkrdStj|jtjƒs,dSt|jdƒ}d}�x�|jƒD�]‚}|jdƒdkr^qH||jƒ}|spqH|ddkr�|dd…jƒ}qHnd}|jddƒ}t |ƒdkr®qH|djƒ}t |djƒƒ}d}|jd ƒ} | dkrô|d| …}|}d}|�rx|jd ƒ} |dk�r"t |j t jƒƒƒ}nVt | ƒdk�rVy t|ƒ}Wntk �rRYnXn"| ddk�rjg}nd d„| Dƒ}||f} ||jk�rÂ|j|} |dk �r¬|| df} |dk �rÂ| d|f} | |j|<qHW|jƒdS)NÚrrú#rrú\ú=éz [comment]ú;r$r%cSsg|]}|jƒr|jƒ‘qSr,)Ústrip)Ú.0Úvalr,r,r-ú ƒsz#ConfigFile.load..éÿÿÿÿr9r9)r$r%)r(ÚosÚaccessÚR_OKÚopenÚ readlinesÚfindr5ÚsplitÚlenrrÚencodeÚlocaleÚgetpreferredencodingÚintÚ ValueErrorr'Úclose) r*r+ÚfZ multilineÚliner@ÚkeyÚvalueÚcommentÚposÚvaluesZnewvalr,r,r-r)Hsd                  zConfigFile.loadc Cs|jdkrdStj|jtjƒsTtjtjj|jƒtjƒsTttdtjj|jƒƒƒdSx~|jj ƒD]p}|j|\}}t |ƒt gƒkr†|n|g}xB||gt |ƒD].}dt |ƒksºdt |ƒkržt d||jfƒ‚qžWq`Wtj|jdtjtjBtjBtjBtjBdƒ}ytj|dƒtj|dƒ}Wn"tk �r@tj|ƒ‚YnX|jdƒ|jd ƒ|jd ƒx”|jj ƒD]†}|j|\} } |jtd || fƒƒt | ƒt gƒk�r¬| g} |tk�rÄttjj| ƒ} |jtd |d jtt | ƒƒfƒƒ|jdƒ�qlW|jƒtj|jd|jƒdS)Nz%s was not foundÚ ú z[refusing to write config option %r to %s: a key, comment, or value contains a CR/LF newlinez.newi€ÚwzI# Automatically generated Red Hat Update Agent config file, do not edit. z# Format: 1.0 rz%s[comment]=%s z%s=%s r4)r(r:r;r<ÚpathÚdirnameÚprintÚ_r'ÚkeysÚtypeÚlistÚstrrFr=ÚO_WRONLYÚO_CREATÚO_TRUNCÚ O_NOFOLLOWÚ O_CLOEXECÚfchmodÚfdopenÚ ExceptionrGÚwriterÚ FileOptionsÚmapÚabspathÚjoinÚrename) r*Z_keyZ_commentZ_valueZ_valuesZ_fieldÚfdrHrJrLrKr,r,r-Úsave�sL         "zConfigFile.savecCs ||jkS)N)r')r*Únamer,r,r-Ú __contains__ÒszConfigFile.__contains__cCs||kS)Nr,)r*rjr,r,r-Úhas_keyÕszConfigFile.has_keycCs |jjƒS)N)r'rV)r*r,r,r-rVÙszConfigFile.keyscCsdd„|jjƒDƒS)NcSsg|] }|d‘qS)rr,)r6Úar,r,r-r8Ýsz%ConfigFile.values..)r'rN)r*r,r,r-rNÜszConfigFile.valuescCs|jj|ƒdS)N)r'Úupdate)r*r'r,r,r-rnßszConfigFile.updatecCs||jkr|j|dSdS)Nr)r')r*rjr,r,r-Ú __getitem__äs zConfigFile.__getitem__cCs0||jkr|j|}nd}|d|f|j|<dS)Nr)NN)r')r*rjrKr7r,r,r-Ú __setitem__és  zConfigFile.__setitem__cCs||jkr|j|dSdS)Nrr)r')r*rjr,r,r-Úinfoñs zConfigFile.info)N)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r.r)rirkrlrVrNrnrorprqr,r,r,r-r&?s  HBr&c@sveZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„ZdS)ÚConfigNcCs.tƒ|_|jjtƒ|r$|jj|ƒi|_dS)N)r&ÚstoredrnÚDefaultsr)Úruntime)r*r+r,r,r-r.ús   zConfig.__init__cCs ||jkrdS||jkrdSdS)NTF)ryrw)r*rjr,r,r-rks   zConfig.__contains__cCs||kS)Nr,)r*rjr,r,r-rl szConfig.has_keycCs8t|jjƒƒ}x$|jjƒD]}||kr|j|ƒqW|S)N)rXryrVrwÚappend)r*ÚretÚkr,r,r-rVs z Config.keyscCs*g}x |jƒD]}|j|j|ƒƒqW|S)N)rVrzro)r*r{r|r,r,r-rNsz Config.valuescCs.g}x$|jƒD]}|j||j|ƒfƒqW|S)N)rVrzro)r*r{r|r,r,r-Úitemssz Config.itemscCs t|jƒƒS)N)rArV)r*r,r,r-Ú__len__!szConfig.__len__cCs||j|<dS)N)ry)r*rjrKr,r,r-rp$szConfig.__setitem__cCs,||jkr|j|S||jkr(|j|SdS)N)ryrw)r*rjr,r,r-ro(s     zConfig.__getitem__cCs |jj|ƒS)N)rwrq)r*rjr,r,r-rq1sz Config.infocCs|jjƒdS)N)rwri)r*r,r,r-ri4sz Config.savecCs8|jj|ƒx&|jjƒD]}||jkr(q|j|=qWdS)N)rwr)rVry)r*r+r|r,r,r-r)7s   z Config.loadcCs ||j|<||jkr|j|=dS)N)rwry)r*rjrKr,r,r-ÚsetAs  z Config.set)N)rrrsrtr.rkrlrVrNr}r~rprorqrir)rr,r,r,r-rvùs   rvcCs^tƒ}d}|d}|rZ|dd…dkr2|dd…}|jdƒ}tt|dƒƒ|d<dj|ƒ}|S)zkreturns proxy string in format hostname:port hostname is converted to Punycode (RFC3492) if needed Nr#ézhttp://ú:r)ÚinitUp2dateConfigr@rYrrf)ÚcfgÚproxyZ proxyHostÚpartsr,r,r-ÚgetProxySettingHs   r†cCs:t|ƒ}tt|dtt|dƒƒ|d|d|dfƒƒS)z=returns url where hostname is converted to Punycode (RFC3492)rrr3éé)rrrrr)ZurlÚsr,r,r-Úconvert_url_to_punyZsrŠcCs&t|tƒrdd„|DƒSt|ƒgSdS)zç Internal function to process server URL to Punycode format. Processes both single URLs and lists of URLs. :param serverUrl: URL or list of URLs to process. :return: List of processed URLs in Punycode format. cSsg|] }t|ƒ‘qSr,)rŠ)r6Úir,r,r-r8jsz$processServerURL..N)Ú isinstancerXrŠ)Z serverUrlr,r,r-ÚprocessServerURL`s r�FcCs^tƒ}t|dƒ}t|dƒ}||f}||f}|r6|Sddlm}|jƒ}|dkrZ|rZ|S|S)aû Return a pair of server URLs (primary and fallback) based on the preferred interface. :param registration: If True, it indicates that the URLs are being fetched for registration purposes. If that is the case, the function will always use IPv4 URLs with IPv6 as fallback, regardless of the preferred_interface setting. Assumed false by default, expected to be specified explicitly when needed. :return: Pair of server URL configs, first is the primary, second is the fallback. rr r)Ú up2dateAuthZIPv6)r‚r�Zup2date_clientrŽZgetPreferredInterface)Ú registrationrƒZipv4_urlZipv6_urlZipv4_primary_pairZipv6_primary_pairrŽZpreferred_interfacer,r,r-ÚgetServerURLPairos     r�cCst|d�dS)az Return the primary server URL from config based on preferred_interface. If preferred_interface=IPv6 in system_id, returns serverURLipv6 if available. Otherwise returns normal serverURL. Note: the config may have one value or a list of values, but this function always returns a list. :return: List of server URLs with hostnames converted to Punycode. )r�r)r�)r�r,r,r-Ú getServerURL–s r‘cCst|d�dS)zñ Determine the fallback server URL from system_id. The fallback server URL is the one that is *not* set as preferred_interface. If preferred_interface is IPv6, it returns serverURL (i.e. IPv4 host), otherwise serverURLipv6. )r�r)r�)r�r,r,r-ÚgetFallbackServerURL£sr’ú/etc/sysconfig/rhn/up2datec CsPytWntk r daYnXtdkrLt|ƒadtd<tjjƒrLdtd<tS)z sV ;O '