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

Commit

Permalink
use proper string formatting in socketdisconnectederrors
Browse files Browse the repository at this point in the history
  • Loading branch information
emmettbutler committed Jul 19, 2017
1 parent 89ddfdb commit 4c41307
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pykafka/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def connect(self, timeout):
))
except (self._handler.SockErr, self._handler.GaiError):
log.info("Failed to connect to %s:%s", self.host, self.port)
raise SocketDisconnectedError("<broker %s:%s>" % (self.host, self.port))
raise SocketDisconnectedError("<broker {}:{}>".format(self.host, self.port))
log.debug("Successfully connected to %s:%s", self.host, self.port)

def disconnect(self):
Expand All @@ -193,13 +193,13 @@ def request(self, request):
"""Send a request over the socket connection"""
bytes_ = request.get_bytes()
if not self._socket:
raise SocketDisconnectedError("<broker %s:%s>" % (self.host, self.port))
raise SocketDisconnectedError("<broker {}:{}>".format(self.host, self.port))
try:
self._socket.sendall(bytes_)
except self._handler.SockErr as e:
log.error("Failed to send data, error: %s" % repr(e))
self.disconnect()
raise SocketDisconnectedError("<broker %s:%s>" % (self.host, self.port))
raise SocketDisconnectedError("<broker {}:{}>".format(self.host, self.port))

def response(self):
"""Wait for a response from the broker"""
Expand All @@ -213,13 +213,13 @@ def response(self):
if r is None or len(r) == 0:
# Happens when broker has shut down
self.disconnect()
raise SocketDisconnectedError("<broker %s:%s>" % (self.host, self.port))
raise SocketDisconnectedError("<broker {}:{}>".format(self.host, self.port))
size += r
size = struct.unpack('!i', size)[0]
try:
recvall_into(self._socket, self._buff, size)
except SocketDisconnectedError:
self.disconnect()
raise SocketDisconnectedError("<broker %s:%s>" % (self.host, self.port))
raise SocketDisconnectedError("<broker {}:{}>".format(self.host, self.port))
# Drop CorrelationId => int32
return buffer(self._buff[4:4 + size])

0 comments on commit 4c41307

Please sign in to comment.