[Pkg-mpd-commits] [python-mpd] 28/262: mpd.py: raise ConnectionError when trying to use an unconnected socket

Simon McVittie smcv at debian.org
Sun May 22 18:16:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch upstream
in repository python-mpd.

commit 11ad737dbfa521db07486a6cb789d3539a5ec4c0
Author: J. Alexander Treuman <jat at spatialrift.net>
Date:   Sun Mar 23 15:50:48 2008 -0400

    mpd.py: raise ConnectionError when trying to use an unconnected socket
    
    ConnectionError will now be raised when trying to read from/write to a
    socket before calling connect() or after calling disconnect().  In the past
    it would try to complete the operation on the unconnected socket, resulting
    in a socket.error exception.
---
 mpd.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/mpd.py b/mpd.py
index e16c8b8..02d2788 100644
--- a/mpd.py
+++ b/mpd.py
@@ -39,6 +39,13 @@ class CommandListError(MPDError):
     pass
 
 
+class _NotConnected(object):
+    def __getattr__(self, attr):
+        return self._dummy
+
+    def _dummy(*args):
+        raise ConnectionError, "Not connected"
+
 class MPDClient(object):
     def __init__(self):
         self.iterate = False
@@ -275,12 +282,15 @@ class MPDClient(object):
     def _reset(self):
         self.mpd_version = None
         self._commandlist = None
-        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self._sockfile = self._sock.makefile("rb+")
+        self._sock = None
+        self._sockfile = _NotConnected()
 
     def connect(self, host, port):
-        self.disconnect()
+        if self._sock:
+            self.disconnect()
+        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self._sock.connect((host, port))
+        self._sockfile = self._sock.makefile("rb+")
         self._hello()
 
     def disconnect(self):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mpd/python-mpd.git



More information about the Pkg-mpd-commits mailing list