Yft@s|dZddlZddlZddlZddgZGdddeZGdddZedkrxe edS)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/python35/lib64/python3.5/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}|dkrYy tjjtjdd}Wntk rXtdYnXi|_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}}|s\Pn|ddkr|j|kr9t|dkr9|jjq9n|dkr|j}n|dkrd}n|dkrK|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#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._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]u}|j|}|d|dt|dd}|dro|dt|d}|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 )rkeysr1r)r Zrepr>ZattrsZmacror=r r r __repr__}s $  znetrc.__repr__)r rrrrr?rBr r r r rs  Q __main__) rrr+r:__all__rrrr printr r r r s $  w