# HG changeset patch # User Goffi # Date 1446990273 -3600 # Node ID 1f7a34d499e08228cba481c4d1f4025b5ad61a25 # Parent 268fda4236cabeb535f3f07808e94dcb8af56c8b plugins XEP-0234, file: use of SatFile for writing too diff -r 268fda4236ca -r 1f7a34d499e0 src/plugins/plugin_misc_file.py --- a/src/plugins/plugin_misc_file.py Sun Nov 08 14:44:33 2015 +0100 +++ b/src/plugins/plugin_misc_file.py Sun Nov 08 14:44:33 2015 +0100 @@ -65,6 +65,12 @@ self._file.close() self.host.removeProgressCb(self.uid, self.profile) + def flush(self): + self._file.flush() + + def write(self, buf): + self._file.write(buf) + def read(self, size=-1): read = self._file.read(size) if not read: diff -r 268fda4236ca -r 1f7a34d499e0 src/plugins/plugin_xep_0234.py --- a/src/plugins/plugin_xep_0234.py Sun Nov 08 14:44:33 2015 +0100 +++ b/src/plugins/plugin_xep_0234.py Sun Nov 08 14:44:33 2015 +0100 @@ -101,6 +101,16 @@ d.addCallback(self._gotConfirmation, session, content_data, application_data, profile) return d + def _openFileWrite(self, content_data, file_path, file_data, profile): + assert 'file_obj' not in content_data + content_data['file_obj'] = self._f.File( + self.host, + file_path, + 'w', + size=file_data['size'], + profile=profile, + ) + def _gotConfirmation(self, data, session, content_data, application_data, profile): """Called when the permission and dest path have been received @@ -120,8 +130,7 @@ if os.path.exists(file_path): def check_overwrite(overwrite): if overwrite: - assert 'file_obj' not in content_data - content_data['file_obj'] = open(file_path, 'w') + self._openFileWrite(content_data, file_path, file_data, profile) return True else: return self._getDestDir(session, content_data, profile) @@ -134,8 +143,7 @@ exists_d.addCallback(check_overwrite) return exists_d - assert 'file_obj' not in content_data - content_data['file_obj'] = open(file_path, 'w') + self._openFileWrite(content_data, file_path, file_data, profile) return True # jingle callbacks