Merge branch 'develop' into roster

Conflicts:
	sleekxmpp/clientxmpp.py
This commit is contained in:
Lance Stout
2011-02-14 16:18:44 -05:00
39 changed files with 1984 additions and 267 deletions

View File

@@ -77,15 +77,6 @@ class Error(ElementBase):
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.getCondition = self.get_condition
self.setCondition = self.set_condition
self.delCondition = self.del_condition
self.getText = self.get_text
self.setText = self.set_text
self.delText = self.del_text
if ElementBase.setup(self, xml):
#If we had to generate XML then set default values.
self['type'] = 'cancel'
@@ -139,3 +130,13 @@ class Error(ElementBase):
"""Remove the <text> element."""
self._del_sub('{%s}text' % self.condition_ns)
return self
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Error.getCondition = Error.get_condition
Error.setCondition = Error.set_condition
Error.delCondition = Error.del_condition
Error.getText = Error.get_text
Error.setText = Error.set_text
Error.delText = Error.del_text

View File

@@ -46,23 +46,6 @@ class HTMLIM(ElementBase):
interfaces = set(('body',))
plugin_attrib = name
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setBody = self.set_body
self.getBody = self.get_body
self.delBody = self.del_body
return ElementBase.setup(self, xml)
def set_body(self, html):
"""
Set the contents of the HTML body.
@@ -95,3 +78,9 @@ class HTMLIM(ElementBase):
register_stanza_plugin(Message, HTMLIM)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
HTMLIM.setBody = HTMLIM.set_body
HTMLIM.getBody = HTMLIM.get_body
HTMLIM.delBody = HTMLIM.del_body

View File

@@ -75,13 +75,6 @@ class Iq(RootStanza):
Overrides StanzaBase.__init__.
"""
StanzaBase.__init__(self, *args, **kwargs)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setPayload = self.set_payload
self.getQuery = self.get_query
self.setQuery = self.set_query
self.delQuery = self.del_query
if self['id'] == '':
if self.stream is not None:
self['id'] = self.stream.getNewId()
@@ -144,7 +137,7 @@ class Iq(RootStanza):
self.xml.remove(child)
return self
def reply(self):
def reply(self, clear=True):
"""
Send a reply <iq> stanza.
@@ -152,9 +145,13 @@ class Iq(RootStanza):
Sets the 'type' to 'result' in addition to the default
StanzaBase.reply behavior.
Arguments:
clear -- Indicates if existing content should be
removed before replying. Defaults to True.
"""
self['type'] = 'result'
StanzaBase.reply(self)
StanzaBase.reply(self, clear)
return self
def send(self, block=True, timeout=None, callback=None):
@@ -185,13 +182,14 @@ class Iq(RootStanza):
if timeout is None:
timeout = self.stream.response_timeout
if callback is not None and self['type'] in ('get', 'set'):
handler = Callback('IqCallback_%s' % self['id'],
handler_name = 'IqCallback_%s' % self['id']
handler = Callback(handler_name,
MatcherId(self['id']),
callback,
once=True)
self.stream.register_handler(handler)
StanzaBase.send(self)
return None
return handler_name
elif block and self['type'] in ('get', 'set'):
waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id']))
self.stream.register_handler(waitfor)
@@ -224,3 +222,11 @@ class Iq(RootStanza):
else:
StanzaBase._set_stanza_values(self, values)
return self
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Iq.setPayload = Iq.set_payload
Iq.getQuery = Iq.get_query
Iq.setQuery = Iq.set_query
Iq.delQuery = Iq.del_query

View File

@@ -63,27 +63,6 @@ class Message(RootStanza):
plugin_attrib = name
types = set((None, 'normal', 'chat', 'headline', 'error', 'groupchat'))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.getType = self.get_type
self.getMucroom = self.get_mucroom
self.setMucroom = self.set_mucroom
self.delMucroom = self.del_mucroom
self.getMucnick = self.get_mucnick
self.setMucnick = self.set_mucnick
self.delMucnick = self.del_mucnick
return StanzaBase.setup(self, xml)
def get_type(self):
"""
Return the message type.
@@ -104,7 +83,7 @@ class Message(RootStanza):
self['type'] = 'normal'
return self
def reply(self, body=None):
def reply(self, body=None, clear=True):
"""
Create a message reply.
@@ -114,7 +93,9 @@ class Message(RootStanza):
adds a message body if one is given.
Arguments:
body -- Optional text content for the message.
body -- Optional text content for the message.
clear -- Indicates if existing content should be removed
before replying. Defaults to True.
"""
StanzaBase.reply(self)
if self['type'] == 'groupchat':
@@ -163,3 +144,14 @@ class Message(RootStanza):
def del_mucnick(self):
"""Dummy method to prevent deletion."""
pass
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Message.getType = Message.get_type
Message.getMucroom = Message.get_mucroom
Message.setMucroom = Message.set_mucroom
Message.delMucroom = Message.del_mucroom
Message.getMucnick = Message.get_mucnick
Message.setMucnick = Message.set_mucnick
Message.delMucnick = Message.del_mucnick

View File

@@ -49,23 +49,6 @@ class Nick(ElementBase):
plugin_attrib = name
interfaces = set(('nick',))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setNick = self.set_nick
self.getNick = self.get_nick
self.delNick = self.del_nick
return ElementBase.setup(self, xml)
def set_nick(self, nick):
"""
Add a <nick> element with the given nickname.
@@ -87,3 +70,9 @@ class Nick(ElementBase):
register_stanza_plugin(Message, Nick)
register_stanza_plugin(Presence, Nick)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Nick.setNick = Nick.set_nick
Nick.getNick = Nick.get_nick
Nick.delNick = Nick.del_nick

View File

@@ -72,26 +72,6 @@ class Presence(RootStanza):
'subscribed', 'unsubscribe', 'unsubscribed'))
showtypes = set(('dnd', 'chat', 'xa', 'away'))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides ElementBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setShow = self.set_show
self.getType = self.get_type
self.setType = self.set_type
self.delType = self.get_type
self.getPriority = self.get_priority
self.setPriority = self.set_priority
return StanzaBase.setup(self, xml)
def exception(self, e):
"""
Override exception passback for presence.
@@ -173,14 +153,28 @@ class Presence(RootStanza):
# The priority is not a number: we consider it 0 as a default
return 0
def reply(self):
def reply(self, clear=True):
"""
Set the appropriate presence reply type.
Overrides StanzaBase.reply.
Arguments:
clear -- Indicates if the stanza contents should be removed
before replying. Defaults to True.
"""
if self['type'] == 'unsubscribe':
self['type'] = 'unsubscribed'
elif self['type'] == 'subscribe':
self['type'] = 'subscribed'
return StanzaBase.reply(self)
return StanzaBase.reply(self, clear)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Presence.setShow = Presence.set_show
Presence.getType = Presence.get_type
Presence.setType = Presence.set_type
Presence.delType = Presence.get_type
Presence.getPriority = Presence.get_priority
Presence.setPriority = Presence.set_priority

View File

@@ -43,8 +43,8 @@ class RootStanza(StanzaBase):
Arguments:
e -- Exception object
"""
self.reply()
if isinstance(e, XMPPError):
self.reply(clear=e.clear)
# We raised this deliberately
self['error']['condition'] = e.condition
self['error']['text'] = e.text
@@ -56,6 +56,7 @@ class RootStanza(StanzaBase):
self['error']['type'] = e.etype
self.send()
else:
self.reply()
# We probably didn't raise this on purpose, so send an error stanza
self['error']['condition'] = 'undefined-condition'
self['error']['text'] = "SleekXMPP got into trouble."

View File

@@ -38,23 +38,6 @@ class Roster(ElementBase):
plugin_attrib = 'roster'
interfaces = set(('items',))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setItems = self.set_items
self.getItems = self.get_items
self.delItems = self.del_items
return ElementBase.setup(self, xml)
def set_items(self, items):
"""
Set the roster entries in the <roster> stanza.
@@ -125,3 +108,9 @@ class Roster(ElementBase):
register_stanza_plugin(Iq, Roster)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Roster.setItems = Roster.set_items
Roster.getItems = Roster.get_items
Roster.delItems = Roster.del_items