summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-12-16 15:18:06 -0500
committerLance Stout <lancestout@gmail.com>2010-12-16 15:25:04 -0500
commitd9c25ee65cee2243c45450655cfc07bab257535c (patch)
treef9aa2c33bacca7442cc8274ce09117385588c910 /sleekxmpp
parent1ebc7f4d4bef38261111f16af4946d77d584d293 (diff)
downloadslixmpp-d9c25ee65cee2243c45450655cfc07bab257535c.tar.gz
slixmpp-d9c25ee65cee2243c45450655cfc07bab257535c.tar.bz2
slixmpp-d9c25ee65cee2243c45450655cfc07bab257535c.tar.xz
slixmpp-d9c25ee65cee2243c45450655cfc07bab257535c.zip
Added more options to the make_iq_* methods.
May include a to and from JID in make_iq_* calls. May pass an existing iq stanza to most of them instead of generating a new stanza. make_iq now accepts a 'to' value, 'type' value, and 'query' value to simplify things a bit more.
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/basexmpp.py99
1 files changed, 79 insertions, 20 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py
index 0ff573ff..42cbaa04 100644
--- a/sleekxmpp/basexmpp.py
+++ b/sleekxmpp/basexmpp.py
@@ -245,7 +245,7 @@ class BaseXMPP(XMLStream):
"""Create a Presence stanza associated with this stream."""
return Presence(self, *args, **kwargs)
- def make_iq(self, id=0, ifrom=None):
+ def make_iq(self, id=0, ifrom=None, ito=None, type=None, query=None):
"""
Create a new Iq stanza with a given Id and from JID.
@@ -253,11 +253,19 @@ class BaseXMPP(XMLStream):
id -- An ideally unique ID value for this stanza thread.
Defaults to 0.
ifrom -- The from JID to use for this stanza.
- """
- return self.Iq()._set_stanza_values({'id': str(id),
- 'from': ifrom})
+ ito -- The destination JID for this stanza.
+ type -- The Iq's type, one of: get, set, result, or error.
+ query -- Optional namespace for adding a query element.
+ """
+ iq = self.Iq()
+ iq['id'] = str(id)
+ iq['to'] = ito
+ iq['from'] = ifrom
+ iq['type'] = itype
+ iq['query'] = query
+ return iq
- def make_iq_get(self, queryxmlns=None):
+ def make_iq_get(self, queryxmlns=None, ito=None, ifrom=None, iq=None):
"""
Create an Iq stanza of type 'get'.
@@ -265,21 +273,45 @@ class BaseXMPP(XMLStream):
Arguments:
queryxmlns -- The namespace of the query to use.
+ ito -- The destination JID for this stanza.
+ ifrom -- The from JID to use for this stanza.
+ iq -- Optionally use an existing stanza instead
+ of generating a new one.
"""
- return self.Iq()._set_stanza_values({'type': 'get',
- 'query': queryxmlns})
+ if not iq:
+ iq = self.Iq()
+ iq['type'] = 'get'
+ iq['query'] = queryxmlns
+ if ito:
+ iq['to'] = ito
+ if ifrom:
+ iq['from'] = ifrom
+ return iq
- def make_iq_result(self, id):
+ def make_iq_result(self, id=None, ito=None, ifrom=None, iq=None):
"""
Create an Iq stanza of type 'result' with the given ID value.
Arguments:
- id -- An ideally unique ID value. May use self.new_id().
+ id -- An ideally unique ID value. May use self.new_id().
+ ito -- The destination JID for this stanza.
+ ifrom -- The from JID to use for this stanza.
+ iq -- Optionally use an existing stanza instead
+ of generating a new one.
"""
- return self.Iq()._set_stanza_values({'id': id,
- 'type': 'result'})
+ if not iq:
+ iq = self.Iq()
+ if id is None:
+ id = self.new_id()
+ iq['id'] = id
+ iq['type'] = 'result'
+ if ito:
+ iq['to'] = ito
+ if ifrom:
+ iq['from'] = ifrom
+ return iq
- def make_iq_set(self, sub=None):
+ def make_iq_set(self, sub=None, ito=None, ifrom=None, iq=None):
"""
Create an Iq stanza of type 'set'.
@@ -287,15 +319,26 @@ class BaseXMPP(XMLStream):
stanza's payload.
Arguments:
- sub -- A stanza or XML object to use as the Iq's payload.
+ sub -- A stanza or XML object to use as the Iq's payload.
+ ito -- The destination JID for this stanza.
+ ifrom -- The from JID to use for this stanza.
+ iq -- Optionally use an existing stanza instead
+ of generating a new one.
"""
- iq = self.Iq()._set_stanza_values({'type': 'set'})
+ if not iq:
+ iq = self.Iq()
+ iq['type'] = 'set'
if sub != None:
iq.append(sub)
+ if ito:
+ iq['to'] = ito
+ if ifrom:
+ iq['from'] = ifrom
return iq
def make_iq_error(self, id, type='cancel',
- condition='feature-not-implemented', text=None):
+ condition='feature-not-implemented',
+ text=None, ito=None, ifrom=None, iq=None):
"""
Create an Iq stanza of type 'error'.
@@ -306,14 +349,24 @@ class BaseXMPP(XMLStream):
condition -- The error condition.
Defaults to 'feature-not-implemented'.
text -- A message describing the cause of the error.
+ ito -- The destination JID for this stanza.
+ ifrom -- The from JID to use for this stanza.
+ iq -- Optionally use an existing stanza instead
+ of generating a new one.
"""
- iq = self.Iq()._set_stanza_values({'id': id})
- iq['error']._set_stanza_values({'type': type,
- 'condition': condition,
- 'text': text})
+ if not iq:
+ iq = self.Iq()
+ iq['id'] = id
+ iq['error']['type'] = type
+ iq['error']['condition'] = condition
+ iq['error']['text'] = text
+ if ito:
+ iq['to'] = ito
+ if ifrom:
+ iq['from'] = ifrom
return iq
- def make_iq_query(self, iq=None, xmlns=''):
+ def make_iq_query(self, iq=None, xmlns='', ito=None, ifrom=None):
"""
Create or modify an Iq stanza to use the given
query namespace.
@@ -322,10 +375,16 @@ class BaseXMPP(XMLStream):
iq -- Optional Iq stanza to modify. A new
stanza is created otherwise.
xmlns -- The query's namespace.
+ ito -- The destination JID for this stanza.
+ ifrom -- The from JID to use for this stanza.
"""
if not iq:
iq = self.Iq()
iq['query'] = xmlns
+ if ito:
+ iq['to'] = ito
+ if ifrom:
+ iq['from'] = ifrom
return iq
def make_query_roster(self, iq=None):