]> granicus.if.org Git - python/commitdiff
asyncio, Tulip issue 180: Make Server attributes and methods private
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Jul 2014 20:52:21 +0000 (22:52 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Jul 2014 20:52:21 +0000 (22:52 +0200)
- loop, waiters and active_count attributes are now private
- attach(), detach() and wakeup() methods are now private

The sockets attribute remains public.

Lib/asyncio/base_events.py
Lib/asyncio/proactor_events.py
Lib/asyncio/selector_events.py

index 3951fb75b47bc98cadbae9aa1f90c84b5371ff8f..10996d23a18afd720aeb77f367e7bb4286982d2e 100644 (file)
@@ -89,43 +89,44 @@ def _raise_stop_error(*args):
 class Server(events.AbstractServer):
 
     def __init__(self, loop, sockets):
-        self.loop = loop
+        self._loop = loop
         self.sockets = sockets
-        self.active_count = 0
-        self.waiters = []
+        self._active_count = 0
+        self._waiters = []
 
-    def attach(self, transport):
+    def _attach(self):
         assert self.sockets is not None
-        self.active_count += 1
+        self._active_count += 1
 
-    def detach(self, transport):
-        assert self.active_count > 0
-        self.active_count -= 1
-        if self.active_count == 0 and self.sockets is None:
+    def _detach(self):
+        assert self._active_count > 0
+        self._active_count -= 1
+        if self._active_count == 0 and self.sockets is None:
             self._wakeup()
 
     def close(self):
         sockets = self.sockets
-        if sockets is not None:
-            self.sockets = None
-            for sock in sockets:
-                self.loop._stop_serving(sock)
-            if self.active_count == 0:
-                self._wakeup()
+        if sockets is None:
+            return
+        self.sockets = None
+        for sock in sockets:
+            self._loop._stop_serving(sock)
+        if self._active_count == 0:
+            self._wakeup()
 
     def _wakeup(self):
-        waiters = self.waiters
-        self.waiters = None
+        waiters = self._waiters
+        self._waiters = None
         for waiter in waiters:
             if not waiter.done():
                 waiter.set_result(waiter)
 
     @coroutine
     def wait_closed(self):
-        if self.sockets is None or self.waiters is None:
+        if self.sockets is None or self._waiters is None:
             return
-        waiter = futures.Future(loop=self.loop)
-        self.waiters.append(waiter)
+        waiter = futures.Future(loop=self._loop)
+        self._waiters.append(waiter)
         yield from waiter
 
 
index fa2479598dafe0797ce80f5059b2dc6a4c185d72..d0b601d7c0b148dab01886bcc0e4bb194c46f29d 100644 (file)
@@ -35,7 +35,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
         self._closing = False  # Set when close() called.
         self._eof_written = False
         if self._server is not None:
-            self._server.attach(self)
+            self._server._attach()
         self._loop.call_soon(self._protocol.connection_made, self)
         if waiter is not None:
             # wait until protocol.connection_made() has been called
@@ -91,7 +91,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
             self._sock.close()
             server = self._server
             if server is not None:
-                server.detach(self)
+                server._detach()
                 self._server = None
 
     def get_write_buffer_size(self):
index 7b364ad3b7c94697f274a16bac7bfa7cf2728b47..b965046870c230fbca1e93891525d4d1304ba02d 100644 (file)
@@ -417,7 +417,7 @@ class _SelectorTransport(transports._FlowControlMixin,
         self._conn_lost = 0  # Set when call to connection_lost scheduled.
         self._closing = False  # Set when close() called.
         if self._server is not None:
-            self._server.attach(self)
+            self._server._attach()
 
     def abort(self):
         self._force_close(None)
@@ -464,7 +464,7 @@ class _SelectorTransport(transports._FlowControlMixin,
             self._loop = None
             server = self._server
             if server is not None:
-                server.detach(self)
+                server._detach()
                 self._server = None
 
     def get_write_buffer_size(self):