summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-11 20:52:21 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-11 20:52:21 (GMT)
commitb28dbac86d3c8ccde7d16c4f2de471eb53a6bffe (patch)
tree0fa5020d6f64ce59dde286c68157ad7ca99ec88e /Lib/asyncio
parent7aee3ecd57c5d7a455420dd514206e239c7dbc39 (diff)
downloadcpython-b28dbac86d3c8ccde7d16c4f2de471eb53a6bffe.zip
cpython-b28dbac86d3c8ccde7d16c4f2de471eb53a6bffe.tar.gz
cpython-b28dbac86d3c8ccde7d16c4f2de471eb53a6bffe.tar.bz2
asyncio, Tulip issue 180: Make Server attributes and methods private
- loop, waiters and active_count attributes are now private - attach(), detach() and wakeup() methods are now private The sockets attribute remains public.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py41
-rw-r--r--Lib/asyncio/proactor_events.py4
-rw-r--r--Lib/asyncio/selector_events.py4
3 files changed, 25 insertions, 24 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 3951fb7..10996d2 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -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
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index fa24795..d0b601d 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -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):
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 7b364ad..b965046 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -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):