Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0096.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | 9902ec2d8d9b |
children | beaf6bec2fcd |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
55 self.host.plugins["XEP-0095"].registerSIProfile(PROFILE_NAME, self.transferRequest) | 55 self.host.plugins["XEP-0095"].registerSIProfile(PROFILE_NAME, self.transferRequest) |
56 host.bridge.addMethod("sendFile", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self.sendFile) | 56 host.bridge.addMethod("sendFile", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self.sendFile) |
57 | 57 |
58 def profileConnected(self, profile): | 58 def profileConnected(self, profile): |
59 client = self.host.getClient(profile) | 59 client = self.host.getClient(profile) |
60 client._xep_0096_waiting_for_approval = {} #key = id, value = [transfer data, IdelayedCall Reactor timeout, | 60 client._xep_0096_waiting_for_approval = {} #key = id, value = [transfer data, IdelayedCall Reactor timeout, |
61 # current stream method, [failed stream methods], profile] | 61 # current stream method, [failed stream methods], profile] |
62 | 62 |
63 def _kill_id(self, approval_id, profile): | 63 def _kill_id(self, approval_id, profile): |
64 """Delete a waiting_for_approval id, called after timeout | 64 """Delete a waiting_for_approval id, called after timeout |
65 @param approval_id: id of _xep_0096_waiting_for_approval""" | 65 @param approval_id: id of _xep_0096_waiting_for_approval""" |
66 info(_("SI File Transfer: TimeOut reached for id %s") % approval_id) | 66 info(_("SI File Transfer: TimeOut reached for id %s") % approval_id) |
67 try: | 67 try: |
68 client = self.host.getClient(profile) | 68 client = self.host.getClient(profile) |
69 del client._xep_0096_waiting_for_approval[approval_id] | 69 del client._xep_0096_waiting_for_approval[approval_id] |
70 except KeyError: | 70 except KeyError: |
71 warning(_("kill id called on a non existant approval id")) | 71 warning(_("kill id called on a non existant approval id")) |
72 | 72 |
73 def transferRequest(self, iq_id, from_jid, si_id, si_mime_type, si_el, profile): | 73 def transferRequest(self, iq_id, from_jid, si_id, si_mime_type, si_el, profile): |
74 """Called when a file transfer is requested | 74 """Called when a file transfer is requested |
75 @param iq_id: id of the iq request | 75 @param iq_id: id of the iq request |
76 @param from_jid: jid of the sender | 76 @param from_jid: jid of the sender |
77 @param si_id: Stream Initiation session id | 77 @param si_id: Stream Initiation session id |
89 file_hash = None | 89 file_hash = None |
90 file_desc = "" | 90 file_desc = "" |
91 can_range = False | 91 can_range = False |
92 file_elts = filter(lambda elt: elt.name == 'file', si_el.elements()) | 92 file_elts = filter(lambda elt: elt.name == 'file', si_el.elements()) |
93 feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_el) | 93 feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_el) |
94 | 94 |
95 if file_elts: | 95 if file_elts: |
96 file_el = file_elts[0] | 96 file_el = file_elts[0] |
97 filename = file_el["name"] | 97 filename = file_el["name"] |
98 file_size = file_el["size"] | 98 file_size = file_el["size"] |
99 file_date = file_el.getAttribute("date", "") | 99 file_date = file_el.getAttribute("date", "") |
106 can_range = True | 106 can_range = True |
107 else: | 107 else: |
108 warning(_("No file element found")) | 108 warning(_("No file element found")) |
109 self.host.plugins["XEP-0095"].sendBadRequestError(iq_id, from_jid, profile) | 109 self.host.plugins["XEP-0095"].sendBadRequestError(iq_id, from_jid, profile) |
110 return | 110 return |
111 | 111 |
112 if feature_elts: | 112 if feature_elts: |
113 feature_el = feature_elts[0] | 113 feature_el = feature_elts[0] |
114 form = data_form.Form.fromElement(feature_el.firstChildElement()) | 114 form = data_form.Form.fromElement(feature_el.firstChildElement()) |
115 try: | 115 try: |
116 stream_method = self.host.plugins["XEP-0020"].negociate(feature_el, 'stream-method',self.managed_stream_m) | 116 stream_method = self.host.plugins["XEP-0020"].negociate(feature_el, 'stream-method',self.managed_stream_m) |
236 | 236 |
237 feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_elt) | 237 feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_elt) |
238 if not feature_elts: | 238 if not feature_elts: |
239 warning(_("No feature element")) | 239 warning(_("No feature element")) |
240 return | 240 return |
241 | 241 |
242 choosed_options = self.host.plugins["XEP-0020"].getChoosedOptions(feature_elts[0]) | 242 choosed_options = self.host.plugins["XEP-0020"].getChoosedOptions(feature_elts[0]) |
243 try: | 243 try: |
244 stream_method = choosed_options["stream-method"] | 244 stream_method = choosed_options["stream-method"] |
245 except KeyError: | 245 except KeyError: |
246 warning(_("No stream method choosed")) | 246 warning(_("No stream method choosed")) |
279 profile = self.host.memory.getProfileName(profile_key) | 279 profile = self.host.memory.getProfileName(profile_key) |
280 if not profile: | 280 if not profile: |
281 warning(_("Trying to send a file from an unknown profile")) | 281 warning(_("Trying to send a file from an unknown profile")) |
282 return "" | 282 return "" |
283 feature_elt = self.host.plugins["XEP-0020"].proposeFeatures({'stream-method': self.managed_stream_m}) | 283 feature_elt = self.host.plugins["XEP-0020"].proposeFeatures({'stream-method': self.managed_stream_m}) |
284 | 284 |
285 file_transfer_elts = [] | 285 file_transfer_elts = [] |
286 | 286 |
287 statinfo = os.stat(filepath) | 287 statinfo = os.stat(filepath) |
288 file_elt = domish.Element((PROFILE, 'file')) | 288 file_elt = domish.Element((PROFILE, 'file')) |
289 file_elt['name']=os.path.basename(filepath) | 289 file_elt['name']=os.path.basename(filepath) |
290 size = file_elt['size']=str(statinfo.st_size) | 290 size = file_elt['size']=str(statinfo.st_size) |
291 file_transfer_elts.append(file_elt) | 291 file_transfer_elts.append(file_elt) |