code: def verify_fileobj(fileobj, writable=False):
      
  
      try:
          data = fileobj.read(0)
      except Exception:
          if not hasattr(fileobj, "read"):
              raise ValueError("%r not a valid file object" % fileobj)
          raise ValueError("Can't read from file object %r" % fileobj)
  
      if not isinstance(data, bytes):
          raise ValueError(
              "file object %r not opened in binary mode" % fileobj)
  
      if writable:
          try:
              fileobj.write(b"")
          except Exception:
              if not hasattr(fileobj, "write"):
                  raise ValueError("%r not a valid file object" % fileobj)
              raise ValueError("Can't write to file object %r" % fileobj)
docs: Verifies that the passed fileobj is a file like object which
      we can use.
  
      Args:
          writable (bool): verify that the file object is writable as well
  
      Raises:
          ValueError: In case the object is not a file object that is readable
              (or writable if required) or is not opened in bytes mode.