[Pkg-mpd-commits] [python-mpd] 55/91: base: Move obtaining of hello line out of hello function

Simon McVittie smcv at debian.org
Sat Feb 24 14:55:35 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 66c7477257d13df50b1fe9146424300764c98d84
Author: chrysn <chrysn at fsfe.org>
Date:   Fri Apr 7 09:51:21 2017 +0200

    base: Move obtaining of hello line out of hello function
    
    This makes _hello nonblocking and thus usable for asyncio.
---
 mpd/asyncio.py | 25 +++++++------------------
 mpd/base.py    |  6 +++---
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/mpd/asyncio.py b/mpd/asyncio.py
index 8560f31..12aa781 100644
--- a/mpd/asyncio.py
+++ b/mpd/asyncio.py
@@ -103,7 +103,13 @@ class MPDClient(MPDClientBase):
 
         self.__commandqueue = asyncio.Queue(loop=loop)
 
-        await self.__hello()
+        try:
+            helloline = await asyncio.wait_for(self.__readline(), timeout=5)
+        except asyncio.TimeoutError:
+            self.disconnect()
+            raise ConnectionError("No response from server while reading MPD hello")
+        # FIXME should be reusable w/o reaching in
+        SyncMPDClient._hello(self, helloline)
 
         self.__run_task = asyncio.Task(self.__run())
 
@@ -143,23 +149,6 @@ class MPDClient(MPDClientBase):
 
     # copied and subtly modifiedstuff from base
 
-    async def __hello(self):
-        # not catching the timeout error, it's actually pretty adaequate
-        try:
-            line = await asyncio.wait_for(self.__readline(), timeout=5)
-        except asyncio.TimeoutError:
-            self.disconnect()
-            raise ConnectionError("No response from server while reading MPD hello")
-
-        # FIXME this is copied from base.MPDClient._hello
-        if not line.endswith("\n"):
-            self.disconnect()
-            raise ConnectionError("Connection lost while reading MPD hello")
-        line = line.rstrip("\n")
-        if not line.startswith(HELLO_PREFIX):
-            raise ProtocolError("Got invalid MPD hello: '{}'".format(line))
-        self.mpd_version = line[len(HELLO_PREFIX):].strip()
-
     # this is just a wrapper for the below
     def _write_line(self, text):
         self.__write(text + "\n")
diff --git a/mpd/base.py b/mpd/base.py
index bed9598..1d0d565 100644
--- a/mpd/base.py
+++ b/mpd/base.py
@@ -542,8 +542,7 @@ class MPDClient(MPDClientBase):
         self._iterating = True
         return self._iterator_wrapper(iterator)
 
-    def _hello(self):
-        line = self._rfile.readline()
+    def _hello(self, line):
         if not line.endswith("\n"):
             self.disconnect()
             raise ConnectionError("Connection lost while reading MPD hello")
@@ -636,7 +635,8 @@ class MPDClient(MPDClientBase):
                 encoding="utf-8",
                 newline="\n")
         try:
-            self._hello()
+            helloline = self._rfile.readline()
+            self._hello(helloline)
         except:
             self.disconnect()
             raise

-- 
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