_exceptions.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. websocket - WebSocket client library for Python
  3. Copyright (C) 2010 Hiroki Ohtani(liris)
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1335 USA
  16. """
  17. """
  18. define websocket exceptions
  19. """
  20. class WebSocketException(Exception):
  21. """
  22. websocket exception class.
  23. """
  24. pass
  25. class WebSocketProtocolException(WebSocketException):
  26. """
  27. If the websocket protocol is invalid, this exception will be raised.
  28. """
  29. pass
  30. class WebSocketPayloadException(WebSocketException):
  31. """
  32. If the websocket payload is invalid, this exception will be raised.
  33. """
  34. pass
  35. class WebSocketConnectionClosedException(WebSocketException):
  36. """
  37. If remote host closed the connection or some network error happened,
  38. this exception will be raised.
  39. """
  40. pass
  41. class WebSocketTimeoutException(WebSocketException):
  42. """
  43. WebSocketTimeoutException will be raised at socket timeout during read/write data.
  44. """
  45. pass
  46. class WebSocketProxyException(WebSocketException):
  47. """
  48. WebSocketProxyException will be raised when proxy error occurred.
  49. """
  50. pass
  51. class WebSocketBadStatusException(WebSocketException):
  52. """
  53. WebSocketBadStatusException will be raised when we get bad handshake status code.
  54. """
  55. def __init__(self, message, status_code, status_message=None, resp_headers=None):
  56. msg = message % (status_code, status_message)
  57. super(WebSocketBadStatusException, self).__init__(msg)
  58. self.status_code = status_code
  59. self.resp_headers = resp_headers
  60. class WebSocketAddressException(WebSocketException):
  61. """
  62. If the websocket address info cannot be found, this exception will be raised.
  63. """
  64. pass