HTTPChannel-extensions.py 974 B

12345678910111213141516171819202122232425262728293031323334
  1. """
  2. HTTPChannel-extensions module: contains methods to extend functionality
  3. of the HTTPChannel class
  4. """
  5. def spawnTask(self, name = None, callback = None, extraArgs = []):
  6. """Spawns a task to service the download recently requested
  7. via beginGetDocument(), etc., and/or downloadToFile() or
  8. downloadToRam(). If a callback is specified, that function is
  9. called when the download is complete, passing in the extraArgs
  10. given.
  11. Returns the newly-spawned task.
  12. """
  13. if not name:
  14. name = self.getUrl().cStr()
  15. import Task
  16. task = Task.Task(self.doTask)
  17. task.callback = callback
  18. task.extraArgs = extraArgs
  19. return taskMgr.add(task, name)
  20. def doTask(self, task):
  21. import Task
  22. if self.run():
  23. return Task.cont
  24. if task.callback:
  25. task.callback(*task.extraArgs)
  26. return Task.done