summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2009-12-11 01:29:46 +0000
committerNathan Fritz <fritzy@netflint.net>2009-12-11 01:29:46 +0000
commit8854509ccdbc1f9ea74e1eb00f3af098f2a3b6b6 (patch)
tree0cd10d2532fe57cf49128779bbc2375875afb8b0 /sleekxmpp/stanza
parenta031dd24a6c82745b7272d98229ebc69dd5f4811 (diff)
downloadslixmpp-8854509ccdbc1f9ea74e1eb00f3af098f2a3b6b6.tar.gz
slixmpp-8854509ccdbc1f9ea74e1eb00f3af098f2a3b6b6.tar.bz2
slixmpp-8854509ccdbc1f9ea74e1eb00f3af098f2a3b6b6.tar.xz
slixmpp-8854509ccdbc1f9ea74e1eb00f3af098f2a3b6b6.zip
* started converstion to stanza objects
Diffstat (limited to 'sleekxmpp/stanza')
-rw-r--r--sleekxmpp/stanza/iq.py20
-rw-r--r--sleekxmpp/stanza/message.py21
-rw-r--r--sleekxmpp/stanza/presence.py62
3 files changed, 68 insertions, 35 deletions
diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py
index eece37bd..68a429e0 100644
--- a/sleekxmpp/stanza/iq.py
+++ b/sleekxmpp/stanza/iq.py
@@ -1,5 +1,8 @@
from .. xmlstream.stanzabase import StanzaBase
from xml.etree import cElementTree as ET
+from . error import Error
+from .. xmlstream.handler.waiter import Waiter
+from .. xmlstream.matcher.id import MatcherId
class Iq(StanzaBase):
interfaces = set(('type', 'to', 'from', 'id', 'body', 'subject'))
@@ -11,7 +14,6 @@ class Iq(StanzaBase):
StanzaBase.__init__(self, *args, **kwargs)
if self['id'] == '':
self['id'] = self.stream.getId()
- print("________LOADED IQ CLASS")
def result(self):
self['type'] = 'result'
@@ -37,3 +39,19 @@ class Iq(StanzaBase):
def unhandled(self):
pass
# returned unhandled error
+
+ def exception(self, traceback=None):
+ pass
+
+ def send(self, block=True, timeout=10):
+ if block:
+ waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id']))
+ self.stream.registerHandler(waitfor)
+ StanzaBase.send(self)
+ return waitfor.wait(timeout)
+ else:
+ return StanzaBase.send(self)
+
+
+Iq.plugin_attrib_map['error'] = Error
+Iq.plugin_tag_map["{%s}%s" % (Error.namespace, Error.name)] = Error
diff --git a/sleekxmpp/stanza/message.py b/sleekxmpp/stanza/message.py
index 3f9eb2ba..999f7924 100644
--- a/sleekxmpp/stanza/message.py
+++ b/sleekxmpp/stanza/message.py
@@ -1,5 +1,6 @@
from .. xmlstream.stanzabase import StanzaBase
from xml.etree import cElementTree as ET
+from . error import Error
class Message(StanzaBase):
interfaces = set(('type', 'to', 'from', 'id', 'body', 'subject'))
@@ -25,21 +26,5 @@ class Message(StanzaBase):
self['body'] = body
return self
-if __name__ == '__main__':
- m = Message()
- m['to'] = 'me'
- m['from'] = 'you'
- m['type'] = 'chat'
- m.reply()
- m['body'] = 'Hello there!'
- m['subject'] = 'whatever'
- m['id'] = 'abc'
- print(str(m))
- print(m['body'])
- print(m['subject'])
- print(m['id'])
- m['type'] = None
- m['body'] = None
- m['id'] = None
- print(str(m))
- print(m['type'])
+Message.plugin_attrib_map['error'] = Error
+Message.plugin_tag_map["{%s}%s" % (Error.namespace, Error.name)] = Error
diff --git a/sleekxmpp/stanza/presence.py b/sleekxmpp/stanza/presence.py
index 0733e9a9..f591211b 100644
--- a/sleekxmpp/stanza/presence.py
+++ b/sleekxmpp/stanza/presence.py
@@ -1,21 +1,51 @@
from .. xmlstream.stanzabase import StanzaBase
-from .. xmlstream import xmlstream as xmlstreammod
-from .. xmlstream.matcher.xpath import MatchXPath
+from xml.etree import cElementTree as ET
+from . error import Error
-#_bases = [StanzaBase] + xmlstreammod.stanza_extensions.get('PresenceStanza', [])
+class Presence(StanzaBase):
+ interfaces = set(('type', 'to', 'from', 'id', 'status', 'priority'))
+ types = set(('available', 'unavailable', 'error', 'probe', 'subscribe', 'subscribed', 'unsubscribe', 'unsubscribed'))
+ showtypes = set(('dnd', 'ffc', 'xa', 'away'))
+ sub_interfaces = set(('status', 'priority'))
+ name = 'presence'
+ namespace = 'jabber:client'
-#class PresenceStanza(*_bases):
-class PresenceStanza(StanzaBase):
-
- def __init__(self, stream, xml=None):
- self.pfrom = ''
- self.pto = ''
- StanzaBase.__init__(self, stream, xml, xmlstreammod.stanza_extensions.get('PresenceStanza', []))
+ def getShowElement(self):
+ return self.xml.find("{%s}show" % self.namespace)
+
+ def setType(self, value):
+ if value in self.types:
+ show = self.getShowElement()
+ if value in self.types:
+ if show is not None:
+ self.xml.remove(show)
+ self._setAttr('type', value)
+ elif value in self.showtypes:
+ if show is None:
+ show = ET.Element("{%s}show" % self.namespace)
+ show.text = value
+ return self
- def fromXML(self, xml):
- StanzaBase.fromXML(self, xml)
- self.pfrom = xml.get('from')
- self.pto = xml.get('to')
- self.ptype = xml.get('type')
+ def setPriority(self, value):
+ self._setSubText('priority', str(value))
+
+ def getPriority(self):
+ p = self._getSubText('priority')
+ if not p: p = 0
+ return int(p)
+
+ def getType(self):
+ out = self._getAttr('type')
+ if not out:
+ show = self.getShowElement()
+ if show is not None:
+ out = show.text
+ if not out or out is None:
+ out = 'available'
+ return out
+
+ def delType(self):
+ self.setType('available')
-stanzas = ({'stanza_class': PresenceStanza, 'matcher': MatchXPath('{jabber:client}presence'), 'root': True},)
+Presence.plugin_attrib_map['error'] = Error
+Presence.plugin_tag_map["{%s}%s" % (Error.namespace, Error.name)] = Error