r46783 - use symbolic names so it's clear what's going on

glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: glyph
Date: Sat Feb 13 17:32:25 2016
New Revision: 46783

Modified:
   branches/hostname-endpoint-8014/twisted/internet/endpoints.py
   branches/hostname-endpoint-8014/twisted/internet/test/test_endpoints.py

Log:
use symbolic names so it's clear what's going on

Modified: branches/hostname-endpoint-8014/twisted/internet/endpoints.py
==============================================================================
--- branches/hostname-endpoint-8014/twisted/internet/endpoints.py	(original)
+++ branches/hostname-endpoint-8014/twisted/internet/endpoints.py	Sat Feb 13 17:32:25 2016
@@ -642,16 +642,16 @@
 
     @ivar _deferToThread: A hook used for testing deferToThread.
 
-    @cvar _DEFAULT_TIME_BETWEEN_ATTEMPTS: The default time to use between
-        attempts, in seconds, when no C{timeBetweenAttempts} is given to
+    @cvar _DEFAULT_ATTEMPT_DELAY: The default time to use between attempts, in
+        seconds, when no C{attemptDelay} is given to
         L{HostnameEndpoint.__init__}.
     """
     _getaddrinfo = staticmethod(socket.getaddrinfo)
     _deferToThread = staticmethod(threads.deferToThread)
-    _DEFAULT_TIME_BETWEEN_ATTEMPTS = 0.3
+    _DEFAULT_ATTEMPT_DELAY = 0.3
 
     def __init__(self, reactor, host, port, timeout=30, bindAddress=None,
-                 timeBetweenAttempts=None):
+                 attemptDelay=None):
         """
         Create a L{HostnameEndpoint}.
 
@@ -672,9 +672,9 @@
             the connections from.
         @type bindAddress: L{bytes}
 
-        @param timeBetweenAttempts: The number of seconds to wait between
+        @param attemptDelay: The number of seconds to delay between connection
             attempts.
-        @type timeBetweenAttempts: L{float}
+        @type attemptDelay: L{float}
 
         @see: L{twisted.internet.interfaces.IReactorTCP.connectTCP}
         """
@@ -683,9 +683,9 @@
         self._port = port
         self._timeout = timeout
         self._bindAddress = bindAddress
-        if timeBetweenAttempts is None:
-            self._timeBetweenAttempts = self._DEFAULT_TIME_BETWEEN_ATTEMPTS
-        self._timeBetweenAttempts = timeBetweenAttempts
+        if attemptDelay is None:
+            attemptDelay = self._DEFAULT_ATTEMPT_DELAY
+        self._attemptDelay = attemptDelay
 
 
     def connect(self, protocolFactory):
@@ -728,9 +728,9 @@
         def startConnectionAttempts(endpoints):
             """
             Given a sequence of endpoints obtained via name resolution, start
-            connecting to a new one every C{self._timeBetweenAttempts} seconds
-            until one of the connections succeeds, all of them fail, or the
-            attempt is cancelled.
+            connecting to a new one every C{self._attemptDelay} seconds until
+            one of the connections succeeds, all of them fail, or the attempt
+            is cancelled.
 
             @param endpoints: an iterable of all the endpoints we might try to
                 connect to, as determined by name resolution.
@@ -781,7 +781,8 @@
                     checkDone()
 
             iterateEndpoint.clock = self._reactor
-            iterateEndpoint.start(self._timeBetweenAttempts)
+            iterateEndpoint.start(self._attemptDelay)
+
             @winner.addBoth
             def cancelRemainingPending(result):
                 checkDone.completed = True

Modified: branches/hostname-endpoint-8014/twisted/internet/test/test_endpoints.py
==============================================================================
--- branches/hostname-endpoint-8014/twisted/internet/test/test_endpoints.py	(original)
+++ branches/hostname-endpoint-8014/twisted/internet/test/test_endpoints.py	Sat Feb 13 17:32:25 2016
@@ -1698,7 +1698,9 @@
         connection attempts have been initiated will cause it to be errbacked
         with a L{ConnectingCancelledError} exception.
         """
-        self.test_endpointConnectingCancelled(advance=0.31)
+        oneBetween = endpoints.HostnameEndpoint._DEFAULT_ATTEMPT_DELAY
+        advance = oneBetween + (oneBetween / 2.0)
+        self.test_endpointConnectingCancelled(advance=advance)
 
 
     def test_endpointConnectFailure(self):
@@ -1718,7 +1720,7 @@
             mreactor, clientFactory)
 
         d = ep.connect(clientFactory)
-        mreactor.advance(0.3)
+        mreactor.advance(endpoints.HostnameEndpoint._DEFAULT_ATTEMPT_DELAY)
         self.assertEqual(self.failureResultOf(d).value, expectedError)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.