irkerd: Replace 'fallback' global with local 'nick_needs_number'
authorW. Trevor King <wking@tremily.us>
Fri, 7 Mar 2014 04:21:09 +0000 (20:21 -0800)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 11 Mar 2014 04:44:34 +0000 (00:44 -0400)
Using the new kwargs handling to pass the data through Irker() down to
Connection().

irkerd

diff --git a/irkerd b/irkerd
index 824dae6fdc70ace1b659b50e6658d54db82bfcb9..6d068ad371906bf1f6200b8d1b5aff7b1261c4fd 100755 (executable)
--- a/irkerd
+++ b/irkerd
@@ -380,9 +380,10 @@ def is_channel(string):
     return string and string[0] in "#&+!"
 
 class Connection:
-    def __init__(self, irker, target, **kwargs):
+    def __init__(self, irker, target, nick_needs_number=False, **kwargs):
         self.irker = irker
         self.target = target
+        self.nick_needs_number = nick_needs_number
         self.kwargs = kwargs
         self.nick_trial = None
         self.connection = None
@@ -398,7 +399,7 @@ class Connection:
         "Return a name for the nth server connection."
         if n is None:
             n = self.nick_trial
-        if fallback:
+        if self.nick_needs_number:
             return (namestyle % n)
         else:
             return namestyle
@@ -414,7 +415,7 @@ class Connection:
     def handle_badnick(self):
         "The server says our nick is ill-formed or has a conflict."
         LOG.info("nick %s rejected" % self.nickname())
-        if fallback:
+        if self.nick_needs_number:
             # Randomness prevents a malicious user or bot from
             # anticipating the next trial name in order to block us
             # from completing the handshake.
@@ -925,8 +926,9 @@ if __name__ == '__main__':
     if log_level:
         LOG.setLevel(log_level)
 
-    fallback = re.search("%.*d", namestyle)
-    irker = Irker()
+    irker = Irker(
+        nick_needs_number=re.search("%.*d", namestyle),
+        )
     LOG.info("irkerd version %s" % version)
     if immediate:
         irker.irc.add_event_handler("quit", lambda _c, _e: sys.exit(0))