summaryrefslogtreecommitdiff
path: root/nephilim/mpdsocket.py
diff options
context:
space:
mode:
Diffstat (limited to 'nephilim/mpdsocket.py')
-rw-r--r--nephilim/mpdsocket.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/nephilim/mpdsocket.py b/nephilim/mpdsocket.py
index 5cc9a60..df423b7 100644
--- a/nephilim/mpdsocket.py
+++ b/nephilim/mpdsocket.py
@@ -56,7 +56,7 @@ class MPDSocket(QtCore.QObject):
#### PUBLIC ####
def __init__(self, parent = None):
QtCore.QObject.__init__(self, parent)
- self._logger = logging.getLogger('%smpdsocket'%(unicode(parent) + "." if parent else ""))
+ self._logger = logging.getLogger('%smpdsocket'%(str(parent) + "." if parent else ""))
self._cmd_queue = []
self.version = (0, 0, 0)
@@ -104,7 +104,7 @@ class MPDSocket(QtCore.QObject):
which shall be called with an iterator over response lines as
an argument. Otherwise the response is silently discarded.
"""
- self._logger.debug('Executing command:' + ' '.join(map(unicode, args)))
+ self._logger.debug('Executing command:' + ' '.join(map(str, args)))
if 'callback' in kwargs:
if callable(kwargs['callback']):
callback = kwargs['callback']
@@ -121,11 +121,11 @@ class MPDSocket(QtCore.QObject):
self._cmd_queue.append((callback, report_errors))
if self._is_idle:
- self._sock.write('noidle\n')
- self._sock.write(args[0])
+ self._sock.write(b'noidle\n')
+ self._sock.write(args[0].encode('utf-8'))
for arg in args[1:]:
- self._sock.write((' "%s" '%self._escape(unicode(arg))).encode('utf-8'))
- self._sock.write('\n')
+ self._sock.write((' "%s" ' % self._escape(str(arg))).encode('utf-8'))
+ self._sock.write(b'\n')
def state(self):
"""
@@ -146,7 +146,7 @@ class MPDSocket(QtCore.QObject):
Read from the socket one line and return it, unless it's an
error or end of response.
"""
- line = str(self._sock.readLine()).decode('utf-8').rstrip('\n')
+ line = self._sock.readLine().data().decode('utf-8').rstrip('\n')
if line.startswith(self.ERROR_PREFIX):
if report_errors:
self._logger.error('MPD returned error: %s'%line)
@@ -170,9 +170,9 @@ class MPDSocket(QtCore.QObject):
# wait until we can read MPD hello
if not self._sock.canReadLine():
return
- line = str(self._sock.readLine())
+ line = self._sock.readLine().data().decode('utf-8')
if not line.startswith(self.HELLO_PREFIX):
- self.logger.error('Got invalid MPD hello: %s' % line)
+ self._logger.error('Got invalid MPD hello: %s' % line)
return self.disconnect_mpd()
self.version = tuple(map(int, line[len(self.HELLO_PREFIX):].strip().split('.')))
@@ -199,7 +199,7 @@ class MPDSocket(QtCore.QObject):
Enter idle mode.
"""
self._logger.debug('Entering idle mode.')
- self._sock.write('idle\n')
+ self._sock.write(b'idle\n')
self._is_idle = True
def _handle_response(self):
@@ -248,12 +248,12 @@ class MPDSocket(QtCore.QObject):
while self._sock.canReadLine():
line = self._readline(report_errors)
if not line:
- raise StopIteration
+ return
yield line
+
if not self._sock.canReadLine() and not self._sock.waitForReadyRead():
self._logger.error('Reading server response timed out, disconnecting.')
self.disconnect_mpd()
- raise StopIteration
def _parse_discard(self, data):
"""