def _read_bytes(fp, size, error_template='ran out of data'):
 data = bytes()
 while True:
  try:
   r = fp.read((size - len(data)))
   data += r
   if ((len(r) == 0) or (len(data) == size)):
    break
  except io.BlockingIOError:
   pass
 if (len(data) != size):
  msg = 'EOF: reading %s, expected %d bytes got %d'
  raise ValueError((msg % (error_template, size, len(data))))
 else:
  return data

def _read_bytes ( fp , size , error_template = 'ran out of data' ) : data = bytes ( ) while True : try : r = fp . read ( ( size - len ( data ) ) ) data += r if ( ( len ( r ) == 0 ) or ( len ( data ) == size ) ) : break except io . BlockingIOError : pass if ( len ( data ) != size ) : msg = 'EOF: reading %s, expected %d bytes got %d' raise ValueError ( ( msg % ( error_template , size , len ( data ) ) ) ) else : return data
read from file-like object until size bytes are read .