From 1b144cef816a2917dd4338bfdf6e88525c310501 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Thu, 11 Oct 2012 15:00:16 +0200 Subject: [PATCH 01/16] Update changelog --- CHANGES.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index e9dac67..27a54e4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,15 @@ python-mpd Changes List ======================= +Changes in 0.3.1 UNRELEASED +---------------- + +* python3 port +* added searchadd and searchaddpl commands +* added seekcur command +* added client to client commands + + Changes in 0.3.0 ---------------- -- 2.39.2 From 92a072f152417f607bd4cc5f549972ba76a15cad Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Mon, 15 Apr 2013 20:13:57 +0200 Subject: [PATCH 02/16] Handles better lost connections --- mpd.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mpd.py b/mpd.py index 4ad4804..373bd16 100644 --- a/mpd.py +++ b/mpd.py @@ -236,6 +236,7 @@ class MPDClient(object): def _read_line(self): line = self._rfile.readline() if not line.endswith("\n"): + self.disconnect() raise ConnectionError("Connection lost while reading line") line = line.rstrip("\n") if line.startswith(ERROR_PREFIX): @@ -414,7 +415,7 @@ class MPDClient(object): if sock is not None: sock.close() if err is not None: - raise err + raise ConnectionError(str(err)) else: raise ConnectionError("getaddrinfo returns an empty list") @@ -434,9 +435,15 @@ class MPDClient(object): raise def disconnect(self): - self._rfile.close() - self._wfile.close() - self._sock.close() + if isinstance(self._rfile, socket._fileobject): + print('closing r socket') + self._rfile.close() + if isinstance(self._wfile, socket._fileobject): + print('closing w socket') + self._wfile.close() + if isinstance(self._sock, socket.socket): + print('closing socket') + self._sock.close() self._reset() def fileno(self): -- 2.39.2 From 652e68d3be1f6f7b97d715deef99a258f249595b Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Mon, 15 Apr 2013 20:17:07 +0200 Subject: [PATCH 03/16] Explicit R/W utf-8 encoded bytes to socket python-mpd now deals only with unicode --- mpd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpd.py b/mpd.py index 373bd16..b504428 100644 --- a/mpd.py +++ b/mpd.py @@ -426,8 +426,8 @@ class MPDClient(object): self._sock = self._connect_unix(host) else: self._sock = self._connect_tcp(host, port) - self._rfile = self._sock.makefile("r") - self._wfile = self._sock.makefile("w") + self._rfile = self._sock.makefile("r", encoding='utf-8') + self._wfile = self._sock.makefile("w", encoding='utf-8') try: self._hello() except: -- 2.39.2 From 82935e106152ee3feebf64be854583ceee4d60e5 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Mon, 15 Apr 2013 21:21:14 +0200 Subject: [PATCH 04/16] Use of hasattr instead of isinstance in disconnect --- mpd.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mpd.py b/mpd.py index b504428..7c7f016 100644 --- a/mpd.py +++ b/mpd.py @@ -435,14 +435,11 @@ class MPDClient(object): raise def disconnect(self): - if isinstance(self._rfile, socket._fileobject): - print('closing r socket') + if hasattr(self._rfile, 'close'): self._rfile.close() - if isinstance(self._wfile, socket._fileobject): - print('closing w socket') + if hasattr(self._wfile, 'close'): self._wfile.close() if isinstance(self._sock, socket.socket): - print('closing socket') self._sock.close() self._reset() -- 2.39.2 From e1bde448be82c3cedaadd6fa0f5447d250ecefb2 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Thu, 9 May 2013 10:32:42 +0200 Subject: [PATCH 05/16] =?utf8?q?Renamed=20project=20mpd=E2=86=92musicpd?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CHANGES.txt | 5 +++-- mpd.py => musicpd.py | 11 ++++++----- setup.py | 23 ++++++++++++----------- 3 files changed, 21 insertions(+), 18 deletions(-) rename mpd.py => musicpd.py (98%) diff --git a/CHANGES.txt b/CHANGES.txt index 27a54e4..c07fcf8 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,9 +1,10 @@ -python-mpd Changes List -======================= +python-musicpd Changes List +=========================== Changes in 0.3.1 UNRELEASED ---------------- +* renamed musicpd * python3 port * added searchadd and searchaddpl commands * added seekcur command diff --git a/mpd.py b/musicpd.py similarity index 98% rename from mpd.py rename to musicpd.py index 7c7f016..864337e 100644 --- a/mpd.py +++ b/musicpd.py @@ -1,19 +1,19 @@ -# python-mpd: Python MPD client library +# python-musicpd: Python MPD client library # Copyright (C) 2008-2010 J. Alexander Treuman -# Copyright (C) 2012 Kaliko Jack +# Copyright (C) 2012-2013 Kaliko Jack # -# python-mpd is free software: you can redistribute it and/or modify +# python-musicpd is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# python-mpd is distributed in the hope that it will be useful, +# python-musicpd is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with python-mpd. If not, see . +# along with python-musicpd. If not, see . import socket @@ -22,6 +22,7 @@ HELLO_PREFIX = "OK MPD " ERROR_PREFIX = "ACK " SUCCESS = "OK" NEXT = "list_OK" +VERSION = '0.3.1b' class MPDError(Exception): diff --git a/setup.py b/setup.py index fee2420..13816a7 100644 --- a/setup.py +++ b/setup.py @@ -13,37 +13,38 @@ CLASSIFIERS = [ "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Natural Language :: English", "Operating System :: OS Independent", - "Programming Language :: Python", + "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules", ] LICENSE = """\ Copyright (C) 2008-2010 J. Alexander Treuman +Copyright (C) 2012-2013 Kaliko Jack -python-mpd is free software: you can redistribute it and/or modify +python-musicpd is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -python-mpd is distributed in the hope that it will be useful, +python-musicpd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License -along with python-mpd. If not, see .\ +along with python-musicpd. If not, see .\ """ setup( - name="python-mpd", - version="0.3.0", - description="Python MPD client library", + name='python-musicpd', + version='0.3.1', + description='Python MPD client library', long_description=DESCRIPTION, - author="J. Alexander Treuman", - author_email="jat@spatialrift.net", - url="http://jatreuman.indefero.net/p/python-mpd/", - download_url="http://pypi.python.org/pypi/python-mpd/", + author='Kaliko Jack', + author_email='kaliko@azylum.org', + #url="http://jatreuman.indefero.net/p/python-mpd/", + download_url="http://pypi.python.org/pypi/python-musicpd/", py_modules=["mpd"], classifiers=CLASSIFIERS, #license=LICENSE, -- 2.39.2 From ffbd90666dc18d72ca0c30ff8b34a629878de6f4 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Thu, 9 May 2013 14:26:54 +0200 Subject: [PATCH 06/16] Ease unitesting with mock --- musicpd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musicpd.py b/musicpd.py index 864337e..6bb0509 100644 --- a/musicpd.py +++ b/musicpd.py @@ -440,7 +440,7 @@ class MPDClient(object): self._rfile.close() if hasattr(self._wfile, 'close'): self._wfile.close() - if isinstance(self._sock, socket.socket): + if hasattr(self._sock, 'close'): self._sock.close() self._reset() -- 2.39.2 From 129580789b889e62a473b5ebe4ffd3a3d3423848 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Sun, 2 Jun 2013 15:27:28 +0200 Subject: [PATCH 07/16] Fixed py_modules in setup.py Mention explicitly py2 is not supported --- CHANGES.txt | 1 + setup.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index c07fcf8..175d564 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,7 @@ Changes in 0.3.1 UNRELEASED * renamed musicpd * python3 port +* no python2 support * added searchadd and searchaddpl commands * added seekcur command * added client to client commands diff --git a/setup.py b/setup.py index 13816a7..4e31856 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 from distutils.core import setup @@ -45,7 +45,7 @@ setup( author_email='kaliko@azylum.org', #url="http://jatreuman.indefero.net/p/python-mpd/", download_url="http://pypi.python.org/pypi/python-musicpd/", - py_modules=["mpd"], + py_modules=["musicpd"], classifiers=CLASSIFIERS, #license=LICENSE, keywords=["mpd"], -- 2.39.2 From 8d479631733614b46a786022a53c8e40a4e92a1b Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Tue, 12 Nov 2013 19:43:47 +0100 Subject: [PATCH 08/16] Add readcomments and toggleoutput commands --- doc/commands.txt | 2 ++ musicpd.py | 2 ++ setup.py | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/commands.txt b/doc/commands.txt index d71063f..1ec938c 100644 --- a/doc/commands.txt +++ b/doc/commands.txt @@ -72,6 +72,7 @@ lsinfo [] -> fetch_database search -> fetch_songs update [] -> fetch_item rescan [] -> fetch_item +readcomments -> fetch_object == Sticker Commands sticker get -> fetch_item @@ -89,6 +90,7 @@ ping -> fetch_nothing == Audio Output Commands disableoutput -> fetch_nothing enableoutput -> fetch_nothing +toggleoutput -> fetch_nothing outputs -> fetch_outputs == Reflection Commands diff --git a/musicpd.py b/musicpd.py index 6bb0509..f365bb0 100644 --- a/musicpd.py +++ b/musicpd.py @@ -131,6 +131,7 @@ class MPDClient(object): "searchaddpl": self._fetch_nothing, "update": self._fetch_item, "rescan": self._fetch_item, + "readcomments": self._fetch_object, # Sticker Commands "sticker get": self._fetch_item, "sticker set": self._fetch_nothing, @@ -145,6 +146,7 @@ class MPDClient(object): # Audio Output Commands "disableoutput": self._fetch_nothing, "enableoutput": self._fetch_nothing, + "toggleoutput": self._fetch_nothing, "outputs": self._fetch_outputs, # Reflection Commands "commands": self._fetch_list, diff --git a/setup.py b/setup.py index 4e31856..e3418ab 100644 --- a/setup.py +++ b/setup.py @@ -47,9 +47,9 @@ setup( download_url="http://pypi.python.org/pypi/python-musicpd/", py_modules=["musicpd"], classifiers=CLASSIFIERS, - #license=LICENSE, + license=LICENSE, keywords=["mpd"], - #platforms=["Independant"], + platforms=["Independant"], ) -- 2.39.2 From 8b540cb8ec163a457d81b84098eba80d630ed7e7 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Tue, 12 Nov 2013 20:16:15 +0100 Subject: [PATCH 09/16] Preparing 0.4 release --- README.txt | 15 +++++++++------ musicpd.py | 2 +- setup.py | 5 +++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.txt b/README.txt index 9cf4173..5388229 100644 --- a/README.txt +++ b/README.txt @@ -14,7 +14,7 @@ Getting the latest source code If you would instead like to use the latest source code, you can grab a copy of the development version from git by running the command: - git clone git://jatreuman.indefero.net/jatreuman/python-mpd.git + git clone git://git.kaliko.me/python-musicpd.git Installing from source @@ -22,10 +22,10 @@ Installing from source To install python-mpd from source, simply run the command: - python setup.py install + python3 setup.py install You can use the `--help` switch to `setup.py` for a complete list of commands -and their options. See the http://docs.python.org/inst/inst.html[Installing +and their options. See the http://docs.python.org/3/install/[Installing Python Modules] document for more details. @@ -69,9 +69,12 @@ for song in client.playlistinfo(): ------------------------------------------------------------------------------ -Contacting the author ---------------------- +Contacting authors +------------------ -You can contact the author by emailing J. Alexander Treuman +You can contact the original author by emailing J. Alexander Treuman . He can also be found idling in #mpd on irc.freenode.net as jat. + +The current maintainer can be found on xmpp chat room kaliko.me@conf.azylum.org +or you can contact him by email/xmpp . diff --git a/musicpd.py b/musicpd.py index f365bb0..f480acd 100644 --- a/musicpd.py +++ b/musicpd.py @@ -22,7 +22,7 @@ HELLO_PREFIX = "OK MPD " ERROR_PREFIX = "ACK " SUCCESS = "OK" NEXT = "list_OK" -VERSION = '0.3.1b' +VERSION = '0.4.0pr0' class MPDError(Exception): diff --git a/setup.py b/setup.py index e3418ab..8bc489d 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ from distutils.core import setup +from musicpd import VERSION DESCRIPTION = """\ An MPD (Music Player Daemon) client library written in pure Python.\ @@ -38,12 +39,12 @@ along with python-musicpd. If not, see .\ setup( name='python-musicpd', - version='0.3.1', + version=VERSION, description='Python MPD client library', long_description=DESCRIPTION, author='Kaliko Jack', author_email='kaliko@azylum.org', - #url="http://jatreuman.indefero.net/p/python-mpd/", + url="http://kaliko.me/code/python-musicpd", download_url="http://pypi.python.org/pypi/python-musicpd/", py_modules=["musicpd"], classifiers=CLASSIFIERS, -- 2.39.2 From 4fdeb581beba85d9157fac917c48ae08dda4c941 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Fri, 15 Nov 2013 15:33:49 +0100 Subject: [PATCH 10/16] Fixed documentation --- README.txt | 67 ++++++++++++++++++++++++++---------------------------- setup.py | 8 +++++-- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/README.txt b/README.txt index 5388229..8077aa2 100644 --- a/README.txt +++ b/README.txt @@ -1,11 +1,12 @@ -python-mpd -========== +============== +python-musicpd +============== -Getting python-mpd ------------------- +Getting python-musicpd +---------------------- -The latest release of python-mpd can be found at -http://pypi.python.org/pypi/python-mpd/[]. +The latest release of python-musicpd can be found at +http://pypi.python.org/pypi/python-musicpd/. Getting the latest source code @@ -20,61 +21,57 @@ of the development version from git by running the command: Installing from source ---------------------- -To install python-mpd from source, simply run the command: +To install python-musicpd from source, simply run the command:: python3 setup.py install You can use the `--help` switch to `setup.py` for a complete list of commands -and their options. See the http://docs.python.org/3/install/[Installing -Python Modules] document for more details. +and their options. See the `Installing Python Modules`_ document for more details. Using the client library ------------------------ -The client library can be used as follows: +The client library can be used as follows:: ------------------------------------------------------------------------------- -client = mpd.MPDClient() # create client object -client.connect("localhost", 6600) # connect to localhost:6600 -print client.mpd_version # print the mpd version -print client.cmd("one", 2) # print result of the command "cmd one 2" -client.close() # send the close command -client.disconnect() # disconnect from the server ------------------------------------------------------------------------------- +>>> client = mpd.MPDClient() # create client object +>>> client.connect("localhost", 6600) # connect to localhost:6600 +>>> print client.mpd_version # print the mpd version +>>> print client.cmd("one", 2) # print result of the command "cmd one 2" +>>> client.close() # send the close command +>>> client.disconnect() # disconnect from the server A list of supported commands, their arguments (as MPD currently understands them), and the functions used to parse their responses can be found in -`doc/commands.txt`. See the -http://www.musicpd.org/doc/protocol/[MPD protocol documentation] for more +`doc/commands.txt`. See the `MPD protocol documentation`_ for more details. Command lists are also supported using `command_list_ok_begin()` and -`command_list_end()`: +`command_list_end()` :: + +>>> client.command_list_ok_begin() # start a command list +>>> client.update() # insert the update command into the list +>>> client.status() # insert the status command into the list +>>> results = client.command_list_end() # results will be a list with the results ------------------------------------------------------------------------------- -client.command_list_ok_begin() # start a command list -client.update() # insert the update command into the list -client.status() # insert the status command into the list -results = client.command_list_end() # results will be a list with the results ------------------------------------------------------------------------------- Commands may also return iterators instead of lists if `iterate` is set to -`True`: +`True`:: ------------------------------------------------------------------------------- -client.iterate = True -for song in client.playlistinfo(): - print song["file"] ------------------------------------------------------------------------------- +>>> client.iterate = True +>>> for song in client.playlistinfo(): +>>> print song["file"] Contacting authors ------------------ You can contact the original author by emailing J. Alexander Treuman -. He can also be found idling in #mpd on +. He can also be found idling in #mpd on irc.freenode.net as jat. The current maintainer can be found on xmpp chat room kaliko.me@conf.azylum.org -or you can contact him by email/xmpp . +or you can contact him by email/xmpp . + + .. _Installing Python Modules: http://docs.python.org/3/install/ + .. _MPD protocol documentation: http://www.musicpd.org/doc/protocol/ diff --git a/setup.py b/setup.py index 8bc489d..81c1276 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,10 @@ DESCRIPTION = """\ An MPD (Music Player Daemon) client library written in pure Python.\ """ + +with open('README.txt') as file: + LONG_DESCRIPTION = file.read() + CLASSIFIERS = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -40,8 +44,8 @@ along with python-musicpd. If not, see .\ setup( name='python-musicpd', version=VERSION, - description='Python MPD client library', - long_description=DESCRIPTION, + description=DESCRIPTION, + long_description=LONG_DESCRIPTION, author='Kaliko Jack', author_email='kaliko@azylum.org', url="http://kaliko.me/code/python-musicpd", -- 2.39.2 From ca2fb2a8b8ec82b9156265e07f43c937111d5b90 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Fri, 15 Nov 2013 20:15:37 +0100 Subject: [PATCH 11/16] Add some pylint exclusions --- README.txt | 4 ++-- musicpd.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 8077aa2..e6a2e31 100644 --- a/README.txt +++ b/README.txt @@ -6,7 +6,7 @@ Getting python-musicpd ---------------------- The latest release of python-musicpd can be found at -http://pypi.python.org/pypi/python-musicpd/. +http://pypi.python.org/pypi/python-musicpd. Getting the latest source code @@ -70,7 +70,7 @@ You can contact the original author by emailing J. Alexander Treuman . He can also be found idling in #mpd on irc.freenode.net as jat. -The current maintainer can be found on xmpp chat room kaliko.me@conf.azylum.org +The current maintainer can be found on xmpp chat room or you can contact him by email/xmpp . .. _Installing Python Modules: http://docs.python.org/3/install/ diff --git a/musicpd.py b/musicpd.py index f480acd..e281a92 100644 --- a/musicpd.py +++ b/musicpd.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with python-musicpd. If not, see . +# pylint: disable=C0111 + import socket @@ -22,7 +24,7 @@ HELLO_PREFIX = "OK MPD " ERROR_PREFIX = "ACK " SUCCESS = "OK" NEXT = "list_OK" -VERSION = '0.4.0pr0' +VERSION = '0.4.0pr1' class MPDError(Exception): @@ -382,6 +384,7 @@ class MPDClient(object): self.mpd_version = line[len(HELLO_PREFIX):].strip() def _reset(self): + # pylint: disable=w0201 self.mpd_version = None self._iterating = False self._pending = [] -- 2.39.2 From d28bd57ddc3465db4fcaa540fe7cb3de53f8be6b Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Fri, 15 Nov 2013 20:28:47 +0100 Subject: [PATCH 12/16] Fixed documentation --- MANIFEST.in | 2 +- README.txt => README.rst | 26 +++++++++++++------------- setup.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) rename README.txt => README.rst (71%) diff --git a/MANIFEST.in b/MANIFEST.in index 066ee11..3305050 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ exclude setup.cfg -include *.txt +include *.txt README.rst recursive-include doc *.txt diff --git a/README.txt b/README.rst similarity index 71% rename from README.txt rename to README.rst index e6a2e31..a926514 100644 --- a/README.txt +++ b/README.rst @@ -34,12 +34,12 @@ Using the client library The client library can be used as follows:: ->>> client = mpd.MPDClient() # create client object ->>> client.connect("localhost", 6600) # connect to localhost:6600 ->>> print client.mpd_version # print the mpd version ->>> print client.cmd("one", 2) # print result of the command "cmd one 2" ->>> client.close() # send the close command ->>> client.disconnect() # disconnect from the server + client = musicpd.MPDClient() # create client object + client.connect('localhost', 6600) # connect to localhost:6600 + print client.mpd_version # print the mpd version + print client.cmd('one', 2) # print result of the command "cmd one 2" + client.close() # send the close command + client.disconnect() # disconnect from the server A list of supported commands, their arguments (as MPD currently understands them), and the functions used to parse their responses can be found in @@ -49,18 +49,18 @@ details. Command lists are also supported using `command_list_ok_begin()` and `command_list_end()` :: ->>> client.command_list_ok_begin() # start a command list ->>> client.update() # insert the update command into the list ->>> client.status() # insert the status command into the list ->>> results = client.command_list_end() # results will be a list with the results + client.command_list_ok_begin() # start a command list + client.update() # insert the update command into the list + client.status() # insert the status command into the list + results = client.command_list_end() # results will be a list with the results Commands may also return iterators instead of lists if `iterate` is set to `True`:: ->>> client.iterate = True ->>> for song in client.playlistinfo(): ->>> print song["file"] + client.iterate = True + for song in client.playlistinfo(): + print song['file'] Contacting authors diff --git a/setup.py b/setup.py index 81c1276..18e0007 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ An MPD (Music Player Daemon) client library written in pure Python.\ """ -with open('README.txt') as file: +with open('README.rst') as file: LONG_DESCRIPTION = file.read() CLASSIFIERS = [ -- 2.39.2 From 798a839ccc7aaa34507b318e123708e2a7a22ca1 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Tue, 14 Jan 2014 16:49:19 +0100 Subject: [PATCH 13/16] Add range capabilities --- musicpd.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/musicpd.py b/musicpd.py index e281a92..9f2d910 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.0pr1' +VERSION = '0.4.0pr2' class MPDError(Exception): @@ -48,15 +48,40 @@ class PendingCommandError(MPDError): class IteratingError(MPDError): pass +class Range: -class _NotConnected(object): + def __init__(self, tpl): + self.tpl = tpl + self._check() + + def __str__(self): + if len(self.tpl) == 1: + return '{0}:'.format(self.tpl[0]) + return '{0[0]}:{0[1]}'.format(self.tpl) + + def __repr__(self): + return 'Range({0})'.format(self.tpl) + + def _check(self): + if not isinstance(self.tpl, tuple): + raise CommandError('Wrong type, provide a tuple') + if len(self.tpl) not in [1, 2]: + raise CommandError('length not in [1, 2]') + for index in self.tpl: + try: + index = int(index) + except (TypeError, ValueError): + raise CommandError('Not a tuple of int') + + +class _NotConnected: def __getattr__(self, attr): return self._dummy def _dummy(*args): raise ConnectionError("Not connected") -class MPDClient(object): +class MPDClient: def __init__(self): self.iterate = False self._reset() @@ -235,7 +260,10 @@ class MPDClient(object): def _write_command(self, command, args=[]): parts = [command] for arg in args: - parts.append('"%s"' % escape(str(arg))) + if isinstance(arg, tuple): + parts.append('{0!s}'.format(Range(arg))) + else: + parts.append('"%s"' % escape(str(arg))) self._write_line(" ".join(parts)) def _read_line(self): -- 2.39.2 From 422c2e94f04420aa25e73becf3ad95d27957cf0c Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Wed, 15 Jan 2014 09:33:59 +0100 Subject: [PATCH 14/16] Upates changelog --- CHANGES.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 175d564..f4150d0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,8 +1,14 @@ python-musicpd Changes List =========================== +Cahnges in 0.4.0 UNRELEASED +--------------------------- + +* support range + + Changes in 0.3.1 UNRELEASED ----------------- +--------------------------- * renamed musicpd * python3 port @@ -10,6 +16,7 @@ Changes in 0.3.1 UNRELEASED * added searchadd and searchaddpl commands * added seekcur command * added client to client commands +* added readcomments and toggleoutput commands Changes in 0.3.0 -- 2.39.2 From b7210ccc7d0d41ef4a514a3bead1b4c3d260db6b Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Sat, 18 Jan 2014 12:09:15 +0100 Subject: [PATCH 15/16] Releasing v0.4.0 --- CHANGES.txt | 6 ++---- musicpd.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f4150d0..83a628d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,12 +1,11 @@ python-musicpd Changes List =========================== -Cahnges in 0.4.0 UNRELEASED ---------------------------- +Changes in 0.4.0 +---------------- * support range - Changes in 0.3.1 UNRELEASED --------------------------- @@ -18,7 +17,6 @@ Changes in 0.3.1 UNRELEASED * added client to client commands * added readcomments and toggleoutput commands - Changes in 0.3.0 ---------------- diff --git a/musicpd.py b/musicpd.py index 9f2d910..ea2ec20 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.0' class MPDError(Exception): -- 2.39.2 From 8fec386e0991e20df8bbb0cc99f0bbf621b6d95c Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Sun, 15 Dec 2013 11:16:49 +0100 Subject: [PATCH 16/16] Avoid potential dangerous default value [] as argument --- musicpd.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/musicpd.py b/musicpd.py index ea2ec20..4980c27 100644 --- a/musicpd.py +++ b/musicpd.py @@ -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) -- 2.39.2