From: Leandro Lucarella Date: Wed, 26 Sep 2007 21:15:39 +0000 (-0300) Subject: Make Host iterable so it can be used as a sequence when serializing. X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/2269d334bc9d3ae1c0de8229875b068e4cb29ac9?ds=sidebyside;hp=d6d7ebf986963fbf1d960730b7371ee5bbbf2952 Make Host iterable so it can be used as a sequence when serializing. --- diff --git a/services/dhcp/__init__.py b/services/dhcp/__init__.py index 1df0062..618f702 100644 --- a/services/dhcp/__init__.py +++ b/services/dhcp/__init__.py @@ -111,6 +111,12 @@ class Host: self.ip = ip self.mac = mac + def __iter__(self): + r"Iterate over a host." + yield self.name + yield self.ip + yield self.mac + class HostHandler: r"""HostHandler(hosts) -> HostHandler instance :: Handle a list of hosts. @@ -157,7 +163,7 @@ class HostHandler: if not name in self.hosts: raise HostNotFoundError(name) h = self.hosts[name] - return '%s,%s,%s' % (h.name, h.ip, h.mac) + return ','.join(list(h)) @handler def list(self): @@ -175,7 +181,7 @@ class HostHandler: hostname,ip,mac """ hosts = self.hosts.values() - return '\n'.join('%s,%s,%s' % (h.name, h.ip, h.mac) for h in hosts) + return '\n'.join(','.join(h) for h in hosts) class DhcpHandler: r"""DhcpHandler([pickle_dir[, config_dir]]) -> DhcpHandler instance.