1[tip] 50259ebef9c5 2011-03-28 22:55 +0200 saffroy support more than one entry per host diff -r 2a976714a5a8 -r 50259ebef9c5 netrc.py --- a/netrc.py Sat Mar 12 01:44:42 2011 +0100 +++ b/netrc.py Mon Mar 28 22:55:58 2011 +0200 @@ -58,13 +58,15 @@ # We're looking at start of an entry for a named machine or default. login = '' account = password = None - self.hosts[entryname] = {} + if entryname not in self.hosts: + self.hosts[entryname] = [] while 1: tt = lexer.get_token() if (tt=='' or tt == 'machine' or tt == 'default' or tt =='macdef'): if password: - self.hosts[entryname] = (login, account, password) + a = (login, account, password) + self.hosts[entryname].append(a) lexer.push_token(tt) break else: @@ -82,12 +84,18 @@ raise NetrcParseError("bad follower token %r" % tt, file, lexer.lineno) - def authenticators(self, host): + def authenticators(self, host, login=None): """Return a (user, account, password) tuple for given host.""" if host in self.hosts: - return self.hosts[host] + if login: + for a in self.hosts[host]: + if a[0] == login: + return a + return None + else: + return self.hosts[host][-1] elif 'default' in self.hosts: - return self.hosts['default'] + return self.hosts['default'][-1] else: return None @@ -95,11 +103,11 @@ """Dump the class data in the format of a .netrc file.""" rep = "" for host in self.hosts.keys(): - attrs = self.hosts[host] - rep = rep + "machine "+ host + "\n\tlogin " + repr(attrs[0]) + "\n" - if attrs[1]: - rep = rep + "account " + repr(attrs[1]) - rep = rep + "\tpassword " + repr(attrs[2]) + "\n" + for attrs in self.hosts[host]: + rep = rep + "machine "+ host + "\n\tlogin " + repr(attrs[0]) + "\n" + if attrs[1]: + rep = rep + "account " + repr(attrs[1]) + rep = rep + "\tpassword " + repr(attrs[2]) + "\n" for macro in self.macros.keys(): rep = rep + "macdef " + macro + "\n" for line in self.macros[macro]: