1. Stefan Schwarzer
  2. connection


Stefan Schwarzer  committed 7c0bcfd

Changed `was_sent` to `sent` as suggested on Python mailing list.

  • Participants
  • Parent commits 3cdfe24
  • Branches default

Comments (0)

Files changed (3)

File connection.py

View file
-    def was_sent(self, timeout=None):
+    def sent(self, timeout=None):
         """Return `True` if sending was successful, `False` if it was
         not (yet) successful.

File examples.py

View file
 ### Combine sent requests and their results (whether they were
 ### successful). Each tuple is going to be (request_data, result).
 put_results = [conn.put_bytes(request) for request in requests]
-# A result will be `None` if `was_sent` timed out.
-results = [(request, put_result.was_sent(timeout=1.0))
+# A result will be `None` if `sent` timed out.
+results = [(request, put_result.sent(timeout=1.0))
            for request in requests]
 put_result = conn.put_bytes(data)
 # It would be better to have this fail immediately as soon as the
 # connection fails. Maybe even raise an exception from `wait`?
-if not put_result.was_sent(10.0) and conn.failed:
+if not put_result.sent(10.0) and conn.failed:
     print "this will never succeed"
 # A way to stop `wait` would be to set the event from the `Connection`
 ### How to have a "common" timeout for a bunch of send results.
-def common_was_sent(put_results, timeout):
+def common_sent(put_results, timeout):
     start_time = time.time()
     while True:
-        results = [put_result.was_sent(timeout=0.0)
+        results = [put_result.sent(timeout=0.0)
                    for put_result in put_results]
         if results.count(False) == 0:
             # Everything has been sent.
     def __init__(self, put_results):
         self._put_results = put_results
-    def was_sent(self, timeout=None):
+    def sent(self, timeout=None):
         """Return `True` if all messages have been sent within
         timeout `timeout` (in seconds). By default, the timeout
         is `None` which means to wait forever.
         start_time = time.time()
         remaining_timeout = timeout
         for index, put_result in enumerate(self._put_results):
-            if not put_result.was_sent(remaining_timeout):
+            if not put_result.sent(remaining_timeout):
                 return False
             if index == len(self._put_results):
                 return True
     def wait(self, timeout=None):
         # Ignore return value.
-        self.was_sent(timeout)
+        self.sent(timeout)
 combined_put_result = CombinedPutResult([put_result1, put_result2])
-if combined_put_result.was_sent(10.0):
+if combined_put_result.sent(10.0):
     print "Everything was sent after 10 seconds."

File test_connection.py

View file
         put_result = self.conn.put_bytes(REQUEST)
         # Blocks, but once the actual sending was tried, the results
         # are available immediately.
-        self.assertEqual(put_result.was_sent(), True)
+        self.assertEqual(put_result.sent(), True)
     def test_put_and_get_bytes(self):
         conn = self.conn
     def tearDown(self):
-    def test_put_bytes_was_sent_timeout(self):
+    def test_put_bytes_sent_timeout(self):
         put_result = self.conn.put_bytes(REQUEST)
-        self.assertEqual(put_result.was_sent(timeout=0.1), False)
+        self.assertEqual(put_result.sent(timeout=0.1), False)
     def test_put_bytes_wait_timeout(self):
         put_result = self.conn.put_bytes(REQUEST)
-        self.assertEqual(put_result.was_sent(timeout=0.1), False)
+        self.assertEqual(put_result.sent(timeout=0.1), False)
 # Helper class to test overridden `process_get_result`.