From 68aaa5ace908bffd101de0e787de1cc73d462b4e Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 5 Mar 2025 01:15:07 -0500 Subject: [PATCH] Add support for RouterOS 7.18's `!empty` reply word See documentation at https://help.mikrotik.com/docs/spaces/ROS/pages/47579160/API#API-Replyword --- routeros_api/sentence.py | 2 +- tests/test_api_communicator.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/routeros_api/sentence.py b/routeros_api/sentence.py index 28fdbd0..ee77411 100644 --- a/routeros_api/sentence.py +++ b/routeros_api/sentence.py @@ -3,7 +3,7 @@ import re from routeros_api import exceptions from routeros_api import query -response_re = re.compile(rb'^!(re|trap|fatal|done)$') +response_re = re.compile(rb'^!(re|trap|fatal|empty|done)$') attribute_re = re.compile(rb'^=([^=]+)=(.*)$', re.DOTALL) tag_re = re.compile(rb'^\.tag=(.*)$') diff --git a/tests/test_api_communicator.py b/tests/test_api_communicator.py index 4bee354..b73683a 100644 --- a/tests/test_api_communicator.py +++ b/tests/test_api_communicator.py @@ -49,6 +49,14 @@ class TestCommunicator(TestCase): self.assertRaises(exceptions.RouterOsApiCommunicationError, promise.get) + def test_empty_call(self): + base = mock.Mock() + base.receive_sentence.side_effect = [[b'!empty', b'.tag=1'], + [b'!done', b'.tag=1']] + communicator = api_communicator.ApiCommunicator(base) + response = communicator.call('/file/', 'print').get() + self.assertEqual(response, []) + def test_query_call(self): base = mock.Mock() base.receive_sentence.return_value = [b'!done', b'.tag=1']