Mercurial > libervia-backend
changeset 1568:1f7a34d499e0
plugins XEP-0234, file: use of SatFile for writing too
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 08 Nov 2015 14:44:33 +0100 |
parents | 268fda4236ca |
children | 44854fb5d3b2 |
files | src/plugins/plugin_misc_file.py src/plugins/plugin_xep_0234.py |
diffstat | 2 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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