]> kaliko git repositories - python-musicpd.git/blobdiff - mpd.py
TODO.txt: changing header for consistency
[python-musicpd.git] / mpd.py
diff --git a/mpd.py b/mpd.py
index a5e1877e5fcfa45f156a982122980163b9bf4335..e16c8b8aa584ca7a5b5db0fa86faf002cc0afd5c 100644 (file)
--- 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
@@ -225,7 +231,7 @@ class MPDClient(object):
     def _getitem(self):
         items = list(self._readitems())
         if len(items) != 1:
-            raise ProtocolError, "Expected 1 item, got %i" % len(items)
+            return
         return items[0][1]
 
     def _getlist(self):
@@ -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()