Skip to content

Commit

Permalink
fix #35 #lines not being filtered on python3
Browse files Browse the repository at this point in the history
  • Loading branch information
rossengeorgiev committed Sep 28, 2017
1 parent b6d67fd commit 39a9c0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions aprslib/inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,18 @@ def consumer(self, callback, blocking=True, immortal=False, raw=False):
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:
Expand Down
16 changes: 8 additions & 8 deletions tests/test_IS.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,32 +338,32 @@ def test_consumer_notconnected(self):
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):
Expand All @@ -374,7 +374,7 @@ def testcallback(line):
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):
Expand Down

0 comments on commit 39a9c0a

Please sign in to comment.