]> kaliko git repositories - python-musicpd.git/blobdiff - musicpd.py
MPDClient: add __enter__/__exit__ to connect/disconnect
[python-musicpd.git] / musicpd.py
index d96e76a54387fcfb7d6ac8db9be83540252edf83..5824056aac4c364c71943e08a06cc2d5c84334ad 100644 (file)
@@ -726,6 +726,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`.