public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/futures/
Date: Sun,  7 Mar 2021 07:31:51 +0000 (UTC)	[thread overview]
Message-ID: <1615102271.a8e0ddccf90a4f6dd0b4c0ae0832b4abb1f35b04.zmedico@gentoo> (raw)

commit:     a8e0ddccf90a4f6dd0b4c0ae0832b4abb1f35b04
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  7 07:29:35 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Mar  7 07:31:11 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a8e0ddcc

Remove unused _EventLoopFuture class

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/util/futures/futures.py | 156 +-----------------------------------
 1 file changed, 1 insertion(+), 155 deletions(-)

diff --git a/lib/portage/util/futures/futures.py b/lib/portage/util/futures/futures.py
index 839c767a7..3f239890a 100644
--- a/lib/portage/util/futures/futures.py
+++ b/lib/portage/util/futures/futures.py
@@ -1,4 +1,4 @@
-# Copyright 2016-2018 Gentoo Foundation
+# Copyright 2016-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 #
 # For compatibility with python versions which do not have the
@@ -19,157 +19,3 @@ from asyncio import (
 	InvalidStateError,
 	TimeoutError,
 )
-# pylint: enable=redefined-builtin
-
-import portage
-portage.proxy.lazyimport.lazyimport(globals(),
-	'portage.util._eventloop.global_event_loop:global_event_loop@_global_event_loop',
-)
-
-_PENDING = 'PENDING'
-_CANCELLED = 'CANCELLED'
-_FINISHED = 'FINISHED'
-
-class _EventLoopFuture:
-	"""
-	This class provides (a subset of) the asyncio.Future interface, for
-	use with the EventLoop class, because EventLoop is currently
-	missing some of the asyncio.AbstractEventLoop methods that
-	asyncio.Future requires.
-	"""
-
-	# Class variables serving as defaults for instance variables.
-	_state = _PENDING
-	_result = None
-	_exception = None
-	_loop = None
-
-	def __init__(self, loop=None):
-		"""Initialize the future.
-
-		The optional loop argument allows explicitly setting the event
-		loop object used by the future. If it's not provided, the future uses
-		the default event loop.
-		"""
-		if loop is None:
-			self._loop = _global_event_loop()
-		else:
-			self._loop = loop
-		self._callbacks = []
-
-	def cancel(self):
-		"""Cancel the future and schedule callbacks.
-
-		If the future is already done or cancelled, return False.  Otherwise,
-		change the future's state to cancelled, schedule the callbacks and
-		return True.
-		"""
-		if self._state != _PENDING:
-			return False
-		self._state = _CANCELLED
-		self._schedule_callbacks()
-		return True
-
-	def _schedule_callbacks(self):
-		"""Internal: Ask the event loop to call all callbacks.
-
-		The callbacks are scheduled to be called as soon as possible. Also
-		clears the callback list.
-		"""
-		callbacks = self._callbacks[:]
-		if not callbacks:
-			return
-
-		self._callbacks[:] = []
-		for callback in callbacks:
-			self._loop.call_soon(callback, self)
-
-	def cancelled(self):
-		"""Return True if the future was cancelled."""
-		return self._state == _CANCELLED
-
-	def done(self):
-		"""Return True if the future is done.
-
-		Done means either that a result / exception are available, or that the
-		future was cancelled.
-		"""
-		return self._state != _PENDING
-
-	def result(self):
-		"""Return the result this future represents.
-
-		If the future has been cancelled, raises CancelledError.  If the
-		future's result isn't yet available, raises InvalidStateError.  If
-		the future is done and has an exception set, this exception is raised.
-		"""
-		if self._state == _CANCELLED:
-			raise CancelledError()
-		if self._state != _FINISHED:
-			raise InvalidStateError('Result is not ready.')
-		if self._exception is not None:
-			raise self._exception
-		return self._result
-
-	def exception(self):
-		"""Return the exception that was set on this future.
-
-		The exception (or None if no exception was set) is returned only if
-		the future is done.  If the future has been cancelled, raises
-		CancelledError.  If the future isn't done yet, raises
-		InvalidStateError.
-		"""
-		if self._state == _CANCELLED:
-			raise CancelledError
-		if self._state != _FINISHED:
-			raise InvalidStateError('Exception is not set.')
-		return self._exception
-
-	def add_done_callback(self, fn):
-		"""Add a callback to be run when the future becomes done.
-
-		The callback is called with a single argument - the future object. If
-		the future is already done when this is called, the callback is
-		scheduled with call_soon.
-		"""
-		if self._state != _PENDING:
-			self._loop.call_soon(fn, self)
-		else:
-			self._callbacks.append(fn)
-
-	def remove_done_callback(self, fn):
-		"""Remove all instances of a callback from the "call when done" list.
-
-		Returns the number of callbacks removed.
-		"""
-		filtered_callbacks = [f for f in self._callbacks if f != fn]
-		removed_count = len(self._callbacks) - len(filtered_callbacks)
-		if removed_count:
-			self._callbacks[:] = filtered_callbacks
-		return removed_count
-
-	def set_result(self, result):
-		"""Mark the future done and set its result.
-
-		If the future is already done when this method is called, raises
-		InvalidStateError.
-		"""
-		if self._state != _PENDING:
-			raise InvalidStateError('{}: {!r}'.format(self._state, self))
-		self._result = result
-		self._state = _FINISHED
-		self._schedule_callbacks()
-
-	def set_exception(self, exception):
-		"""Mark the future done and set an exception.
-
-		If the future is already done when this method is called, raises
-		InvalidStateError.
-		"""
-		if self._state != _PENDING:
-			raise InvalidStateError('{}: {!r}'.format(self._state, self))
-		if isinstance(exception, type):
-			exception = exception()
-		self._exception = exception
-		self._state = _FINISHED
-		self._schedule_callbacks()


             reply	other threads:[~2021-03-07  7:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-07  7:31 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-09-20  7:21 [gentoo-commits] proj/portage:master commit in: lib/portage/util/futures/ Zac Medico
2021-03-07  8:11 Zac Medico
2021-03-07  7:41 Zac Medico
2021-03-07  7:13 Zac Medico
2021-01-18 12:20 Zac Medico
2021-01-04  9:00 Zac Medico
2020-08-24  3:40 Zac Medico
2020-08-17  4:24 Zac Medico
2019-02-16 17:38 Robin H. Johnson
2018-11-20 10:28 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1615102271.a8e0ddccf90a4f6dd0b4c0ae0832b4abb1f35b04.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox