def read_exactly(socket, n):
 data = six.binary_type()
 while (len(data) < n):
  next_data = read(socket, (n - len(data)))
  if (not next_data):
   raise SocketError('Unexpected EOF')
  data += next_data
 return data

def read_exactly ( socket , n ) : data = six . binary_type ( ) while ( len ( data ) < n ) : next_data = read ( socket , ( n - len ( data ) ) ) if ( not next_data ) : raise SocketError ( 'Unexpected EOF' ) data += next_data return data
reads exactly n bytes from socket raises socketerror if there isnt enough data .