X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=musicpd.py;h=118309f351402ae6c1ed8d7df56aae97d878842c;hb=28fdb74239a4cc7afc04d500573cb8088b6a083a;hp=ea2ec2098c26de1e01464013c5085e2395d9af59;hpb=b7210ccc7d0d41ef4a514a3bead1b4c3d260db6b;p=python-musicpd.git diff --git a/musicpd.py b/musicpd.py index ea2ec20..118309f 100644 --- a/musicpd.py +++ b/musicpd.py @@ -24,7 +24,7 @@ HELLO_PREFIX = "OK MPD " ERROR_PREFIX = "ACK " SUCCESS = "OK" NEXT = "list_OK" -VERSION = '0.4.0' +VERSION = '0.4.1' class MPDError(Exception): @@ -90,7 +90,7 @@ class MPDClient: "clearerror": self._fetch_nothing, "currentsong": self._fetch_object, "idle": self._fetch_list, - "noidle": None, + #"noidle": None, "status": self._fetch_object, "stats": self._fetch_object, # Playback Option Commands @@ -257,7 +257,9 @@ class MPDClient: self._wfile.write("%s\n" % line) self._wfile.flush() - def _write_command(self, command, args=[]): + def _write_command(self, command, args=None): + if args is None: + args = [] parts = [command] for arg in args: if isinstance(arg, tuple): @@ -310,11 +312,13 @@ class MPDClient: yield value def _read_playlist(self): - for key, value in self._read_pairs(":"): + for _, value in self._read_pairs(":"): yield value - def _read_objects(self, delimiters=[]): + def _read_objects(self, delimiters=None): obj = {} + if delimiters is None: + delimiters = [] for key, value in self._read_pairs(): key = key.lower() if obj: @@ -438,7 +442,7 @@ class MPDClient: for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, flags): - af, socktype, proto, canonname, sa = res + af, socktype, proto, _, sa = res sock = None try: sock = socket.socket(af, socktype, proto) @@ -453,6 +457,14 @@ class MPDClient: else: raise ConnectionError("getaddrinfo returns an empty list") + def noidle(self): + # noidle's special case + if not self._pending or self._pending[0] != 'idle': + raise CommandError('cannot send noidle if send_idle was not called') + del self._pending[0] + self._write_command("noidle") + return self._fetch_list() + def connect(self, host, port): if self._sock is not None: raise ConnectionError("Already connected")