Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(self):
try:
while not self._halt.is_set():
try:
self._send_heartbeat()
except TimeoutError:
pass
if self._adrenaline.is_set():
interval_in_seconds = self._hurry_interval_in_seconds
else:
interval_in_seconds = self._relax_interval_in_seconds
self._rest.wait(interval_in_seconds)
except ConnectionError:
logging.debug("[heartbeat connection error]")
def disconnect(self, path=""):
if not path or not self._opened:
self._close()
elif path:
socketIO_packet_type = 1
socketIO_packet_data, _ = format_socketIO_packet_data(path)
try:
self._message(str(socketIO_packet_type) + socketIO_packet_data)
except (TimeoutError, ConnectionError):
pass
try:
namespace = self._namespace_by_path.pop(path)
namespace.on_disconnect()
except KeyError:
pass
def get_response(request, *args, **kw):
try:
response = request(*args, stream=True, **kw)
except requests.exceptions.Timeout as e:
raise TimeoutError(e)
except requests.exceptions.ConnectionError as e:
raise ConnectionError(e)
except requests.exceptions.SSLError as e:
raise ConnectionError("could not negotiate SSL (%s)" % e)
status_code = response.status_code
if 200 != status_code:
raise ConnectionError(
"unexpected status code (%s %s)" % (status_code, response.text)
)
return response
def send_packet(self, engineIO_packet_type, engineIO_packet_data=""):
packet = format_packet_text(engineIO_packet_type, engineIO_packet_data)
try:
self._connection.send(packet)
except websocket.WebSocketTimeoutException as e:
raise TimeoutError("send timed out (%s)" % e)
except socket.error as e:
raise ConnectionError("send disconnected (%s)" % e)
except websocket.WebSocketConnectionClosedException as e:
raise ConnectionError("send disconnected (%s)" % e)
def recv_packet(self):
try:
packet_text = self._connection.recv()
except websocket.WebSocketTimeoutException as e:
raise TimeoutError("recv timed out (%s)" % e)
except SSLError as e:
raise ConnectionError("recv disconnected by SSL (%s)" % e)
except websocket.WebSocketConnectionClosedException as e:
raise ConnectionError("recv disconnected (%s)" % e)
except socket.error as e:
raise ConnectionError("recv disconnected (%s)" % e)
if not isinstance(packet_text, six.binary_type):
packet_text = six.b(packet_text)
engineIO_packet_type, engineIO_packet_data = parse_packet_text(packet_text)
yield engineIO_packet_type, engineIO_packet_data