]> kaliko git repositories - python-musicpd.git/blobdiff - musicpd.py
mpd_version attribute init to empty string instead of None
[python-musicpd.git] / musicpd.py
index d96e76a54387fcfb7d6ac8db9be83540252edf83..50c35dd33bdd80342f38b230f674e399a5445f13 100644 (file)
@@ -1,21 +1,11 @@
-# python-musicpd: Python MPD client library
-# Copyright (C) 2012-2021  kaliko <kaliko@azylum.org>
-# Copyright (C) 2019       Naglis Jonaitis <naglis@mailbox.org>
-# Copyright (C) 2019       Bart Van Loon <bbb@bbbart.be>
-# Copyright (C) 2008-2010  J. Alexander Treuman <jat@spatialrift.net>
-#
-# 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-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-musicpd.  If not, see <http://www.gnu.org/licenses/>.
+# SPDX-FileCopyrightText: 2012-2023  kaliko <kaliko@azylum.org>
+# SPDX-FileCopyrightText: 2021       Wonko der Verständige <wonko@hanstool.org>
+# SPDX-FileCopyrightText: 2019       Naglis Jonaitis <naglis@mailbox.org>
+# SPDX-FileCopyrightText: 2019       Bart Van Loon <bbb@bbbart.be>
+# SPDX-FileCopyrightText: 2008-2010  J. Alexander Treuman <jat@spatialrift.net>
+# SPDX-License-Identifier: LGPL-3.0-or-later
+"""python-musicpd: Python Music Player Daemon client library"""
+
 
 import socket
 import os
@@ -26,7 +16,7 @@ HELLO_PREFIX = "OK MPD "
 ERROR_PREFIX = "ACK "
 SUCCESS = "OK"
 NEXT = "list_OK"
-VERSION = '0.8.0b0'
+VERSION = '0.9.0b0'
 #: Seconds before a connection attempt times out
 #: (overriden by MPD_TIMEOUT env. var.)
 CONNECTION_TIMEOUT = 30
@@ -162,6 +152,10 @@ class MPDClient:
         #: Current connection timeout value, defaults to
         #: :py:obj:`CONNECTION_TIMEOUT` or env. var. ``MPD_TIMEOUT`` if provided
         self.mpd_timeout = None
+        self.mpd_version = ''
+        """Protocol version as exposed by the server as a :py:obj:`str`
+
+        .. note:: This is the version of the protocol spoken, not the real version of the daemon."""
         self._reset()
         self._commands = {
             # Status Commands
@@ -595,7 +589,7 @@ class MPDClient:
         self.mpd_version = line[len(HELLO_PREFIX):].strip()
 
     def _reset(self):
-        self.mpd_version = None
+        self.mpd_version = ''
         self._iterating = False
         self._pending = []
         self._command_list = None
@@ -726,6 +720,13 @@ class MPDClient:
             self._sock.close()
         self._reset()
 
+    def __enter__(self):
+        self.connect()
+        return self
+
+    def __exit__(self, exception_type, exception_value, exception_traceback):
+        self.disconnect()
+
     def fileno(self):
         """Return the socket’s file descriptor (a small integer).
         This is useful with :py:obj:`select.select`.