def upgradeWithIQResponseTracker(xs):
 def callback(iq):
  '\n        Handle iq response by firing associated deferred.\n        '
  if getattr(iq, 'handled', False):
   return
  try:
   d = xs.iqDeferreds[iq['id']]
  except KeyError:
   pass
  else:
   del xs.iqDeferreds[iq['id']]
   iq.handled = True
   if (iq['type'] == 'error'):
    d.errback(error.exceptionFromStanza(iq))
   else:
    d.callback(iq)
 def disconnected(_):
  "\n        Make sure deferreds do not linger on after disconnect.\n\n        This errbacks all deferreds of iq's for which no response has been\n        received with a L{ConnectionLost} failure. Otherwise, the deferreds\n        will never be fired.\n        "
  iqDeferreds = xs.iqDeferreds
  xs.iqDeferreds = {}
  for d in iqDeferreds.itervalues():
   d.errback(ConnectionLost())
 xs.iqDeferreds = {}
 xs.iqDefaultTimeout = getattr(xs, 'iqDefaultTimeout', None)
 xs.addObserver(xmlstream.STREAM_END_EVENT, disconnected)
 xs.addObserver('/iq[@type="result"]', callback)
 xs.addObserver('/iq[@type="error"]', callback)
 directlyProvides(xs, ijabber.IIQResponseTracker)

def upgradeWithIQResponseTracker ( xs ) : def callback ( iq ) : if getattr ( iq , 'handled' , False ) : return try : d = xs . iqDeferreds [ iq [ 'id' ] ] except KeyError : pass else : del xs . iqDeferreds [ iq [ 'id' ] ] iq . handled = True if ( iq [ 'type' ] == 'error' ) : d . errback ( error . exceptionFromStanza ( iq ) ) else : d . callback ( iq ) def disconnected ( _ ) : iqDeferreds = xs . iqDeferreds xs . iqDeferreds = { } for d in iqDeferreds . itervalues ( ) : d . errback ( ConnectionLost ( ) ) xs . iqDeferreds = { } xs . iqDefaultTimeout = getattr ( xs , 'iqDefaultTimeout' , None ) xs . addObserver ( xmlstream . STREAM_END_EVENT , disconnected ) xs . addObserver ( '/iq[@type="result"]' , callback ) xs . addObserver ( '/iq[@type="error"]' , callback ) directlyProvides ( xs , ijabber . IIQResponseTracker )
enhances an xmlstream for iq response tracking .