peerdb/tripe-newpeers.in (ConfigSection.items): Just return names.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 26 May 2018 13:47:06 +0000 (14:47 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 14 Jun 2018 11:50:38 +0000 (12:50 +0100)
It has to do a full `get' for each one anyway, which the caller can do
just as well if they actually want to.  Sometimes they don't, which
saves some effort.

peerdb/tripe-newpeers.in

index 304d34a..b8cf681 100644 (file)
@@ -287,9 +287,7 @@ class ConfigSection (object):
 
   def items(me, resolvep = True):
     """
-    Return a list of (NAME, VALUE) items in this section.
-
-    This extends the default method by handling the inheritance chain.
+    Yield a list of item names in the section.
     """
 
     ## Initialize for a depth-first walk of the inheritance graph.
@@ -308,12 +306,8 @@ class ConfigSection (object):
         if key == '@inherit': stack += value.replace(',', ' ').split()
         else: d[key] = None
 
-    ## Now collect the values for the known keys, one by one.
-    items = []
-    for key in d: items.append((key, me.get(key, resolvep)))
-
     ## And we're done.
-    return items
+    return d.iterkeys()
 
 class MyConfigParser (object):
   """
@@ -439,7 +433,8 @@ class MyConfigParser (object):
     resolve hostnames will fail!
     """
     for sec in me.sections():
-      for key, value in sec.items(resolvep = False):
+      for key in sec.items():
+        value = sec.get(key, resolvep = False)
         for match in RX_RESOLVE.finditer(value):
           me._resolver.prepare(match.group(1))
     me._resolver.run()
@@ -525,9 +520,9 @@ def output(conf, cdb):
       except MissingKeyException: pass
       else: cdb.add('U%s' % u)
     url = M.URLEncode(laxp = True, semip = True)
-    for key, value in sorted(sec.items(), key = lambda (k, v): k):
+    for key in sorted(sec.items()):
       if not key.startswith('@'):
-        url.encode(key, ' '.join(M.split(value)[0]))
+        url.encode(key, ' '.join(M.split(sec.get(key))[0]))
     cdb.add(label, url.result)
   cdb.add('%AUTO', ' '.join(auto))
   cdb.finish()