3 \4@sXdZddlZddlZddlZddgZGdddeZGdddZedkrTe edS)z-An object-oriented interface to .netrc files.NnetrcNetrcParseErrorc@s"eZdZdZdddZddZdS)rz5Exception raised on syntax errors in the .netrc file.NcCs"||_||_||_tj||dS)N)filenamelinenomsg Exception__init__)selfrrrr /usr/lib64/python3.6/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 ddZddZddZdd ZdS) rNcCsx|dk}|dkrFytjjtjdd}Wntk rDtdYnXi|_i|_t|}|j |||WdQRXdS)NHOMEz.netrcz'Could not find .netrc: $HOME is not set) ospathjoinenvironKeyErrorOSErrorhostsmacrosopen_parse)r file default_netrcfpr r r rs znetrc.__init__cCstj|}|jd7_|jjdd|_x|j}|j}}|sFPn|ddkrv|j|kr,t|dkr,|jjq,n|dkr|j}nz|dkrd}nl|dkr|j}g|j |<d |_ x4|jj} | s| d krd |_ P|j |j | qWq,nt d |||jd} d} } i|j |<x|j}|jds:|dkr~| r^| | | f|j |<|j|Pnt d ||t|f||jq|dks|dkr|j} q|dkr|j} q|dkrtjdkr|rtj|j} | jtjkr|ddl}y|j| jd}Wn tk r*d| j}YnXy|jtjd}Wn"tk rddtj}YnXt d||f||j| jtjtjB@rt d||j|j} nt d|||jqWq,WdS)Nz !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~#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$r"r#)shlexZ wordcharsZ commentersreplacerZ get_tokenlenZinstreamreadlinerZ whitespaceappendrr startswithZ push_tokenreprrnamefstatfilenost_uidgetuidpwdgetpwuidrst_modestatS_IRWXGS_IRWXO)r rrrZlexerZ saved_linenoZtoplevelZttZ entrynameliner&r(r)Zpropr7Zfownerr'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 authenticatorsts     znetrc.authenticatorscCsd}xf|jjD]X}|j|}|d|d|dd7}|drT|d|dd7}|d|d d7}qWxF|jjD]8}|d |d7}x|j|D] }||7}qW|d7}qxW|S) z3Dump the class data in the format of a .netrc file.r zmachine z login rr%r!z account z password zmacdef )rkeysr)r Zrepr>ZattrsZmacror=r r r __repr__}s   znetrc.__repr__)N)r rrrrr?rBr r r r rs Q __main__) rrr+r:__all__rrrr printr r r r s  w