summaryrefslogtreecommitdiff
path: root/sleekxmpp/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/__init__.py')
-rw-r--r--sleekxmpp/__init__.py71
1 files changed, 21 insertions, 50 deletions
diff --git a/sleekxmpp/__init__.py b/sleekxmpp/__init__.py
index f0be089c..91dffa04 100644
--- a/sleekxmpp/__init__.py
+++ b/sleekxmpp/__init__.py
@@ -75,6 +75,7 @@ class ClientXMPP(basexmpp, XMLStream):
#self.map_namespace('http://etherx.jabber.org/streams', 'stream')
#self.map_namespace('jabber:client', '')
self.features = []
+ #TODO: Use stream state here
self.authenticated = False
self.sessionstarted = False
self.registerHandler(Callback('Stream Features', MatchXPath('{http://etherx.jabber.org/streams}features'), self._handleStreamFeatures, thread=True))
@@ -88,14 +89,6 @@ class ClientXMPP(basexmpp, XMLStream):
#self.registerStanzaExtension('PresenceStanza', PresenceStanzaType)
#self.register_plugins()
- def importStanzas(self):
- pass
- return
- for modname in stanza.__all__:
- __import__("%s.%s" % (globals()['stanza'].__name__, modname))
- for register in getattr(stanza, modname).stanzas:
- self.registerStanza(**register)
-
def __getitem__(self, key):
if key in self.plugin:
return self.plugin[key]
@@ -109,7 +102,6 @@ class ClientXMPP(basexmpp, XMLStream):
def connect(self, address=tuple()):
"""Connect to the Jabber Server. Attempts SRV lookup, and if it fails, uses
the JID server."""
- self.importStanzas()
if not address or len(address) < 2:
if not self.srvsupport:
logging.debug("Did not supply (address, port) to connect to and no SRV support is installed (http://www.dnspython.org). Continuing to attempt connection, using server hostname from JID.")
@@ -163,26 +155,15 @@ class ClientXMPP(basexmpp, XMLStream):
def updateRoster(self, jid, name=None, subscription=None, groups=[]):
"""Add or change a roster item."""
- iq = self.makeIqSet()
- iq.attrib['from'] = self.fulljid
- query = self.makeQueryRoster(iq)
- item = ET.Element('item')
- item.attrib['jid'] = jid
- if name:
- item.attrib['name'] = name
- if subscription in ['to', 'from', 'both']:
- item.attrib['subscription'] = subscription
- else:
- item.attrib['subscription'] = 'none'
- for group in groups:
- groupxml = ET.Element('group')
- groupxml.text = group
- item.append.groupxml
- return self.send(iq, self.makeIq(self.getId()))
+ iq = self.Iq().setValues({'type': 'set'})
+ iq['roster'] = {jid: {'name': name, 'subscription': subscription, 'groups': groups}}
+ #self.send(iq, self.Iq().setValues({'id': iq['id']}))
+ r = iq.send()
+ return r['type'] == 'result'
def getRoster(self):
"""Request the roster be sent."""
- self.send(self.makeIqGet('jabber:iq:roster'))
+ self.Iq().setValues({'type': 'get'}).enable('roster').send()
def _handleStreamFeatures(self, features):
self.features = []
@@ -198,7 +179,7 @@ class ClientXMPP(basexmpp, XMLStream):
def handler_starttls(self, xml):
if not self.authenticated and self.ssl_support:
self.add_handler("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_tls_start, instream=True)
- self.send(xml)
+ self.sendXML(xml)
return True
else:
logging.warning("The module tlslite is required in to some servers, and has not been found.")
@@ -240,14 +221,14 @@ class ClientXMPP(basexmpp, XMLStream):
def handler_bind_resource(self, xml):
logging.debug("Requesting resource: %s" % self.resource)
- out = self.makeIqSet()
+ iq = self.Iq(stype='set')
res = ET.Element('resource')
res.text = self.resource
xml.append(res)
- out.append(xml)
- id = out.get('id')
- response = self.send(out, self.makeIqResult(id))
- self.set_jid(response.find('{urn:ietf:params:xml:ns:xmpp-bind}bind/{urn:ietf:params:xml:ns:xmpp-bind}jid').text)
+ iq.append(xml)
+ response = iq.send()
+ #response = self.send(iq, self.Iq(sid=iq['id']))
+ self.set_jid(response.xml.find('{urn:ietf:params:xml:ns:xmpp-bind}bind/{urn:ietf:params:xml:ns:xmpp-bind}jid').text)
logging.info("Node set to: %s" % self.fulljid)
if "{urn:ietf:params:xml:ns:xmpp-session}session" not in self.features:
logging.debug("Established Session")
@@ -261,21 +242,11 @@ class ClientXMPP(basexmpp, XMLStream):
self.sessionstarted = True
self.event("session_start")
- def _handleRoster(self, roster):
- xml = roster.xml
- xml = roster.xml
- roster_update = {}
- for item in xml.findall('{jabber:iq:roster}query/{jabber:iq:roster}item'):
- if not item.attrib['jid'] in self.roster:
- self.roster[item.attrib['jid']] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': False}
- self.roster[item.attrib['jid']]['name'] = item.get('name', '')
- self.roster[item.attrib['jid']]['subscription'] = item.get('subscription', 'none')
- self.roster[item.attrib['jid']]['in_roster'] = 'True'
- for group in item.findall('{jabber:iq:roster}group'):
- self.roster[item.attrib['jid']]['groups'].append(group.text)
- if self.roster[item.attrib['jid']]['groups'] == []:
- self.roster[item.attrib['jid']]['groups'].append('Default')
- roster_update[item.attrib['jid']] = self.roster[item.attrib['jid']]
- if xml.get('type', 'result') == 'set':
- self.send(self.makeIqResult(xml.get('id', '0')))
- self.event("roster_update", roster_update)
+ def _handleRoster(self, iq):
+ for jid in iq['roster']['items']:
+ if not jid.bare in self.roster:
+ self.roster[jid.bare] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': True}
+ self.roster[jid.bare].update(iq['roster']['jid'])
+ if iq['type'] == 'set':
+ self.send(self.Iq().setValues({'type': 'result', 'id': iq['id']}).enable('roster'))
+ self.event("roster_update", iq)