Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0096.py @ 941:c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 28 Mar 2014 18:07:02 +0100 |
parents | 1a759096ccbd |
children | 301b342c697a |
comparison
equal
deleted
inserted
replaced
940:92e41e7c7e00 | 941:c6d8fc63b1db |
---|---|
23 from twisted.words.xish import domish | 23 from twisted.words.xish import domish |
24 from twisted.words.protocols.jabber import jid | 24 from twisted.words.protocols.jabber import jid |
25 from twisted.words.protocols.jabber import error as jab_error | 25 from twisted.words.protocols.jabber import error as jab_error |
26 import os | 26 import os |
27 from twisted.internet import reactor | 27 from twisted.internet import reactor |
28 from sat.core.exceptions import ProfileNotInCacheError | |
29 | 28 |
30 from wokkel import data_form | 29 from wokkel import data_form |
31 | 30 |
32 IQ_SET = '/iq[@type="set"]' | 31 IQ_SET = '/iq[@type="set"]' |
33 PROFILE_NAME = "file-transfer" | 32 PROFILE_NAME = "file-transfer" |
79 @param si_el: domish.Element of the request | 78 @param si_el: domish.Element of the request |
80 @param profile: %(doc_profile)s""" | 79 @param profile: %(doc_profile)s""" |
81 info(_("XEP-0096 file transfer requested")) | 80 info(_("XEP-0096 file transfer requested")) |
82 debug(si_el.toXml()) | 81 debug(si_el.toXml()) |
83 client = self.host.getClient(profile) | 82 client = self.host.getClient(profile) |
84 if not client: | |
85 raise ProfileNotInCacheError | |
86 filename = "" | 83 filename = "" |
87 file_size = "" | 84 file_size = "" |
88 file_date = None | 85 file_date = None |
89 file_hash = None | 86 file_hash = None |
90 file_desc = "" | 87 file_desc = "" |
109 self.host.plugins["XEP-0095"].sendBadRequestError(iq_id, from_jid, profile) | 106 self.host.plugins["XEP-0095"].sendBadRequestError(iq_id, from_jid, profile) |
110 return | 107 return |
111 | 108 |
112 if feature_elts: | 109 if feature_elts: |
113 feature_el = feature_elts[0] | 110 feature_el = feature_elts[0] |
114 form = data_form.Form.fromElement(feature_el.firstChildElement()) | 111 data_form.Form.fromElement(feature_el.firstChildElement()) |
115 try: | 112 try: |
116 stream_method = self.host.plugins["XEP-0020"].negociate(feature_el, 'stream-method', self.managed_stream_m) | 113 stream_method = self.host.plugins["XEP-0020"].negociate(feature_el, 'stream-method', self.managed_stream_m) |
117 except KeyError: | 114 except KeyError: |
118 warning(_("No stream method found")) | 115 warning(_("No stream method found")) |
119 self.host.plugins["XEP-0095"].sendBadRequestError(iq_id, from_jid, profile) | 116 self.host.plugins["XEP-0095"].sendBadRequestError(iq_id, from_jid, profile) |
144 """Called on confirmation answer | 141 """Called on confirmation answer |
145 @param sid: file transfer session id | 142 @param sid: file transfer session id |
146 @param accepted: True if file transfer is accepted | 143 @param accepted: True if file transfer is accepted |
147 @param frontend_data: data sent by frontend""" | 144 @param frontend_data: data sent by frontend""" |
148 client = self.host.getClient(profile) | 145 client = self.host.getClient(profile) |
149 if not client: | |
150 raise ProfileNotInCacheError | |
151 data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid] | 146 data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid] |
152 can_range = data['can_range'] == "True" | 147 can_range = data['can_range'] == "True" |
153 range_offset = 0 | 148 range_offset = 0 |
154 if accepted: | 149 if accepted: |
155 if timeout.active(): | 150 if timeout.active(): |
190 | 185 |
191 def _transferSucceeded(self, sid, file_obj, stream_method, profile): | 186 def _transferSucceeded(self, sid, file_obj, stream_method, profile): |
192 """Called by the stream method when transfer successfuly finished | 187 """Called by the stream method when transfer successfuly finished |
193 @param id: stream id""" | 188 @param id: stream id""" |
194 client = self.host.getClient(profile) | 189 client = self.host.getClient(profile) |
195 if not client: | |
196 raise ProfileNotInCacheError | |
197 file_obj.close() | 190 file_obj.close() |
198 info(_('Transfer %s successfuly finished') % sid) | 191 info(_('Transfer %s successfuly finished') % sid) |
199 del(client._xep_0096_waiting_for_approval[sid]) | 192 del(client._xep_0096_waiting_for_approval[sid]) |
200 | 193 |
201 def _transferFailed(self, sid, file_obj, stream_method, reason, profile): | 194 def _transferFailed(self, sid, file_obj, stream_method, reason, profile): |
202 """Called when something went wrong with the transfer | 195 """Called when something went wrong with the transfer |
203 @param id: stream id | 196 @param id: stream id |
204 @param reason: can be TIMEOUT, IO_ERROR, PROTOCOL_ERROR""" | 197 @param reason: can be TIMEOUT, IO_ERROR, PROTOCOL_ERROR""" |
205 client = self.host.getClient(profile) | 198 client = self.host.getClient(profile) |
206 if not client: | |
207 raise ProfileNotInCacheError | |
208 data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid] | 199 data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid] |
209 warning(_('Transfer %(id)s failed with stream method %(s_method)s: %(reason)s') % { | 200 warning(_('Transfer %(id)s failed with stream method %(s_method)s: %(reason)s') % { |
210 'id': sid, | 201 'id': sid, |
211 's_method': stream_method, | 202 's_method': stream_method, |
212 'reason': reason}) | 203 'reason': reason}) |