Don't use command_list as both bool and list (#211)

This commit is contained in:
Stein Magnus Jodal 2012-10-17 01:43:22 +02:00
parent 65b550eb44
commit 8683537816
3 changed files with 24 additions and 13 deletions

View File

@ -22,8 +22,9 @@ class MpdDispatcher(object):
def __init__(self, session=None, core=None):
self.authenticated = False
self.command_list = False
self.command_list_receiving = False
self.command_list_ok = False
self.command_list = []
self.command_list_index = None
self.context = MpdContext(self, session=session, core=core)
@ -108,8 +109,7 @@ class MpdDispatcher(object):
def _is_receiving_command_list(self, request):
return (
self.command_list is not False and
request != u'command_list_end')
self.command_list_receiving and request != u'command_list_end')
def _is_processing_command_list(self, request):
return (

View File

@ -19,18 +19,19 @@ def command_list_begin(context):
returned. If ``command_list_ok_begin`` is used, ``list_OK`` is
returned for each successful command executed in the command list.
"""
context.dispatcher.command_list = []
context.dispatcher.command_list_receiving = True
context.dispatcher.command_list_ok = False
context.dispatcher.command_list = []
@handle_request(r'^command_list_end$')
def command_list_end(context):
"""See :meth:`command_list_begin()`."""
if context.dispatcher.command_list is False:
# Test for False exactly, and not e.g. empty list
if not context.dispatcher.command_list_receiving:
raise MpdUnknownCommand(command='command_list_end')
context.dispatcher.command_list_receiving = False
(command_list, context.dispatcher.command_list) = (
context.dispatcher.command_list, False)
context.dispatcher.command_list, [])
(command_list_ok, context.dispatcher.command_list_ok) = (
context.dispatcher.command_list_ok, False)
command_list_response = []
@ -49,5 +50,6 @@ def command_list_end(context):
@handle_request(r'^command_list_ok_begin$')
def command_list_ok_begin(context):
"""See :meth:`command_list_begin()`."""
context.dispatcher.command_list = []
context.dispatcher.command_list_receiving = True
context.dispatcher.command_list_ok = True
context.dispatcher.command_list = []

View File

@ -18,13 +18,18 @@ class CommandListsTest(protocol.BaseTestCase):
def test_command_list_with_ping(self):
self.sendRequest(u'command_list_begin')
self.assertTrue(self.dispatcher.command_list_receiving)
self.assertFalse(self.dispatcher.command_list_ok)
self.assertEqual([], self.dispatcher.command_list)
self.assertEqual(False, self.dispatcher.command_list_ok)
self.sendRequest(u'ping')
self.assertIn(u'ping', self.dispatcher.command_list)
self.sendRequest(u'command_list_end')
self.assertInResponse(u'OK')
self.assertEqual(False, self.dispatcher.command_list)
self.assertFalse(self.dispatcher.command_list_receiving)
self.assertFalse(self.dispatcher.command_list_ok)
self.assertEqual([], self.dispatcher.command_list)
def test_command_list_with_error_returns_ack_with_correct_index(self):
self.sendRequest(u'command_list_begin')
@ -39,15 +44,19 @@ class CommandListsTest(protocol.BaseTestCase):
def test_command_list_ok_with_ping(self):
self.sendRequest(u'command_list_ok_begin')
self.assertTrue(self.dispatcher.command_list_receiving)
self.assertTrue(self.dispatcher.command_list_ok)
self.assertEqual([], self.dispatcher.command_list)
self.assertEqual(True, self.dispatcher.command_list_ok)
self.sendRequest(u'ping')
self.assertIn(u'ping', self.dispatcher.command_list)
self.sendRequest(u'command_list_end')
self.assertInResponse(u'list_OK')
self.assertInResponse(u'OK')
self.assertEqual(False, self.dispatcher.command_list)
self.assertEqual(False, self.dispatcher.command_list_ok)
self.assertFalse(self.dispatcher.command_list_receiving)
self.assertFalse(self.dispatcher.command_list_ok)
self.assertEqual([], self.dispatcher.command_list)
# FIXME this should also include the special handling of idle within a
# command list. That is that once a idle/noidle command is found inside a