]> granicus.if.org Git - python/commitdiff
asyncio, tulip issue 203: Add _FlowControlMixin.get_write_buffer_limits() method
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Aug 2014 22:22:28 +0000 (00:22 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Aug 2014 22:22:28 +0000 (00:22 +0200)
Doc/library/asyncio-protocol.rst
Lib/asyncio/transports.py
Lib/test/test_asyncio/test_transports.py

index 952ab690f2f8276a088dd0b0ce2a8e31beaef330..92b055a7b5672592361824fed234bbfbc5039f8e 100644 (file)
@@ -121,6 +121,16 @@ WriteTransport
 
       Return the current size of the output buffer used by the transport.
 
+   .. method:: get_write_buffer_limits()
+
+      Get the *high*- and *low*-water limits for write flow control. Return a
+      tuple ``(low, high)`` where *low* and *high* are positive number of
+      bytes.
+
+      Use :meth:`set_write_buffer_limits` to set the limits.
+
+      .. versionadded:: 3.4.2
+
    .. method:: set_write_buffer_limits(high=None, low=None)
 
       Set the *high*- and *low*-water limits for write flow control.
@@ -141,6 +151,8 @@ WriteTransport
       reduces opportunities for doing I/O and computation
       concurrently.
 
+      Use :meth:`get_write_buffer_limits` to get the limits.
+
    .. method:: write(data)
 
       Write some *data* bytes to the transport.
index 5f674f99d773f2a09252c7a27de89ab0e6dc318b..3caf853f9ebc49ffdb7182c77c2dcbebd8de3b9c 100644 (file)
@@ -273,6 +273,9 @@ class _FlowControlMixin(Transport):
                     'protocol': self._protocol,
                 })
 
+    def get_write_buffer_limits(self):
+        return (self._low_water, self._high_water)
+
     def _set_write_buffer_limits(self, high=None, low=None):
         if high is None:
             if low is None:
index cfbdf3e9bcca36096326c0afdd39e9293bb9c3c8..5be1b7bf895309b5e7952a399ad823d9e3565ffe 100644 (file)
@@ -79,9 +79,11 @@ class TransportTests(unittest.TestCase):
 
         transport.set_write_buffer_limits(high=1024, low=128)
         self.assertFalse(transport._protocol_paused)
+        self.assertEqual(transport.get_write_buffer_limits(), (128, 1024))
 
         transport.set_write_buffer_limits(high=256, low=128)
         self.assertTrue(transport._protocol_paused)
+        self.assertEqual(transport.get_write_buffer_limits(), (128, 256))
 
 
 if __name__ == '__main__':