Merge pull request #251 from jpcaruana/jid_performance
This commit is contained in:
commit
85bc6f5301
1 changed files with 91 additions and 41 deletions
116
sleekxmpp/jid.py
116
sleekxmpp/jid.py
|
@ -506,51 +506,101 @@ class JID(object):
|
||||||
"""
|
"""
|
||||||
self._jid = JID(data)._jid
|
self._jid = JID(data)._jid
|
||||||
|
|
||||||
# pylint: disable=R0911
|
@property
|
||||||
def __getattr__(self, name):
|
def resource(self):
|
||||||
"""Retrieve the given JID component.
|
|
||||||
|
|
||||||
:param name: one of: user, server, domain, resource,
|
|
||||||
full, or bare.
|
|
||||||
"""
|
|
||||||
if name == 'resource':
|
|
||||||
return self._jid[2] or ''
|
return self._jid[2] or ''
|
||||||
elif name in ('user', 'username', 'local', 'node'):
|
|
||||||
|
@property
|
||||||
|
def user(self):
|
||||||
return self._jid[0] or ''
|
return self._jid[0] or ''
|
||||||
elif name in ('server', 'domain', 'host'):
|
|
||||||
return self._jid[1] or ''
|
@property
|
||||||
elif name in ('full', 'jid'):
|
def local(self):
|
||||||
return _format_jid(*self._jid)
|
return self._jid[0] or ''
|
||||||
elif name == 'bare':
|
|
||||||
|
@property
|
||||||
|
def node(self):
|
||||||
|
return self._jid[0] or ''
|
||||||
|
|
||||||
|
@property
|
||||||
|
def username(self):
|
||||||
|
return self._jid[0] or ''
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bare(self):
|
||||||
return _format_jid(self._jid[0], self._jid[1])
|
return _format_jid(self._jid[0], self._jid[1])
|
||||||
elif name == '_jid':
|
|
||||||
return getattr(super(JID, self), '_jid')
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# pylint: disable=W0212
|
@property
|
||||||
def __setattr__(self, name, value):
|
def server(self):
|
||||||
"""Update the given JID component.
|
return self._jid[1] or ''
|
||||||
|
|
||||||
:param name: one of: ``user``, ``username``, ``local``,
|
@property
|
||||||
``node``, ``server``, ``domain``, ``host``,
|
def domain(self):
|
||||||
``resource``, ``full``, ``jid``, or ``bare``.
|
return self._jid[1] or ''
|
||||||
:param value: The new string value of the JID component.
|
|
||||||
"""
|
@property
|
||||||
if name == '_jid':
|
def host(self):
|
||||||
super(JID, self).__setattr__('_jid', value)
|
return self._jid[1] or ''
|
||||||
elif name == 'resource':
|
|
||||||
|
@property
|
||||||
|
def full(self):
|
||||||
|
return _format_jid(*self._jid)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def jid(self):
|
||||||
|
return _format_jid(*self._jid)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bare(self):
|
||||||
|
return _format_jid(self._jid[0], self._jid[1])
|
||||||
|
|
||||||
|
|
||||||
|
@resource.setter
|
||||||
|
def resource(self, value):
|
||||||
self._jid = JID(self, resource=value)._jid
|
self._jid = JID(self, resource=value)._jid
|
||||||
elif name in ('user', 'username', 'local', 'node'):
|
|
||||||
|
@user.setter
|
||||||
|
def user(self, value):
|
||||||
self._jid = JID(self, local=value)._jid
|
self._jid = JID(self, local=value)._jid
|
||||||
elif name in ('server', 'domain', 'host'):
|
|
||||||
|
@username.setter
|
||||||
|
def username(self, value):
|
||||||
|
self._jid = JID(self, local=value)._jid
|
||||||
|
|
||||||
|
@local.setter
|
||||||
|
def local(self, value):
|
||||||
|
self._jid = JID(self, local=value)._jid
|
||||||
|
|
||||||
|
@node.setter
|
||||||
|
def node(self, value):
|
||||||
|
self._jid = JID(self, local=value)._jid
|
||||||
|
|
||||||
|
@server.setter
|
||||||
|
def server(self, value):
|
||||||
self._jid = JID(self, domain=value)._jid
|
self._jid = JID(self, domain=value)._jid
|
||||||
elif name in ('full', 'jid'):
|
|
||||||
|
@domain.setter
|
||||||
|
def domain(self, value):
|
||||||
|
self._jid = JID(self, domain=value)._jid
|
||||||
|
|
||||||
|
@host.setter
|
||||||
|
def host(self, value):
|
||||||
|
self._jid = JID(self, domain=value)._jid
|
||||||
|
|
||||||
|
@full.setter
|
||||||
|
def full(self, value):
|
||||||
self._jid = JID(value)._jid
|
self._jid = JID(value)._jid
|
||||||
elif name == 'bare':
|
|
||||||
|
@jid.setter
|
||||||
|
def jid(self, value):
|
||||||
|
self._jid = JID(value)._jid
|
||||||
|
|
||||||
|
@bare.setter
|
||||||
|
def bare(self, value):
|
||||||
parsed = JID(value)._jid
|
parsed = JID(value)._jid
|
||||||
self._jid = (parsed[0], parsed[1], self._jid[2])
|
self._jid = (parsed[0], parsed[1], self._jid[2])
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Use the full JID as the string value."""
|
"""Use the full JID as the string value."""
|
||||||
return _format_jid(*self._jid)
|
return _format_jid(*self._jid)
|
||||||
|
|
Loading…
Reference in a new issue