X-Git-Url: http://git.kaliko.me/?p=python-musicpd.git;a=blobdiff_plain;f=mpd.py;h=e16c8b8aa584ca7a5b5db0fa86faf002cc0afd5c;hp=be8b390482e2a18639f94298e025e2282f5400a8;hb=ecdbc2e2d41d0e4545d6e4c68e9fd00e0f6129c3;hpb=c9d183f5a967068be96b538a197d9a9dedac6048 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()