X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;ds=sidebyside;f=musicpd.py;h=fe14987dc54af0355a399b90bd8f3c294b35c28b;hb=e8daa719b31e6728f697fdc2812d969038ebe159;hp=9f2d910fd7626e0aca0c6d35d71ad609896a48a2;hpb=798a839ccc7aaa34507b318e123708e2a7a22ca1;p=python-musicpd.git diff --git a/musicpd.py b/musicpd.py index 9f2d910..fe14987 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.0pr2' +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 @@ -190,6 +190,8 @@ class MPDClient: } def __getattr__(self, attr): + if attr == 'send_noidle': # have send_noidle to cancel idle as well as noidle + return self.noidle() if attr.startswith("send_"): command = attr.replace("send_", "", 1) wrapper = self._send @@ -257,7 +259,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 +314,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 +444,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 +459,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")