plugins XEP-0234, file: use of SatFile for writing too

This commit is contained in:
Goffi 2015-11-08 14:44:33 +01:00
commit 5e356f28f0
2 changed files with 18 additions and 4 deletions

View file

@ -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:

View file

@ -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