mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
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.
This commit is contained in:
parent
1ebc7f4d4b
commit
d9c25ee65c
1 changed files with 78 additions and 19 deletions
|
@ -245,7 +245,7 @@ class BaseXMPP(XMLStream):
|
||||||
"""Create a Presence stanza associated with this stream."""
|
"""Create a Presence stanza associated with this stream."""
|
||||||
return Presence(self, *args, **kwargs)
|
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.
|
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.
|
id -- An ideally unique ID value for this stanza thread.
|
||||||
Defaults to 0.
|
Defaults to 0.
|
||||||
ifrom -- The from JID to use for this stanza.
|
ifrom -- The from JID to use for this stanza.
|
||||||
|
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.
|
||||||
"""
|
"""
|
||||||
return self.Iq()._set_stanza_values({'id': str(id),
|
iq = self.Iq()
|
||||||
'from': ifrom})
|
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'.
|
Create an Iq stanza of type 'get'.
|
||||||
|
|
||||||
|
@ -265,21 +273,45 @@ class BaseXMPP(XMLStream):
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
queryxmlns -- The namespace of the query to use.
|
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',
|
if not iq:
|
||||||
'query': queryxmlns})
|
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.
|
Create an Iq stanza of type 'result' with the given ID value.
|
||||||
|
|
||||||
Arguments:
|
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,
|
if not iq:
|
||||||
'type': 'result'})
|
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'.
|
Create an Iq stanza of type 'set'.
|
||||||
|
|
||||||
|
@ -288,14 +320,25 @@ class BaseXMPP(XMLStream):
|
||||||
|
|
||||||
Arguments:
|
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:
|
if sub != None:
|
||||||
iq.append(sub)
|
iq.append(sub)
|
||||||
|
if ito:
|
||||||
|
iq['to'] = ito
|
||||||
|
if ifrom:
|
||||||
|
iq['from'] = ifrom
|
||||||
return iq
|
return iq
|
||||||
|
|
||||||
def make_iq_error(self, id, type='cancel',
|
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'.
|
Create an Iq stanza of type 'error'.
|
||||||
|
|
||||||
|
@ -306,14 +349,24 @@ class BaseXMPP(XMLStream):
|
||||||
condition -- The error condition.
|
condition -- The error condition.
|
||||||
Defaults to 'feature-not-implemented'.
|
Defaults to 'feature-not-implemented'.
|
||||||
text -- A message describing the cause of the error.
|
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})
|
if not iq:
|
||||||
iq['error']._set_stanza_values({'type': type,
|
iq = self.Iq()
|
||||||
'condition': condition,
|
iq['id'] = id
|
||||||
'text': text})
|
iq['error']['type'] = type
|
||||||
|
iq['error']['condition'] = condition
|
||||||
|
iq['error']['text'] = text
|
||||||
|
if ito:
|
||||||
|
iq['to'] = ito
|
||||||
|
if ifrom:
|
||||||
|
iq['from'] = ifrom
|
||||||
return iq
|
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
|
Create or modify an Iq stanza to use the given
|
||||||
query namespace.
|
query namespace.
|
||||||
|
@ -322,10 +375,16 @@ class BaseXMPP(XMLStream):
|
||||||
iq -- Optional Iq stanza to modify. A new
|
iq -- Optional Iq stanza to modify. A new
|
||||||
stanza is created otherwise.
|
stanza is created otherwise.
|
||||||
xmlns -- The query's namespace.
|
xmlns -- The query's namespace.
|
||||||
|
ito -- The destination JID for this stanza.
|
||||||
|
ifrom -- The from JID to use for this stanza.
|
||||||
"""
|
"""
|
||||||
if not iq:
|
if not iq:
|
||||||
iq = self.Iq()
|
iq = self.Iq()
|
||||||
iq['query'] = xmlns
|
iq['query'] = xmlns
|
||||||
|
if ito:
|
||||||
|
iq['to'] = ito
|
||||||
|
if ifrom:
|
||||||
|
iq['from'] = ifrom
|
||||||
return iq
|
return iq
|
||||||
|
|
||||||
def make_query_roster(self, iq=None):
|
def make_query_roster(self, iq=None):
|
||||||
|
|
Loading…
Reference in a new issue