code: def _check_mode(stream):
      
      mode = getattr(stream, "mode", None)
  
      if isinstance(stream, gzip.GzipFile):
          if mode != gzip.READ:
              raise ValueError(
                  "Cannot upload gzip files opened in write mode:  use "
                  "gzip.GzipFile(filename, mode='rb')"
              )
      else:
          if mode is not None and mode not in ("rb", "r+b", "rb+"):
              raise ValueError(
                  "Cannot upload files opened in text mode:  use "
                  "open(filename, mode='rb') or open(filename, mode='r+b')"
              )
docs: Check that a stream was opened in read-binary mode.
  
      :type stream: IO[bytes]
      :param stream: A bytes IO object open for reading.
  
      :raises: :exc:`ValueError` if the ``stream.mode`` is a valid attribute
               and is not among ``rb``, ``r+b`` or ``rb+``.