HTTPChannel_extensions.py 1.4 KB

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