From 2269d334bc9d3ae1c0de8229875b068e4cb29ac9 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 26 Sep 2007 18:15:39 -0300 Subject: [PATCH 1/1] Make Host iterable so it can be used as a sequence when serializing. --- services/dhcp/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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. -- 2.43.0