main.py 1006 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- test-case-name: twisted.internet.test.test_main -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Backwards compatibility, and utility functions.
  6. In general, this module should not be used, other than by reactor authors
  7. who need to use the 'installReactor' method.
  8. """
  9. from twisted.internet import error
  10. CONNECTION_DONE = error.ConnectionDone("Connection done")
  11. CONNECTION_LOST = error.ConnectionLost("Connection lost")
  12. def installReactor(reactor):
  13. """
  14. Install reactor C{reactor}.
  15. @param reactor: An object that provides one or more IReactor* interfaces.
  16. """
  17. # this stuff should be common to all reactors.
  18. import sys
  19. import twisted.internet
  20. if "twisted.internet.reactor" in sys.modules:
  21. raise error.ReactorAlreadyInstalledError("reactor already installed")
  22. twisted.internet.reactor = reactor
  23. sys.modules["twisted.internet.reactor"] = reactor
  24. __all__ = ["CONNECTION_LOST", "CONNECTION_DONE", "installReactor"]