code: def _read_bytes(fp, size, error_template="ran out of data"):
      """Read from file-like object until size bytes are read.
  
      TODO python2_drop: is it still needed? The docstring mentions python 2.6
      and it looks like this can be at least simplified ...
  
      Raises ValueError if not EOF is encountered before size bytes are read.
      Non-blocking objects only supported if they derive from io objects.
  
      Required as e.g. ZipExtFile in python 2.6 can return less data than
      requested.
  
      This function was taken from numpy/lib/format.py in version 1.10.2.
  
      Parameters
      ----------
      fp: file-like object
      size: int
      error_template: str
  
      Returns
      -------
      a bytes object
          The data read in bytes.
  
      """
      data = bytes()
      while True:
          # io files (default in python3) return None or raise on
          # would-block, python2 file will truncate, probably nothing can be
          # done about that.  note that regular files can't be non-blocking
          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
  
file_path: catboost/contrib/python/joblib/joblib/numpy_pickle_utils.py
imports: import pickle
  import io
  import sys
  import warnings
  import contextlib
  from .compressor import _ZFILE_PREFIX
  from .compressor import _COMPRESSORS
label_desc: Use image node_id 10 for calling a global function with example usage: _read_bytes(fp, size, error_template) and returns: data