mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-12-18 03:00:18 +00:00
Save progress
This commit is contained in:
parent
d3bd9cd31d
commit
c49a8e9114
4 changed files with 64 additions and 10 deletions
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from sleekxmpp.xmlstream import JID
|
||||||
|
|
||||||
|
|
||||||
class Roster(object):
|
class Roster(object):
|
||||||
|
|
||||||
|
@ -64,7 +66,7 @@ class Roster(object):
|
||||||
Arguments:
|
Arguments:
|
||||||
key -- Return the roster for this JID.
|
key -- Return the roster for this JID.
|
||||||
"""
|
"""
|
||||||
if not isinstance(key, str):
|
if isinstance(key, JID):
|
||||||
key = key.bare
|
key = key.bare
|
||||||
if key not in self._rosters:
|
if key not in self._rosters:
|
||||||
self.add(key)
|
self.add(key)
|
||||||
|
@ -87,7 +89,7 @@ class Roster(object):
|
||||||
Arguments:
|
Arguments:
|
||||||
node -- The JID for the new roster node.
|
node -- The JID for the new roster node.
|
||||||
"""
|
"""
|
||||||
if not isinstance(node, str):
|
if isinstance(node, JID):
|
||||||
node = node.bare
|
node = node.bare
|
||||||
if node not in self._rosters:
|
if node not in self._rosters:
|
||||||
self._rosters[node] = RosterNode(self.xmpp, node, self.db)
|
self._rosters[node] = RosterNode(self.xmpp, node, self.db)
|
||||||
|
@ -169,7 +171,7 @@ class RosterNode(object):
|
||||||
|
|
||||||
A new item entry will be created if one does not already exist.
|
A new item entry will be created if one does not already exist.
|
||||||
"""
|
"""
|
||||||
if not isinstance(key, str):
|
if isinstance(key, JID):
|
||||||
key = key.bare
|
key = key.bare
|
||||||
if key not in self._jids:
|
if key not in self._jids:
|
||||||
self.add(key, save=True)
|
self.add(key, save=True)
|
||||||
|
@ -228,7 +230,7 @@ class RosterNode(object):
|
||||||
if one is used.
|
if one is used.
|
||||||
Defaults to False.
|
Defaults to False.
|
||||||
"""
|
"""
|
||||||
if not isinstance(jid, str):
|
if isinstance(jid, JID):
|
||||||
key = jid.bare
|
key = jid.bare
|
||||||
state = {'name': name,
|
state = {'name': name,
|
||||||
'groups': groups or [],
|
'groups': groups or [],
|
||||||
|
|
|
@ -16,7 +16,8 @@ import sleekxmpp
|
||||||
from sleekxmpp import ClientXMPP, ComponentXMPP
|
from sleekxmpp import ClientXMPP, ComponentXMPP
|
||||||
from sleekxmpp.stanza import Message, Iq, Presence
|
from sleekxmpp.stanza import Message, Iq, Presence
|
||||||
from sleekxmpp.test import TestSocket, TestLiveSocket
|
from sleekxmpp.test import TestSocket, TestLiveSocket
|
||||||
from sleekxmpp.xmlstream import StanzaBase, ET, register_stanza_plugin
|
from sleekxmpp.xmlstream import ET, register_stanza_plugin
|
||||||
|
from sleekxmpp.xmlstream import ElementBase, StanzaBase
|
||||||
from sleekxmpp.xmlstream.tostring import tostring
|
from sleekxmpp.xmlstream.tostring import tostring
|
||||||
from sleekxmpp.xmlstream.matcher import StanzaPath, MatcherId
|
from sleekxmpp.xmlstream.matcher import StanzaPath, MatcherId
|
||||||
from sleekxmpp.xmlstream.matcher import MatchXMLMask, MatchXPath
|
from sleekxmpp.xmlstream.matcher import MatchXMLMask, MatchXPath
|
||||||
|
@ -227,7 +228,7 @@ class SleekTest(unittest.TestCase):
|
||||||
"Stanza:\n%s" % str(stanza))
|
"Stanza:\n%s" % str(stanza))
|
||||||
else:
|
else:
|
||||||
stanza_class = stanza.__class__
|
stanza_class = stanza.__class__
|
||||||
if isinstance(criteria, str):
|
if not isinstance(criteria, ElementBase):
|
||||||
xml = self.parse_xml(criteria)
|
xml = self.parse_xml(criteria)
|
||||||
else:
|
else:
|
||||||
xml = criteria.xml
|
xml = criteria.xml
|
||||||
|
@ -632,7 +633,7 @@ class SleekTest(unittest.TestCase):
|
||||||
self.fail("Stanza data was sent: %s" % sent)
|
self.fail("Stanza data was sent: %s" % sent)
|
||||||
if sent is None:
|
if sent is None:
|
||||||
self.fail("No stanza was sent.")
|
self.fail("No stanza was sent.")
|
||||||
|
|
||||||
xml = self.parse_xml(sent)
|
xml = self.parse_xml(sent)
|
||||||
self.fix_namespaces(xml, 'jabber:client')
|
self.fix_namespaces(xml, 'jabber:client')
|
||||||
sent = self.xmpp._build_stanza(xml, 'jabber:client')
|
sent = self.xmpp._build_stanza(xml, 'jabber:client')
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
See the file LICENSE for copying permission.
|
See the file LICENSE for copying permission.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
class JID(object):
|
class JID(object):
|
||||||
"""
|
"""
|
||||||
|
@ -42,7 +44,9 @@ class JID(object):
|
||||||
Arguments:
|
Arguments:
|
||||||
jid - The new JID value.
|
jid - The new JID value.
|
||||||
"""
|
"""
|
||||||
self._full = self._jid = str(jid)
|
if isinstance(jid, JID):
|
||||||
|
jid = jid.full
|
||||||
|
self._full = self._jid = jid
|
||||||
self._domain = None
|
self._domain = None
|
||||||
self._resource = None
|
self._resource = None
|
||||||
self._user = None
|
self._user = None
|
||||||
|
@ -123,10 +127,11 @@ class JID(object):
|
||||||
return self.full
|
return self.full
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self)
|
return self.full
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"""
|
"""
|
||||||
Two JIDs are considered equal if they have the same full JID value.
|
Two JIDs are considered equal if they have the same full JID value.
|
||||||
"""
|
"""
|
||||||
return str(other) == str(self)
|
other = JID(other)
|
||||||
|
return self.full == other.full
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- encoding:utf8 -*-
|
||||||
|
|
||||||
from sleekxmpp.test import *
|
from sleekxmpp.test import *
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
@ -158,5 +160,49 @@ class TestStreamRoster(SleekTest):
|
||||||
self.failUnless(events == ['roster_callback'],
|
self.failUnless(events == ['roster_callback'],
|
||||||
"Roster timeout event not triggered: %s." % events)
|
"Roster timeout event not triggered: %s." % events)
|
||||||
|
|
||||||
|
def testRosterUnicode(self):
|
||||||
|
"""Test that JIDs with Unicode values are handled properly."""
|
||||||
|
self.stream_start()
|
||||||
|
self.recv("""
|
||||||
|
<iq to="tester@localhost" type="set" id="1">
|
||||||
|
<query xmlns="jabber:iq:roster">
|
||||||
|
<item jid="andré@foo" subscription="both">
|
||||||
|
<group>Unicode</group>
|
||||||
|
</item>
|
||||||
|
</query>
|
||||||
|
</iq>
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Give the event queue time to process.
|
||||||
|
time.sleep(.1)
|
||||||
|
|
||||||
|
roster = {'andré@foo': {
|
||||||
|
'name': '',
|
||||||
|
'subscription': 'both',
|
||||||
|
'groups': ['Unicode'],
|
||||||
|
'presence': {},
|
||||||
|
'in_roster': True}}
|
||||||
|
self.failUnless(self.xmpp.roster == roster,
|
||||||
|
"Unexpected roster values: %s" % self.xmpp.roster)
|
||||||
|
|
||||||
|
self.recv("""
|
||||||
|
<presence from="andré@foo/bar" />
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Give the event queue time to process.
|
||||||
|
time.sleep(.1)
|
||||||
|
|
||||||
|
roster = {'andré@foo': {
|
||||||
|
'name': '',
|
||||||
|
'subscription': 'both',
|
||||||
|
'groups': ['Unicode'],
|
||||||
|
'presence': {
|
||||||
|
'bar':{'priority':0,
|
||||||
|
'status':'',
|
||||||
|
'show':'available'}},
|
||||||
|
'in_roster': True}}
|
||||||
|
self.failUnless(self.xmpp.roster == roster,
|
||||||
|
"Unexpected roster values: %s" % self.xmpp.roster)
|
||||||
|
|
||||||
|
|
||||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster)
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster)
|
||||||
|
|
Loading…
Reference in a new issue