def recv_until(sock, suffix):
 message = sock.recv(4096)
 if (not message):
  raise EOFError('socket closed')
 while (not message.endswith(suffix)):
  data = sock.recv(4096)
  if (not data):
   raise IOError('received {!r} then socket closed'.format(message))
  message += data
 return message

def recv_until ( sock , suffix ) : message = sock . recv ( 4096 ) if ( not message ) : raise EOFError ( 'socket closed' ) while ( not message . endswith ( suffix ) ) : data = sock . recv ( 4096 ) if ( not data ) : raise IOError ( 'received {!r} then socket closed' . format ( message ) ) message += data return message
receive bytes over socket sock until we receive the suffix .