diff src/plugins/plugin_xep_0234.py @ 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 c668081eba1c
line wrap: on
line diff
--- 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