From: J. Alexander Treuman Date: Sun, 23 Mar 2008 03:16:31 +0000 (-0400) Subject: mpd.py: raise ConnectionError on EOF X-Git-Tag: v0.2.0~17 X-Git-Url: https://git.kaliko.me/?p=python-musicpd.git;a=commitdiff_plain;h=ecdbc2e2d41d0e4545d6e4c68e9fd00e0f6129c3 mpd.py: raise ConnectionError on EOF --- diff --git a/mpd.py b/mpd.py index be8b390..e16c8b8 100644 --- a/mpd.py +++ b/mpd.py @@ -26,6 +26,9 @@ NEXT = "list_OK" class MPDError(Exception): pass +class ConnectionError(MPDError): + pass + class ProtocolError(MPDError): pass @@ -141,7 +144,10 @@ class MPDClient(object): self._writeline(" ".join(parts)) def _readline(self): - line = self._sockfile.readline().rstrip("\n") + line = self._sockfile.readline() + if not line.endswith("\n"): + raise ConnectionError, "Connection lost while reading line" + line = line.rstrip("\n") if line.startswith(ERROR_PREFIX): error = line[len(ERROR_PREFIX):].strip() raise CommandError, error @@ -259,7 +265,9 @@ class MPDClient(object): return self._wrapiterator(self._readcommandlist()) def _hello(self): - line = self._sockfile.readline().rstrip("\n") + line = self._sockfile.readline() + if not line.endswith("\n"): + raise ConnectionError, "Connection lost while reading MPD hello" if not line.startswith(HELLO_PREFIX): raise ProtocolError, "Got invalid MPD hello: '%s'" % line self.mpd_version = line[len(HELLO_PREFIX):].strip()