From 5e356f28f0c105da1204d9a1fd4f3fff5390fc52 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 8 Nov 2015 14:44:33 +0100 Subject: [PATCH] plugins XEP-0234, file: use of SatFile for writing too --- src/plugins/plugin_misc_file.py | 6 ++++++ src/plugins/plugin_xep_0234.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/plugins/plugin_misc_file.py b/src/plugins/plugin_misc_file.py index 6cd25bca..28d40f8f 100644 --- a/src/plugins/plugin_misc_file.py +++ b/src/plugins/plugin_misc_file.py @@ -65,6 +65,12 @@ class SatFile(object): 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 --git a/src/plugins/plugin_xep_0234.py b/src/plugins/plugin_xep_0234.py index 40b567af..4f09aa57 100644 --- a/src/plugins/plugin_xep_0234.py +++ b/src/plugins/plugin_xep_0234.py @@ -101,6 +101,16 @@ class XEP_0234(object): 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 @@ class XEP_0234(object): 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 @@ class XEP_0234(object): 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