Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
Catch socket errors and rethrow as a GNTP Error
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm committed Dec 9, 2012
1 parent 68a3c7d commit c39f66f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions gntp/notifier.py
Expand Up @@ -14,6 +14,8 @@
import logging
import platform

import gntp.errors as errors

__all__ = [
'mini',
'GrowlNotifier',
Expand Down Expand Up @@ -179,11 +181,15 @@ def _send(self, messagetype, packet):

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(self.socketTimeout)
s.connect((self.hostname, self.port))
s.send(data)
recv_data = s.recv(1024)
while not recv_data.endswith("\r\n\r\n"):
recv_data += s.recv(1024)
try:
s.connect((self.hostname, self.port))
s.send(data)
recv_data = s.recv(1024)
while not recv_data.endswith("\r\n\r\n"):
recv_data += s.recv(1024)
except socket.error, e:
raise errors.NetworkError(e.message)

response = gntp.parse_gntp(recv_data)
s.close()

Expand Down

0 comments on commit c39f66f

Please sign in to comment.