removed unused and redundant 'makeIq...' methods from basexmpp; cleaned up the (few\!) plugins that actually used them.
This commit is contained in:
parent
f7273affc5
commit
fc952efae9
@ -158,12 +158,6 @@ class basexmpp(object):
|
|||||||
if mask is not None:
|
if mask is not None:
|
||||||
return waitfor.wait(timeout)
|
return waitfor.wait(timeout)
|
||||||
|
|
||||||
def makeIq(self, id=0, ifrom=None):
|
|
||||||
# FIXME this will always assign an ID of 0 instead of allowing `getNewId`
|
|
||||||
# to assign a unique ID to the new IQ packet. This method is only called
|
|
||||||
# from xep_0199 and should probably be deprecated.
|
|
||||||
return self.Iq().setValues({'id': id, 'from': ifrom})
|
|
||||||
|
|
||||||
def makeIqGet(self, queryxmlns = None):
|
def makeIqGet(self, queryxmlns = None):
|
||||||
# TODO this should take a 'to' param since more often than not you set
|
# TODO this should take a 'to' param since more often than not you set
|
||||||
# iq['to']=whatever immediately after.
|
# iq['to']=whatever immediately after.
|
||||||
@ -191,21 +185,6 @@ class basexmpp(object):
|
|||||||
iq['error'].setValues({'type': type, 'condition': condition, 'text': text})
|
iq['error'].setValues({'type': type, 'condition': condition, 'text': text})
|
||||||
return iq
|
return iq
|
||||||
|
|
||||||
def makeIqQuery(self, iq, xmlns):
|
|
||||||
# FIXME this looks like it essentially duplicates the `makeIqGet`
|
|
||||||
# and is only used in xep_009 (in two places) and gmail_notify (once).
|
|
||||||
# Probably safe to deprecate and replace with `makeIqGet.`
|
|
||||||
query = ET.Element("{%s}query" % xmlns)
|
|
||||||
iq.append(query)
|
|
||||||
return iq
|
|
||||||
|
|
||||||
def makeQueryRoster(self, iq=None):
|
|
||||||
# FIXME unused. Remove; any user of this code can replace it by `makeIqGet('jabber:iq:roster')`
|
|
||||||
query = ET.Element("{jabber:iq:roster}query")
|
|
||||||
if iq:
|
|
||||||
iq.append(query)
|
|
||||||
return query
|
|
||||||
|
|
||||||
def add_event_handler(self, name, pointer, threaded=False, disposable=False):
|
def add_event_handler(self, name, pointer, threaded=False, disposable=False):
|
||||||
if not name in self.event_handlers:
|
if not name in self.event_handlers:
|
||||||
self.event_handlers[name] = []
|
self.event_handlers[name] = []
|
||||||
|
@ -50,7 +50,7 @@ class gmail_notify(base.base_plugin):
|
|||||||
iq = self.xmpp.makeIqGet()
|
iq = self.xmpp.makeIqGet()
|
||||||
iq.attrib['from'] = self.xmpp.fulljid
|
iq.attrib['from'] = self.xmpp.fulljid
|
||||||
iq.attrib['to'] = self.xmpp.jid
|
iq.attrib['to'] = self.xmpp.jid
|
||||||
self.xmpp.makeIqQuery(iq, 'google:mail:notify')
|
iq.append(ET.Element('{google:mail:notify}query'))
|
||||||
emails = iq.send()
|
emails = iq.send()
|
||||||
mailbox = emails.find('{google:mail:notify}mailbox')
|
mailbox = emails.find('{google:mail:notify}mailbox')
|
||||||
total = int(mailbox.get('total-matched', 0))
|
total = int(mailbox.get('total-matched', 0))
|
||||||
|
@ -226,35 +226,31 @@ class xep_0009(base.base_plugin):
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
|
||||||
def makeMethodCallQuery(self,pmethod,params):
|
def makeIqMethodCall(self,pto,pmethod,params):
|
||||||
query = self.xmpp.makeIqQuery(iq,"jabber:iq:rpc")
|
query = ET.Element("{jabber:iq:rpc}query")
|
||||||
methodCall = ET.Element('methodCall')
|
methodCall = ET.Element('methodCall')
|
||||||
methodName = ET.Element('methodName')
|
methodName = ET.Element('methodName')
|
||||||
methodName.text = pmethod
|
methodName.text = pmethod
|
||||||
methodCall.append(methodName)
|
methodCall.append(methodName)
|
||||||
methodCall.append(params)
|
methodCall.append(params)
|
||||||
query.append(methodCall)
|
query.append(methodCall)
|
||||||
return query
|
iq = self.xmpp.makeIqSet(query)
|
||||||
|
|
||||||
def makeIqMethodCall(self,pto,pmethod,params):
|
|
||||||
iq = self.xmpp.makeIqSet()
|
|
||||||
iq.set('to',pto)
|
iq.set('to',pto)
|
||||||
iq.append(self.makeMethodCallQuery(pmethod,params))
|
|
||||||
return iq
|
return iq
|
||||||
|
|
||||||
def makeIqMethodResponse(self,pto,pid,params):
|
def makeIqMethodResponse(self,pto,pid,params):
|
||||||
iq = self.xmpp.makeIqResult(pid)
|
query = ET.Element("{jabber:iq:rpc}query")
|
||||||
iq.set('to',pto)
|
|
||||||
query = self.xmpp.makeIqQuery(iq,"jabber:iq:rpc")
|
|
||||||
methodResponse = ET.Element('methodResponse')
|
methodResponse = ET.Element('methodResponse')
|
||||||
methodResponse.append(params)
|
methodResponse.append(params)
|
||||||
query.append(methodResponse)
|
query.append(methodResponse)
|
||||||
|
iq = self.xmpp.makeIqResult(pid)
|
||||||
|
iq.set('to',pto)
|
||||||
|
iq.append(query)
|
||||||
return iq
|
return iq
|
||||||
|
|
||||||
def makeIqMethodError(self,pto,id,pmethod,params,condition):
|
def makeIqMethodError(self,pto,pid,pmethod,params,condition):
|
||||||
iq = self.xmpp.makeIqError(id)
|
iq = self.self.makeMethodCallQuery(pto,pmethod,params)
|
||||||
iq.set('to',pto)
|
iq.setValues({'id':pid,'type':'error'})
|
||||||
iq.append(self.makeMethodCallQuery(pmethod,params))
|
|
||||||
iq.append(self.xmpp['xep_0086'].makeError(condition))
|
iq.append(self.xmpp['xep_0086'].makeError(condition))
|
||||||
return iq
|
return iq
|
||||||
|
|
||||||
|
@ -56,17 +56,13 @@ class xep_0199(base.base_plugin):
|
|||||||
Sends a ping to the specified jid, returning the time (in seconds)
|
Sends a ping to the specified jid, returning the time (in seconds)
|
||||||
to receive a reply, or None if no reply is received in timeout seconds.
|
to receive a reply, or None if no reply is received in timeout seconds.
|
||||||
"""
|
"""
|
||||||
id = self.xmpp.getNewId()
|
iq = self.xmpp.makeIqGet()
|
||||||
iq = self.xmpp.makeIq(id)
|
|
||||||
iq.attrib['type'] = 'get'
|
|
||||||
iq.attrib['to'] = jid
|
iq.attrib['to'] = jid
|
||||||
ping = ET.Element('{http://www.xmpp.org/extensions/xep-0199.html#ns}ping')
|
ping = ET.Element('{http://www.xmpp.org/extensions/xep-0199.html#ns}ping')
|
||||||
iq.append(ping)
|
iq.append(ping)
|
||||||
startTime = time.clock()
|
startTime = time.clock()
|
||||||
#pingresult = self.xmpp.send(iq, self.xmpp.makeIq(id), timeout)
|
|
||||||
pingresult = iq.send()
|
pingresult = iq.send()
|
||||||
endTime = time.clock()
|
endTime = time.clock()
|
||||||
if pingresult == False:
|
if pingresult == False:
|
||||||
#self.xmpp.disconnect(reconnect=True)
|
|
||||||
return False
|
return False
|
||||||
return endTime - startTime
|
return endTime - startTime
|
||||||
|
Loading…
x
Reference in New Issue
Block a user