[Pkg-mpd-commits] [python-mpd] 64/91: asyncio: Restore Python 3.5 compatibility
Simon McVittie
smcv at debian.org
Sat Feb 24 14:55:37 UTC 2018
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian/master
in repository python-mpd.
commit 6c5ccc3f6f2ce535ade6e1c140b5b54e3df9d2f7
Author: chrysn <chrysn at fsfe.org>
Date: Fri Apr 21 14:33:07 2017 +0200
asyncio: Restore Python 3.5 compatibility
---
mpd/asyncio.py | 49 +++++++++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 10 deletions(-)
diff --git a/mpd/asyncio.py b/mpd/asyncio.py
index 388b889..fa61afa 100644
--- a/mpd/asyncio.py
+++ b/mpd/asyncio.py
@@ -361,18 +361,47 @@ class MPDClient(MPDClientBase):
# commands that just work differently
- async def idle(self, subsystems=()):
+# async def idle(self, subsystems=()):
+# interests_before = self._get_idle_interests()
+# changes = asyncio.Queue()
+# try:
+# entry = (subsystems, changes.put_nowait)
+# self.__idle_consumers.append(entry)
+# if self._get_idle_interests != interests_before:
+# self._nudge_idle()
+# while True:
+# yield await changes.get()
+# finally:
+# self.__idle_consumers.remove(entry)
+
+ def idle(self, subsystems=()):
+ # this is a desugared workaround for python 3.5 like
+ # _parse_objects_direct. like there, please consider the above block
+ # authoritative and this a workaround, and only apply changes here once
+ # they're incorprated there.
+
+ def final():
+ self.__idle_consumers.remove(entry)
+
+ class IdleAIter:
+ def __aiter__(self):
+ return self
+
+ def __anext__(self):
+ return changes.get()
+
+ def __del__(self):
+ final()
+
interests_before = self._get_idle_interests()
changes = asyncio.Queue()
- try:
- entry = (subsystems, changes.put_nowait)
- self.__idle_consumers.append(entry)
- if self._get_idle_interests != interests_before:
- self._nudge_idle()
- while True:
- yield await changes.get()
- finally:
- self.__idle_consumers.remove(entry)
+
+ entry = (subsystems, changes.put_nowait)
+ self.__idle_consumers.append(entry)
+ if self._get_idle_interests != interests_before:
+ self._nudge_idle()
+
+ return IdleAIter()
def noidle(self):
raise AttributeError("noidle is not supported / required in mpd.asyncio")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mpd/python-mpd.git
More information about the Pkg-mpd-commits
mailing list