Merge branch 'master' of github.com:fritzy/SleekXMPP

This commit is contained in:
Nathan Fritz
2010-01-25 10:40:50 -08:00
14 changed files with 134 additions and 21 deletions

View File

@@ -58,7 +58,7 @@ class Subscription(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'subscription'
plugin_attrib = name
interfaces = set(('jid', 'node', 'subscription'))
interfaces = set(('jid', 'node', 'subscription', 'subid'))
plugin_attrib_map = {}
plugin_tag_map = {}
@@ -207,9 +207,10 @@ class Publish(Items):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'publish'
plugin_attrib = name
interfaces = set(('node'))
interfaces = set(('node',))
plugin_attrib_map = {}
plugin_tag_map = {}
subitem = Item
stanzaPlugin(Pubsub, Publish)

View File

@@ -53,7 +53,7 @@ class xep_0030(base.base_plugin):
def info_handler(self, xml):
logging.debug("Info request from %s" % xml.get('from', ''))
iq = self.xmpp.makeIqResult(xml.get('id', self.xmpp.getNewId()))
iq.attrib['from'] = self.xmpp.fulljid
iq.attrib['from'] = xml.get('to')
iq.attrib['to'] = xml.get('from', self.xmpp.server)
query = xml.find('{http://jabber.org/protocol/disco#info}query')
node = query.get('node', 'main')
@@ -74,7 +74,7 @@ class xep_0030(base.base_plugin):
def item_handler(self, xml):
logging.debug("Item request from %s" % xml.get('from', ''))
iq = self.xmpp.makeIqResult(xml.get('id', self.xmpp.getNewId()))
iq.attrib['from'] = self.xmpp.fulljid
iq.attrib['from'] = xml.get('to')
iq.attrib['to'] = xml.get('from', self.xmpp.server)
query = self.xmpp.makeIqQuery(iq, 'http://jabber.org/protocol/disco#items').find('{http://jabber.org/protocol/disco#items}query')
node = xml.find('{http://jabber.org/protocol/disco#items}query').get('node', 'main')
@@ -82,7 +82,7 @@ class xep_0030(base.base_plugin):
itemxml = ET.Element('item')
itemxml.attrib = item
if itemxml.attrib['jid'] is None:
itemxml.attrib['jid'] = self.xmpp.fulljid
itemxml.attrib['jid'] = xml.get('to')
query.append(itemxml)
self.xmpp.send(iq)

View File

@@ -223,12 +223,15 @@ class xep_0045(base.base_plugin):
return False
return True
def setAffiliation(self, room, jid, affiliation='member'):
def setAffiliation(self, room, jid=None, nick=None, affiliation='member'):
""" Change room affiliation."""
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
raise TypeError
query = ET.Element('{http://jabber.org/protocol/muc#admin}query')
item = ET.Element('item', {'affiliation':affiliation, 'jid':jid})
if nick is not None:
item = ET.Element('item', {'affiliation':affiliation, 'nick':nick})
else:
item = ET.Element('item', {'affiliation':affiliation, 'jid':jid})
query.append(item)
iq = self.xmpp.makeIqSet(query)
iq['to'] = room

View File

@@ -62,6 +62,7 @@ class xep_0050(base.base_plugin):
name, form, pointer, multi = self.commands[node]
self.sessions[sessionid] = {}
self.sessions[sessionid]['jid'] = xml.get('from')
self.sessions[sessionid]['to'] = xml.get('to')
self.sessions[sessionid]['past'] = [(form, None)]
self.sessions[sessionid]['next'] = pointer
npointer = pointer
@@ -133,6 +134,8 @@ class xep_0050(base.base_plugin):
command.append(xmlactions)
if not sessionid:
sessionid = self.getNewSession()
else:
iq.attrib['from'] = self.sessions[sessionid]['to']
command.attrib['sessionid'] = sessionid
if form is not None:
if hasattr(form,'getXML'):

View File

@@ -20,10 +20,11 @@ class Iq(RootStanza):
self['id'] = '0'
def unhandled(self):
self.reply()
self['error']['condition'] = 'feature-not-implemented'
self['error']['text'] = 'No handlers registered for this request.'
self.send()
if self['type'] in ('get', 'set'):
self.reply()
self['error']['condition'] = 'feature-not-implemented'
self['error']['text'] = 'No handlers registered for this request.'
self.send()
def result(self):
self['type'] = 'result'

View File

@@ -3,4 +3,4 @@ from . import base
class MatcherId(base.MatcherBase):
def match(self, xml):
return xml.get('id') == self._criteria
return xml['id'] == self._criteria

View File

@@ -0,0 +1,7 @@
from . import base
from xml.etree import cElementTree
class StanzaPath(base.MatcherBase):
def match(self, stanza):
return stanza.match(self._criteria)

View File

@@ -16,6 +16,8 @@ class MatchXMLMask(base.MatcherBase):
self.default_ns = ns
def match(self, xml):
if hasattr(xml, 'xml'):
xml = xml.xml
return self.maskcmp(xml, self._criteria, True)
def maskcmp(self, source, maskobj, use_ns=False, default_ns='__no_ns__'):

View File

@@ -6,6 +6,8 @@ ignore_ns = False
class MatchXPath(base.MatcherBase):
def match(self, xml):
if hasattr(xml, 'xml'):
xml = xml.xml
x = cElementTree.Element('x')
x.append(xml)
if not ignore_ns:

View File

@@ -2,6 +2,8 @@ from xml.etree import cElementTree as ET
import logging
import traceback
xmltester = type(ET.Element('xml'))
class JID(object):
def __init__(self, jid):
self.jid = jid
@@ -62,7 +64,10 @@ class ElementBase(object):
def append(self, item):
if not isinstance(item, ElementBase):
raise TypeError
if type(item) == xmltester:
return self.appendxml(item)
else:
raise TypeError
self.xml.append(item.xml)
self.iterables.append(item)
return self
@@ -86,11 +91,27 @@ class ElementBase(object):
out.append('substanzas')
return tuple(out)
def find(self, item):
return self.iterables.find(item)
def match(self, xml):
return xml.tag == self.tag
def match(self, matchstring):
if isinstance(matchstring, str):
nodes = matchstring.split('/')
else:
nodes = matchstring
tagargs = nodes[0].split('@')
if tagargs[0] not in (self.plugins, self.name): return False
founditerable = False
for iterable in self.iterables:
founditerable = iterable.match(nodes[1:])
if founditerable: break;
for evals in tagargs[1:]:
x,y = evals.split('=')
if self[x] != y: return False
if not founditerable and len(nodes) > 1:
next = nodes[1].split('@')[0]
if next in self.plugins:
return self.plugins[next].match(nodes[1:])
else:
return False
return True
def find(self, xpath): # for backwards compatiblity, expose elementtree interface
return self.xml.find(xpath)

View File

@@ -279,7 +279,7 @@ class XMLStream(object):
stanza = StanzaBase(self, xmlobj)
unhandled = True
for handler in self.__handlers:
if handler.match(xmlobj):
if handler.match(stanza):
handler.prerun(stanza)
self.eventqueue.put(('stanza', handler, stanza))
if handler.checkDelete(): self.__handlers.pop(self.__handlers.index(handler))