_exceptions.py 2.3 KB

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