class MPDError(Exception):
pass
+class ConnectionError(MPDError):
+ pass
+
class ProtocolError(MPDError):
pass
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
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):
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()