summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slixmpp/basexmpp.py6
-rw-r--r--slixmpp/features/feature_bind/bind.py2
-rw-r--r--slixmpp/jid.py73
-rw-r--r--slixmpp/plugins/xep_0078/legacyauth.py5
4 files changed, 23 insertions, 63 deletions
diff --git a/slixmpp/basexmpp.py b/slixmpp/basexmpp.py
index f60ba560..80699319 100644
--- a/slixmpp/basexmpp.py
+++ b/slixmpp/basexmpp.py
@@ -57,12 +57,12 @@ class BaseXMPP(XMLStream):
self.stream_id = None
#: The JabberID (JID) requested for this connection.
- self.requested_jid = JID(jid, cache_lock=True)
+ self.requested_jid = JID(jid)
#: The JabberID (JID) used by this connection,
#: as set after session binding. This may even be a
#: different bare JID than what was requested.
- self.boundjid = JID(jid, cache_lock=True)
+ self.boundjid = JID(jid)
self._expected_server_name = self.boundjid.host
self._redirect_attempts = 0
@@ -638,7 +638,7 @@ class BaseXMPP(XMLStream):
def set_jid(self, jid):
"""Rip a JID apart and claim it as our own."""
log.debug("setting jid to %s", jid)
- self.boundjid = JID(jid, cache_lock=True)
+ self.boundjid = JID(jid)
def getjidresource(self, fulljid):
if '/' in fulljid:
diff --git a/slixmpp/features/feature_bind/bind.py b/slixmpp/features/feature_bind/bind.py
index 25c99948..c031ab72 100644
--- a/slixmpp/features/feature_bind/bind.py
+++ b/slixmpp/features/feature_bind/bind.py
@@ -52,7 +52,7 @@ class FeatureBind(BasePlugin):
iq.send(callback=self._on_bind_response)
def _on_bind_response(self, response):
- self.xmpp.boundjid = JID(response['bind']['jid'], cache_lock=True)
+ self.xmpp.boundjid = JID(response['bind']['jid'])
self.xmpp.bound = True
self.xmpp.event('session_bind', self.xmpp.boundjid)
self.xmpp.session_bind_event.set()
diff --git a/slixmpp/jid.py b/slixmpp/jid.py
index 8a1530c3..715a8892 100644
--- a/slixmpp/jid.py
+++ b/slixmpp/jid.py
@@ -16,13 +16,11 @@ from __future__ import unicode_literals
import re
import socket
import stringprep
-import threading
import encodings.idna
from copy import deepcopy
from slixmpp.util import stringprep_profiles
-from collections import OrderedDict
#: These characters are not allowed to appear in a JID.
ILLEGAL_CHARS = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r' + \
@@ -69,25 +67,6 @@ JID_UNESCAPE_TRANSFORMATIONS = {'\\20': ' ',
'\\40': '@',
'\\5c': '\\'}
-JID_CACHE = OrderedDict()
-JID_CACHE_LOCK = threading.Lock()
-JID_CACHE_MAX_SIZE = 1024
-
-def _cache(key, parts, locked):
- JID_CACHE[key] = (parts, locked)
- if len(JID_CACHE) > JID_CACHE_MAX_SIZE:
- with JID_CACHE_LOCK:
- while len(JID_CACHE) > JID_CACHE_MAX_SIZE:
- found = None
- for key, item in JID_CACHE.items():
- if not item[1]: # if not locked
- found = key
- break
- if not found: # more than MAX_SIZE locked
- # warn?
- break
- del JID_CACHE[found]
-
# pylint: disable=c0103
#: The nodeprep profile of stringprep used to validate the local,
#: or username, portion of a JID.
@@ -436,7 +415,6 @@ class JID(object):
# pylint: disable=W0212
def __init__(self, jid=None, **kwargs):
- locked = kwargs.get('cache_lock', False)
in_local = kwargs.get('local', None)
in_domain = kwargs.get('domain', None)
in_resource = kwargs.get('resource', None)
@@ -444,40 +422,23 @@ class JID(object):
if in_local or in_domain or in_resource:
parts = (in_local, in_domain, in_resource)
- # only check cache if there is a jid string, or parts, not if there
- # are both
- self._jid = None
- key = None
- if (jid is not None) and (parts is None):
- if isinstance(jid, JID):
- # it's already good to go, and there are no additions
- self._jid = jid._jid
- return
- key = jid
- self._jid, locked = JID_CACHE.get(jid, (None, locked))
- elif jid is None and parts is not None:
- key = parts
- self._jid, locked = JID_CACHE.get(parts, (None, locked))
- if not self._jid:
- if not jid:
- parsed_jid = (None, None, None)
- elif not isinstance(jid, JID):
- parsed_jid = _parse_jid(jid)
- else:
- parsed_jid = jid._jid
-
- local, domain, resource = parsed_jid
-
- if 'local' in kwargs:
- local = _escape_node(in_local)
- if 'domain' in kwargs:
- domain = _validate_domain(in_domain)
- if 'resource' in kwargs:
- resource = _validate_resource(in_resource)
-
- self._jid = (local, domain, resource)
- if key:
- _cache(key, self._jid, locked)
+ if not jid:
+ parsed_jid = (None, None, None)
+ elif not isinstance(jid, JID):
+ parsed_jid = _parse_jid(jid)
+ else:
+ parsed_jid = jid._jid
+
+ local, domain, resource = parsed_jid
+
+ if 'local' in kwargs:
+ local = _escape_node(in_local)
+ if 'domain' in kwargs:
+ domain = _validate_domain(in_domain)
+ if 'resource' in kwargs:
+ resource = _validate_resource(in_resource)
+
+ self._jid = (local, domain, resource)
def unescape(self):
"""Return an unescaped JID object.
diff --git a/slixmpp/plugins/xep_0078/legacyauth.py b/slixmpp/plugins/xep_0078/legacyauth.py
index 0bcfb3d0..d949a913 100644
--- a/slixmpp/plugins/xep_0078/legacyauth.py
+++ b/slixmpp/plugins/xep_0078/legacyauth.py
@@ -128,9 +128,8 @@ class XEP_0078(BasePlugin):
self.xmpp.authenticated = True
- self.xmpp.boundjid = JID(self.xmpp.requested_jid,
- resource=resource,
- cache_lock=True)
+ self.xmpp.boundjid = JID(self.xmpp.requested_jid)
+ self.xmpp.boundjid.resource = resource
self.xmpp.event('session_bind', self.xmpp.boundjid)
log.debug("Established Session")