comparison sat/core/patches.py @ 2809:00d905e1b0ef

core (patches): partially fixed jid caching: jid caching in Twisted use a dict (__internJIDs) which associate a jid as string to its jid.JID instance. But this caching doesn't handle mutability of the objects, resulting wrong jid returned when a modification is done (e.g. if resource is changed). This is a temporary workaround until the patch is proposed and merged upstream. note: this is a partial fix because the caching is also leaking memory (cf. https://twistedmatrix.com/trac/ticket/5122)
author Goffi <goffi@goffi.org>
date Sun, 24 Feb 2019 14:09:44 +0100
parents 1ecceac3df96
children ab2696e34d29
comparison
equal deleted inserted replaced
2808:51c53fc4fc4a 2809:00d905e1b0ef
1 from twisted.words.protocols.jabber import xmlstream, sasl, client as tclient 1 import copy
2 from twisted.words.protocols.jabber import xmlstream, sasl, client as tclient, jid
2 from twisted.internet import ssl 3 from twisted.internet import ssl
3 from wokkel import client 4 from wokkel import client
4 from sat.core.constants import Const as C 5 from sat.core.constants import Const as C
5 from sat.core.log import getLogger 6 from sat.core.log import getLogger
6 7
137 tclient.IQAuthInitializer(self.xmlstream)) 138 tclient.IQAuthInitializer(self.xmlstream))
138 else: 139 else:
139 raise Exception("No available authentication method found") 140 raise Exception("No available authentication method found")
140 141
141 142
143 # jid fix
144
145 def internJID(jidstring):
146 """
147 Return interned JID.
148
149 @rtype: L{JID}
150 """
151 # XXX: this interJID return a copy of the cached jid
152 # this avoid modification of cached jid as JID is mutable
153 # TODO: propose this upstream
154
155 if jidstring in jid.__internJIDs:
156 return copy.copy(jid.__internJIDs[jidstring])
157 else:
158 j = jid.JID(jidstring)
159 jid.__internJIDs[jidstring] = j
160 return copy.copy(j)
161
162
142 def apply(): 163 def apply():
143 # certificate validation 164 # certificate validation
144 xmlstream.TLSInitiatingInitializer = TLSInitiatingInitializer 165 xmlstream.TLSInitiatingInitializer = TLSInitiatingInitializer
145 client.XMPPClient = XMPPClient 166 client.XMPPClient = XMPPClient
146 # XmlStream triggers 167 # XmlStream triggers
147 xmlstream.XmlStreamFactory.protocol = XmlStream 168 xmlstream.XmlStreamFactory.protocol = XmlStream
169 # jid fix
170 jid.internJID = internJID