f ft@sdZddlZddlZddlZddgZGdddeZGdddZedkr{e endS)z-An object-oriented interface to .netrc files.NnetrcNetrcParseErrorc@s4eZdZdZddddZddZdS)rz5Exception raised on syntax errors in the .netrc file.NcCs/||_||_||_tj||dS)N)filenamelinenomsg Exception__init__)selfrrrr */opt/alt/python34/lib64/python3.4/netrc.pyr s   zNetrcParseError.__init__cCsd|j|j|jfS)Nz%s (%s, line %s))rrr)r r r r __str__szNetrcParseError.__str__)__name__ __module__ __qualname____doc__rr r r r r r s c@sCeZdZdddZddZddZdd ZdS) rNcCs|dk}|dkr\y tjjtjdd}Wq\tk rXtdYq\Xni|_i|_t|}|j |||WdQXdS)NHOMEz.netrcz'Could not find .netrc: $HOME is not set) ospathjoinenvironKeyErrorOSErrorhostsmacrosopen_parse)r file default_netrcfpr r r rs      znetrc.__init__cCstj|}|jd7_|jjdd|_xk|j}|j}}|s\Pn|ddkr|j|kr9t|dkr9|jjq9q9n|dkr|j}n|dkrd}n|dkrQ|j}g|j |?@[\]^_`{|}~#rmachinedefaultmacdefz  z zbad toplevel token %rz&malformed %s entry %s terminated by %sloginuseraccountpasswordposixzuid %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>r r$machinedefault)shlexZ wordcharsZ commentersreplacerZ get_tokenlenZinstreamreadlinerZ whitespaceappendrr startswithZ push_tokenreprrnamefstatfilenost_uidgetuidpwdgetpwuidrst_modestatS_IRWXGS_IRWXO)r rrrZlexerZ saved_linenoZtoplevelZttZ entrynameliner&r(r)Zpropr9Zfownerr'r r r r#s !                    z netrc._parsecCs<||jkr|j|Sd|jkr4|jdSdSdS)z8Return a (user, account, password) tuple for given host.r#N)r)r hostr r r authenticatorsts   znetrc.authenticatorscCsd}x|jjD]x}|j|}|d|dt|dd}|drr|dt|d}n|dt|d d}qWxU|jjD]D}|d |d}x|j|D]}||}qW|d}qW|S) z3Dump the class data in the format of a .netrc file.r zmachine z login rr%r!zaccount z password zmacdef )rkeysr3r)r Zrepr@attrsZmacror?r r r __repr__}s $  znetrc.__repr__)r rrrrrArEr r r r rs  Q __main__) rrr-r<__all__rrrr printr r r r s $  w