IS: added connection related logger lines
This commit is contained in:
parent
7f9c7816b1
commit
18be87d460
|
|
@ -114,10 +114,11 @@ class IS(object):
|
|||
self._connect()
|
||||
self._send_login()
|
||||
break
|
||||
except:
|
||||
except (LoginError, ConnectionError):
|
||||
if not blocking:
|
||||
raise
|
||||
|
||||
self.logger.info("Retrying connection is %d seconds." % retry)
|
||||
time.sleep(retry)
|
||||
|
||||
def close(self):
|
||||
|
|
@ -252,12 +253,14 @@ class IS(object):
|
|||
else:
|
||||
raise ConnectionError("invalid banner from server")
|
||||
|
||||
except ConnectionError:
|
||||
except ConnectionError as e:
|
||||
self.logger.error(str(e))
|
||||
self.close()
|
||||
raise
|
||||
except (socket.error, socket.timeout) as e:
|
||||
self.close()
|
||||
|
||||
self.logger.error("Socket error: %s" % str(e))
|
||||
if str(e) == "timed out":
|
||||
raise ConnectionError("no banner from server")
|
||||
else:
|
||||
|
|
@ -303,12 +306,14 @@ class IS(object):
|
|||
else:
|
||||
self.logger.info("Login successful")
|
||||
|
||||
except LoginError:
|
||||
except LoginError as e:
|
||||
self.logger.error(str(e))
|
||||
self.close()
|
||||
raise
|
||||
except:
|
||||
self.close()
|
||||
raise LoginError("failed to login")
|
||||
self.logger.error("Failed to login")
|
||||
raise LoginError("Failed to login")
|
||||
|
||||
def _socket_readlines(self, blocking=False):
|
||||
"""
|
||||
|
|
@ -317,6 +322,7 @@ class IS(object):
|
|||
try:
|
||||
self.sock.setblocking(0)
|
||||
except socket.error as e:
|
||||
self.logger.error("socket error when setblocking(0): %s" % str(e))
|
||||
raise ConnectionDrop("connection dropped")
|
||||
|
||||
while True:
|
||||
|
|
@ -330,8 +336,10 @@ class IS(object):
|
|||
|
||||
# sock.recv returns empty if the connection drops
|
||||
if not short_buf:
|
||||
self.logger.error("socket.recv(): returned empty")
|
||||
raise ConnectionDrop("connection dropped")
|
||||
except socket.error as e:
|
||||
self.logger.error("socket error on recv(): %s" % str(e))
|
||||
if "Resource temporarily unavailable" in str(e):
|
||||
if not blocking:
|
||||
if len(self.buf) == 0:
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ except ImportError:
|
|||
return {'confidence': 0.0, 'encoding': 'windows-1252'}
|
||||
|
||||
from .exceptions import (UnknownFormat, ParseError)
|
||||
from . import base91, string_type_parse, is_py3
|
||||
from . import base91, string_type_parse
|
||||
|
||||
__all__ = ['parse']
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ def parse(packet):
|
|||
"""
|
||||
|
||||
if not isinstance(packet, string_type_parse):
|
||||
raise TypeError("Epected packet to be str/unicode/bytes, got %s", type(packet))
|
||||
raise TypeError("Expected packet to be str/unicode/bytes, got %s", type(packet))
|
||||
|
||||
# attempt to detect encoding
|
||||
if isinstance(packet, bytes):
|
||||
|
|
|
|||
|
|
@ -252,9 +252,9 @@ class TC_IS(unittest.TestCase):
|
|||
def test_connect_raising_exceptions(self):
|
||||
self.m.StubOutWithMock(self.ais, "_connect")
|
||||
self.m.StubOutWithMock(self.ais, "_send_login")
|
||||
self.ais._connect().AndRaise(Exception("first"))
|
||||
self.ais._connect().AndRaise(aprslib.exceptions.ConnectionError("first"))
|
||||
self.ais._connect()
|
||||
self.ais._send_login().AndRaise(Exception("second"))
|
||||
self.ais._send_login().AndRaise(aprslib.exceptions.LoginError("second"))
|
||||
self.ais._connect()
|
||||
self.ais._send_login()
|
||||
self.m.ReplayAll()
|
||||
|
|
|
|||
Loading…
Reference in New Issue