From ecdbc2e2d41d0e4545d6e4c68e9fd00e0f6129c3 Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Sat, 22 Mar 2008 23:16:31 -0400 Subject: [PATCH] mpd.py: raise ConnectionError on EOF --- mpd.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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() -- 2.39.2