fake_select.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2011 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. """
  16. A mock-up module of select
  17. *** NOTE ***
  18. It is only for testing stats_httpd module and not reusable for
  19. external module.
  20. """
  21. import fake_socket
  22. import errno
  23. class error(Exception):
  24. pass
  25. def select(rlst, wlst, xlst, timeout):
  26. if type(timeout) != int and type(timeout) != float:
  27. raise TypeError("Error: %s must be integer or float"
  28. % timeout.__class__.__name__)
  29. for s in rlst + wlst + xlst:
  30. if type(s) != fake_socket.socket:
  31. raise TypeError("Error: %s must be a dummy socket"
  32. % s.__class__.__name__)
  33. s._called = s._called + 1
  34. if s._called > 3:
  35. raise error("Something is happened!")
  36. elif s._called > 2:
  37. raise error(errno.EINTR)
  38. return (rlst, wlst, xlst)