fix #35 #lines not being filtered on python3

This commit is contained in:
Rossen Georgiev 2017-09-28 21:14:14 +01:00
parent b6d67fd66d
commit 39a9c0a1a4
2 changed files with 11 additions and 11 deletions

View File

@ -173,18 +173,18 @@ class IS(object):
if not self._connected:
raise ConnectionError("not connected to a server")
line = ''
line = b''
while True:
try:
for line in self._socket_readlines(blocking):
if line[0] != "#":
if line[0:1] != b'#':
if raw:
callback(line)
else:
callback(self._parse(line))
else:
self.logger.debug("Server: %s", line)
self.logger.debug("Server: %s", line.decode('utf8'))
except ParseError as exp:
self.logger.log(11, "%s\n Packet: %s", exp.message, exp.packet)
except UnknownFormat as exp:

View File

@ -338,32 +338,32 @@ class TC_IS_consumer(unittest.TestCase):
self.ais.consumer(callback=lambda: None, blocking=False)
def test_consumer_raw(self):
self.ais._socket_readlines(False).AndReturn(["line1"])
self.ais._socket_readlines(False).AndReturn([b"line1"])
self.m.ReplayAll()
def testcallback(line):
self.assertEqual(line, "line1")
self.assertEqual(line, b"line1")
self.ais.consumer(callback=testcallback, blocking=False, raw=True)
self.m.VerifyAll()
def test_consumer_blocking(self):
self.ais._socket_readlines(True).AndReturn(["line1"])
self.ais._socket_readlines(True).AndReturn(["line1"] * 5)
self.ais._socket_readlines(True).AndReturn([b"line1"])
self.ais._socket_readlines(True).AndReturn([b"line1"] * 5)
self.ais._socket_readlines(True).AndRaise(StopIteration)
self.m.ReplayAll()
def testcallback(line):
self.assertEqual(line, "line1")
self.assertEqual(line, b"line1")
self.ais.consumer(callback=testcallback, blocking=True, raw=True)
self.m.VerifyAll()
def test_consumer_parsed(self):
self.ais._socket_readlines(False).AndReturn(["line1"])
self.ais._parse("line1").AndReturn([])
self.ais._socket_readlines(False).AndReturn([b"line1"])
self.ais._parse(b"line1").AndReturn([])
self.m.ReplayAll()
def testcallback(line):
@ -374,7 +374,7 @@ class TC_IS_consumer(unittest.TestCase):
self.m.VerifyAll()
def test_consumer_serverline(self):
self.ais._socket_readlines(False).AndReturn(["# serverline"])
self.ais._socket_readlines(False).AndReturn([b"# serverline"])
self.m.ReplayAll()
def testcallback(line):