diff src/plugins/plugin_xep_0065.py @ 1757:abd6d6f89006

plugins XEP-0065, XEP-0260: fixed session creation order: session is created earlied, and file object associated in a second time if needed
author Goffi <goffi@goffi.org>
date Thu, 17 Dec 2015 22:37:58 +0100
parents 244a605623d6
children a66d34353f34
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0065.py	Thu Dec 17 22:37:56 2015 +0100
+++ b/src/plugins/plugin_xep_0065.py	Thu Dec 17 22:37:58 2015 +0100
@@ -1148,7 +1148,8 @@
         """Create a session_data associated to hash
 
         @param session_hash(str): hash of the session
-        @param file_obj(file): file-like object
+        @param file_obj(file, None): file-like object
+            None if it will be filled later
         @param profile: %(doc_profile)s
         return (dict): session data
         """
@@ -1157,10 +1158,13 @@
         session_d = defer.Deferred()
         session_d.addBoth(self.killSession, session_hash, None, client)
         session_data = client._s5b_sessions[session_hash] = {
-            "file": file_obj,
             DEFER_KEY: session_d,
             TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client),
             }
+
+        if file_obj is not None:
+            session_data['file'] = file_obj
+
         if session_hash in self.hash_profiles_map:
             # The only case when 2 profiles want to register the same hash
             # is when they are on the same instance
@@ -1181,6 +1185,12 @@
 
         return session_data
 
+    def associateFileObj(self, session_hash, file_obj, profile):
+        """Associate a file obj with  a session"""
+        session_data = self.getSession(session_hash, profile)
+        assert 'file' not in session_data
+        session_data['file'] = file_obj
+
     def streamQuery(self, iq_elt, profile):
         log.debug(u"BS stream query")
         client = self.host.getClient(profile)