code: def setcontents(self, source, **kwargs):
          
          if isinstance(source, six.string_types):
              _file = opener.open(source, 'rb')
          else:
              _file = source
  
          # signals.document_before_content_set.send(self)
  
          data = _file.read()
          _fs, filename = opener.parse(self.uri)
          _fs.setcontents(filename, data, **kwargs)
          _fs.close()
  
          # signals.document_after_content_set.send(self)
  
          if isinstance(source, six.string_types) and hasattr(_file, 'close'):
              _file.close()
docs: Create a new file from a string or file-like object.