commit:     e6ae7fdc18a876d3a0f5fcea437b5f448d1dcb4e
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 17 05:44:14 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Apr 17 05:48:42 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=e6ae7fdc

Use asyncio shim for TimeoutError and other exceptions

 pym/portage/sync/modules/rsync/rsync.py       |  4 ++--
 pym/portage/tests/util/futures/test_retry.py  |  7 +++----
 pym/portage/util/futures/_asyncio/__init__.py | 10 +++++++++-
 pym/portage/util/futures/retry.py             |  4 ++--
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/pym/portage/sync/modules/rsync/rsync.py 
b/pym/portage/sync/modules/rsync/rsync.py
index de8327a55..180bf8571 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -25,7 +25,7 @@ warn = create_color_func("WARN")
 from portage.const import VCS_DIRS, TIMESTAMP_FORMAT, RSYNC_PACKAGE_ATOM
 from portage.util._eventloop.global_event_loop import global_event_loop
 from portage.util import writemsg, writemsg_stdout
-from portage.util.futures.futures import TimeoutError
+from portage.util.futures import asyncio
 from portage.sync.getaddrinfo_validate import getaddrinfo_validate
 from _emerge.UserQuery import UserQuery
 from portage.sync.syncbase import NewBase
@@ -163,7 +163,7 @@ class RsyncSync(NewBase):
                                                decorated_func = 
retry_decorator(func_coroutine)
                                                
loop.run_until_complete(decorated_func())
                                        out.eend(0)
-                               except (GematoException, TimeoutError) as e:
+                               except (GematoException, asyncio.TimeoutError) 
as e:
                                        writemsg_level("!!! Manifest 
verification impossible due to keyring problem:\n%s\n"
                                                        % (e,),
                                                        level=logging.ERROR, 
noiselevel=-1)

diff --git a/pym/portage/tests/util/futures/test_retry.py 
b/pym/portage/tests/util/futures/test_retry.py
index 409f50971..27d8c7b61 100644
--- a/pym/portage/tests/util/futures/test_retry.py
+++ b/pym/portage/tests/util/futures/test_retry.py
@@ -12,7 +12,6 @@ from portage.tests import TestCase
 from portage.util._eventloop.global_event_loop import global_event_loop
 from portage.util.backoff import RandomExponentialBackoff
 from portage.util.futures import asyncio
-from portage.util.futures.futures import TimeoutError
 from portage.util.futures.retry import retry
 from portage.util.monotonic import monotonic
 
@@ -97,7 +96,7 @@ class RetryTestCase(TestCase):
                decorated_func = decorator(func_coroutine)
                done, pending = 
loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop))
                self.assertEqual(len(done), 1)
-               self.assertTrue(isinstance(done.pop().exception().__cause__, 
TimeoutError))
+               self.assertTrue(isinstance(done.pop().exception().__cause__, 
asyncio.TimeoutError))
 
        def testHangForeverReraise(self):
                loop = global_event_loop()._asyncio_wrapper
@@ -108,7 +107,7 @@ class RetryTestCase(TestCase):
                decorated_func = decorator(func_coroutine)
                done, pending = 
loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop))
                self.assertEqual(len(done), 1)
-               self.assertTrue(isinstance(done.pop().exception(), 
TimeoutError))
+               self.assertTrue(isinstance(done.pop().exception(), 
asyncio.TimeoutError))
 
        def testCancelRetry(self):
                loop = global_event_loop()._asyncio_wrapper
@@ -144,4 +143,4 @@ class RetryTestCase(TestCase):
                decorated_func = decorator(func_coroutine)
                done, pending = 
loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop))
                self.assertEqual(len(done), 1)
-               self.assertTrue(isinstance(done.pop().exception().__cause__, 
TimeoutError))
+               self.assertTrue(isinstance(done.pop().exception().__cause__, 
asyncio.TimeoutError))

diff --git a/pym/portage/util/futures/_asyncio/__init__.py 
b/pym/portage/util/futures/_asyncio/__init__.py
index d1584fdea..9ae050874 100644
--- a/pym/portage/util/futures/_asyncio/__init__.py
+++ b/pym/portage/util/futures/_asyncio/__init__.py
@@ -6,7 +6,10 @@ __all__ = (
        'FIRST_COMPLETED',
        'FIRST_EXCEPTION',
        'ensure_future',
+       'CancelledError',
        'Future',
+       'InvalidStateError',
+       'TimeoutError',
        'get_child_watcher',
        'get_event_loop',
        'set_child_watcher',
@@ -26,7 +29,12 @@ import portage
 portage.proxy.lazyimport.lazyimport(globals(),
        'portage.util.futures.unix_events:DefaultEventLoopPolicy',
 )
-from portage.util.futures.futures import Future
+from portage.util.futures.futures import (
+       CancelledError,
+       Future,
+       InvalidStateError,
+       TimeoutError,
+)
 from portage.util.futures._asyncio.tasks import (
        ALL_COMPLETED,
        FIRST_COMPLETED,

diff --git a/pym/portage/util/futures/retry.py 
b/pym/portage/util/futures/retry.py
index 902ed163a..82012d2f3 100644
--- a/pym/portage/util/futures/retry.py
+++ b/pym/portage/util/futures/retry.py
@@ -10,7 +10,7 @@ import functools
 
 from portage.exception import PortageException
 from portage.util._eventloop.global_event_loop import global_event_loop
-from portage.util.futures.futures import TimeoutError
+from portage.util.futures import asyncio
 
 
 class RetryError(PortageException):
@@ -170,7 +170,7 @@ class _Retry(object):
 
        def _retry_error(self):
                if self._previous_result is None or 
self._previous_result.cancelled():
-                       cause = TimeoutError()
+                       cause = asyncio.TimeoutError()
                else:
                        cause = self._previous_result.exception()
 

Reply via email to