def _get_auth_from_netrc(self, hostname):
        """Try to find login auth in ``~/.netrc``."""
        try:
            hostauth = netrc(self.NETRC_FILE)
        except IOError as cause:
            if cause.errno != errno.ENOENT:
                raise
            return None
        except NetrcParseError as cause:
            raise  # TODO: Map to common base class, so caller has to handle less error types?

        # Try to find specific `user@host` credentials first, then just `host`
        auth = hostauth.hosts.get('{}@{}'.format(self.user or getpass.getuser(), hostname), None)
        if not auth:
            auth = hostauth.hosts.get(hostname, None)

        if auth:
            username, account, password = auth  # pylint: disable=unpacking-non-sequence
            if username:
                self.user = username
            if password == 'base64':
                # support for password obfuscation, prevent "over the shoulder lookup"
                self.password = account.decode('base64')
            elif password:
                self.password = password

        return 'netrc'
def _get_auth_from_netrc ( self , hostname ) : try : hostauth = netrc ( self . NETRC_FILE ) except IOError as cause : if cause . errno != errno . ENOENT : raise return None except NetrcParseError as cause : raise auth = hostauth . hosts . get ( '{}@{}' . format ( self . user or getpass . getuser ( ) , hostname ) , None ) if not auth : auth = hostauth . hosts . get ( hostname , None ) if auth : username , account , password = auth if username : self . user = username if password == 'base64' : self . password = account . decode ( 'base64' ) elif password : self . password = password return 'netrc'
Try to find login auth in ``~/.netrc``.