diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-13 21:20:45 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-13 21:20:45 +0100 |
commit | 51342c3e61fa6e70cfce0351dc1f7ddae322f5e5 (patch) | |
tree | d3d339dfa22ffc85bcc3f10a25b9745fd74b4de7 | |
parent | bac726a629b2982bd17294f1386c0cdb74bad341 (diff) | |
download | trollius-51342c3e61fa6e70cfce0351dc1f7ddae322f5e5.tar.gz |
Change Return(): it now accepts more than 1 parameter
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | asyncio/base_events.py | 12 | ||||
-rw-r--r-- | asyncio/streams.py | 2 | ||||
-rw-r--r-- | asyncio/tasks.py | 11 | ||||
-rw-r--r-- | asyncio/windows_events.py | 2 | ||||
-rw-r--r-- | examples/cacheclt.py | 2 | ||||
-rw-r--r-- | examples/child_process.py | 2 | ||||
-rw-r--r-- | examples/crawl.py | 4 | ||||
-rw-r--r-- | examples/fetch3.py | 2 |
9 files changed, 24 insertions, 17 deletions
@@ -42,7 +42,7 @@ Differences between Trollius and Tulip * Trollius coroutines use "yield" and "raise Return(value)", whereas Tulip coroutines use "yield from" and "return". - "return x, y" must be converted to "raise Return((x, y))". + "return x, y" must be converted to "raise Return(x, y)". * On Python 2.7, asyncio.SSLContext has less features than the ssl.SSLContext of Python 3.3: no options, verify_mode cannot be modified (fixed to CERT_NONE), no set_default_verify_paths() method, no SNI, etc. The SSL @@ -129,6 +129,8 @@ Development version - Workaround bugs in the ssl module of Python older than 2.6.6 (ex: system python on Mac OS 10.6, Snow Leopard) - SSL support is now optional: don't fail if the ssl module is missing +- ``return x, y`` is now written ``raise Return(x, y)`` instead of + ``raise Return((x, y))`` 2014-01-08: version 0.1.2 diff --git a/asyncio/base_events.py b/asyncio/base_events.py index 795074c..dd444fb 100644 --- a/asyncio/base_events.py +++ b/asyncio/base_events.py @@ -388,7 +388,7 @@ class BaseEventLoop(events.AbstractEventLoop): transport = self._make_socket_transport(sock, protocol, waiter) yield waiter - raise tasks.Return((transport, protocol)) + raise tasks.Return(transport, protocol) @tasks.coroutine def create_datagram_endpoint(self, protocol_factory, @@ -456,7 +456,7 @@ class BaseEventLoop(events.AbstractEventLoop): protocol = protocol_factory() transport = self._make_datagram_transport(sock, protocol, r_addr) - raise tasks.Return((transport, protocol)) + raise tasks.Return(transport, protocol) @tasks.coroutine def create_server(self, protocol_factory, host=None, port=None, @@ -538,7 +538,7 @@ class BaseEventLoop(events.AbstractEventLoop): waiter = futures.Future(loop=self) transport = self._make_read_pipe_transport(pipe, protocol, waiter) yield waiter - raise tasks.Return((transport, protocol)) + raise tasks.Return(transport, protocol) @tasks.coroutine def connect_write_pipe(self, protocol_factory, pipe): @@ -546,7 +546,7 @@ class BaseEventLoop(events.AbstractEventLoop): waiter = futures.Future(loop=self) transport = self._make_write_pipe_transport(pipe, protocol, waiter) yield waiter - raise tasks.Return((transport, protocol)) + raise tasks.Return(transport, protocol) @tasks.coroutine def subprocess_shell(self, protocol_factory, cmd, stdin=subprocess.PIPE, @@ -559,7 +559,7 @@ class BaseEventLoop(events.AbstractEventLoop): protocol = protocol_factory() transport = yield self._make_subprocess_transport( protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs) - raise tasks.Return((transport, protocol)) + raise tasks.Return(transport, protocol) @tasks.coroutine def subprocess_exec(self, protocol_factory, *args, **kwargs): @@ -577,7 +577,7 @@ class BaseEventLoop(events.AbstractEventLoop): protocol = protocol_factory() transport = yield self._make_subprocess_transport( protocol, args, False, stdin, stdout, stderr, bufsize, **kwargs) - raise tasks.Return((transport, protocol)) + raise tasks.Return(transport, protocol) def _add_callback(self, handle): """Add a Handle to ready or scheduled.""" diff --git a/asyncio/streams.py b/asyncio/streams.py index 694032f..cf0c800 100644 --- a/asyncio/streams.py +++ b/asyncio/streams.py @@ -43,7 +43,7 @@ def open_connection(host=None, port=None, transport, _ = yield loop.create_connection( lambda: protocol, host, port, **kwds) writer = StreamWriter(transport, protocol, reader, loop) - raise tasks.Return((reader, writer)) + raise tasks.Return(reader, writer) @tasks.coroutine diff --git a/asyncio/tasks.py b/asyncio/tasks.py index d64df69..710cf7f 100644 --- a/asyncio/tasks.py +++ b/asyncio/tasks.py @@ -38,9 +38,14 @@ _DEBUG = False class Return(StopIteration): - def __init__(self, value=None): + def __init__(self, *value): StopIteration.__init__(self) - self.value = value + if not value: + self.value = None + elif len(value) == 1: + self.value = value[0] + else: + self.value = value class CoroWrapper(object): @@ -456,7 +461,7 @@ def _wait(fs, timeout, return_when, loop): done.add(f) else: pending.add(f) - raise Return((done, pending)) + raise Return(done, pending) # This is *not* a @coroutine! It is just an iterator (yielding Futures). diff --git a/asyncio/windows_events.py b/asyncio/windows_events.py index 17ff044..65bdbcf 100644 --- a/asyncio/windows_events.py +++ b/asyncio/windows_events.py @@ -136,7 +136,7 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop): protocol = protocol_factory() trans = self._make_duplex_pipe_transport(pipe, protocol, extra={'addr': address}) - raise tasks.Return((trans, protocol)) + raise tasks.Return(trans, protocol) @tasks.coroutine def start_serving_pipe(self, protocol_factory, address): diff --git a/examples/cacheclt.py b/examples/cacheclt.py index fbea74b..bc0f071 100644 --- a/examples/cacheclt.py +++ b/examples/cacheclt.py @@ -162,7 +162,7 @@ class CacheClient: if len(data) != resp_size: raise EOFError() resp = json.loads(data.decode('utf8')) - raise asyncio.Return((resp_id, resp)) + raise asyncio.Return(resp_id, resp) def main(): diff --git a/examples/child_process.py b/examples/child_process.py index 76bd04d..2c74413 100644 --- a/examples/child_process.py +++ b/examples/child_process.py @@ -45,7 +45,7 @@ def connect_read_pipe(file): def factory(): return streams.StreamReaderProtocol(stream_reader) transport, _ = yield loop.connect_read_pipe(factory, file) - raise asyncio.Return((stream_reader, transport)) + raise asyncio.Return(stream_reader, transport) # diff --git a/examples/crawl.py b/examples/crawl.py index 74959d3..af70817 100644 --- a/examples/crawl.py +++ b/examples/crawl.py @@ -178,7 +178,7 @@ class ConnectionPool: else: self.log(1, '* Reusing pooled connection', key, 'FD =', writer._transport._sock.fileno()) - raise asyncio.Return((key, reader, writer)) + raise asyncio.Return(key, reader, writer) # Create a new connection. reader, writer = yield asyncio.open_connection(host, port, @@ -191,7 +191,7 @@ class ConnectionPool: key = host, port, ssl self.log(1, '* New connection', key, 'FD =', writer._transport._sock.fileno()) - raise asyncio.Return((key, reader, writer)) + raise asyncio.Return(key, reader, writer) def unreserve(self, key, reader, writer): """Make a connection available for reuse. diff --git a/examples/fetch3.py b/examples/fetch3.py index 98a9567..1da2349 100644 --- a/examples/fetch3.py +++ b/examples/fetch3.py @@ -57,7 +57,7 @@ class ConnectionPool: self.connections[key] = reader, writer if self.verbose: print('* New connection', key, file=sys.stderr) - raise Return((reader, writer)) + raise Return(reader, writer) class Request: |