B €/g^¾ã@sXdZddlZddlZddlZddgZGdd„deƒZGdd„dƒZedkrTe eƒƒdS)z-An object-oriented interface to .netrc files.éNÚnetrcÚNetrcParseErrorc@s"eZdZdZddd„Zdd„ZdS)rz5Exception raised on syntax errors in the .netrc file.NcCs"||_||_||_t ||¡dS)N)ÚfilenameÚlinenoÚmsgÚ ExceptionÚ__init__)Úselfrrr©r ú/usr/lib64/python3.7/netrc.pyr szNetrcParseError.__init__cCsd|j|j|jfS)Nz%s (%s, line %s))rrr)r r r r Ú__str__szNetrcParseError.__str__)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr r r r r r s c@s.eZdZd dd„Zdd„Zdd„Zdd „ZdS) rNc CsX|dk}|dkr&tj tj d¡d¡}i|_i|_t|ƒ}| |||¡WdQRXdS)Nú~z.netrc)ÚosÚpathÚjoinÚ expanduserÚhostsÚmacrosÚopenÚ_parse)r ÚfileÚ default_netrcÚfpr r r rs znetrc.__init__cCsÆt |¡}|jd7_|j dd¡|_x–|j}| ¡}}|sFPnº|ddkrv|j|kr,t|ƒdkr,|j ¡q,nŠ|dkrˆ| ¡}nx|dkr–d}nj|dkrî| ¡}g|j |<d |_ x2|j ¡} | rÎ| d krÖd |_ P|j |  | ¡q¸Wq,nt d |||jƒ‚d} d} } i|j |<x¤| ¡}| d¡s8|d kr|| r\| | | f|j |<| |¡Pnt d||t|ƒf||jƒ‚q|dks|dkrœ| ¡} q|dkr²| ¡} q|dkr¦tjdkrœ|rœt | ¡¡} | jt ¡krzddl}y| | j¡d}Wn tk r(d| j}YnXy| t ¡¡d}Wn"tk rbdt ¡}YnXt d||f||jƒ‚| jtjtjB@rœt d||jƒ‚| ¡} nt d|||jƒ‚qWq,WdS)Nz !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ú#ÚréÚmachineÚdefaultÚmacdefz Ú z zbad toplevel token %r>rr!r"r z&malformed %s entry %s terminated by %sÚloginÚuserÚaccountÚpasswordÚposixzuid %sz9~/.netrc file owner (%s) does not match current user (%s)zY~/.netrc access too permissive: access permissions must restrict access to only the ownerzbad follower token %r)ÚshlexZ wordcharsZ commentersÚreplacerZ get_tokenÚlenZinstreamÚreadlinerZ whitespaceÚappendrrÚ startswithZ push_tokenÚreprrÚnameÚfstatÚfilenoÚst_uidÚgetuidÚpwdÚgetpwuidÚKeyErrorÚst_modeÚstatÚS_IRWXGÚS_IRWXO)r rrrZlexerZ saved_linenoZtoplevelZttZ entrynameÚliner$r&r'Zpropr5Zfownerr%r r r r s                   z netrc._parsecCs0||jkr|j|Sd|jkr(|jdSdSdS)z8Return a (user, account, password) tuple for given host.r!N)r)r Úhostr r r Úauthenticatorsqs     znetrc.authenticatorscCs¸d}xf|j ¡D]X}|j|}|d|›d|d›d7}|drT|d|d›d7}|d|d ›d7}qWxF|j ¡D]8}|d |›d7}x|j|D] }||7}q˜W|d7}qxW|S) z3Dump the class data in the format of a .netrc file.rzmachine z login rr#rz account z password ézmacdef )rÚkeysr)r Zrepr=ZattrsZmacror<r r r Ú__repr__zs   znetrc.__repr__)N)r rrrrr>rAr r r r rs Q Ú__main__) rrr)r9Ú__all__rrrr Úprintr r r r Ús  t