gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.5KB

  1. ##########################################################################
  2. #
  3. # pgAdmin 4 - PostgreSQL Tools
  4. #
  5. # Copyright (C) 2013 - 2020, The pgAdmin Development Team
  6. # This software is released under the PostgreSQL Licence
  7. #
  8. ##########################################################################
  9. from werkzeug.exceptions import HTTPException
  10. from werkzeug.http import HTTP_STATUS_CODES
  11. from flask_babelex import gettext as _
  12. from flask import request
  13. from pgadmin.utils.ajax import service_unavailable, gone
  14. class ConnectionLost(HTTPException):
  15. """
  16. Exception
  17. """
  18. def __init__(self, _server_id, _database_name, _conn_id):
  19. self.sid = _server_id
  20. self.db = _database_name
  21. self.conn_id = _conn_id
  22. HTTPException.__init__(self)
  23. @property
  24. def name(self):
  25. return HTTP_STATUS_CODES.get(503, 'Service Unavailable')
  26. def get_response(self, environ=None):
  27. return service_unavailable(
  28. _("Connection to the server has been lost."),
  29. info="CONNECTION_LOST",
  30. data={
  31. 'sid': self.sid,
  32. 'database': self.db,
  33. 'conn_id': self.conn_id
  34. }
  35. )
  36. def __str__(self):
  37. return "Connection (id #{2}) lost for the server (#{0}) on " \
  38. "database ({1})".format(self.sid, self.db, self.conn_id)
  39. def __repr__(self):
  40. return "Connection (id #{2}) lost for the server (#{0}) on " \
  41. "database ({1})".format(self.sid, self.db, self.conn_id)
  42. class SSHTunnelConnectionLost(HTTPException):
  43. """
  44. Exception when connection to SSH tunnel is lost
  45. """
  46. def __init__(self, _tunnel_host):
  47. self.tunnel_host = _tunnel_host
  48. HTTPException.__init__(self)
  49. @property
  50. def name(self):
  51. return HTTP_STATUS_CODES.get(503, 'Service Unavailable')
  52. def get_response(self, environ=None):
  53. return service_unavailable(
  54. _("Connection to the SSH Tunnel for host '{0}' has been lost. "
  55. "Reconnect to the database server.").format(self.tunnel_host),
  56. info="SSH_TUNNEL_CONNECTION_LOST",
  57. data={
  58. 'tunnel_host': self.tunnel_host
  59. }
  60. )
  61. def __str__(self):
  62. return "Connection to the SSH Tunnel for host '{0}' has been lost. " \
  63. "Reconnect to the database server".format(self.tunnel_host)
  64. def __repr__(self):
  65. return "Connection to the SSH Tunnel for host '{0}' has been lost. " \
  66. "Reconnect to the database server".format(self.tunnel_host)
  67. class CryptKeyMissing(HTTPException):
  68. """
  69. Exception
  70. """
  71. def __init__(self):
  72. HTTPException.__init__(self)
  73. @property
  74. def name(self):
  75. return HTTP_STATUS_CODES.get(503, 'Service Unavailable')
  76. def get_response(self, environ=None):
  77. return service_unavailable(
  78. _("Crypt key is missing."),
  79. info="CRYPTKEY_MISSING",
  80. )
  81. def __str__(self):
  82. return "Crypt key is missing."
  83. def __repr__(self):
  84. return "Crypt key is missing."
  85. class ObjectGone(HTTPException):
  86. """
  87. Exception
  88. """
  89. def __init__(self, error_msg):
  90. self.error_msg = error_msg
  91. HTTPException.__init__(self)
  92. @property
  93. def name(self):
  94. return HTTP_STATUS_CODES.get(410, 'Gone')
  95. def get_response(self, environ=None):
  96. return gone(self.error_msg)
  97. def __str__(self):
  98. return self.error_msg
  99. def __repr__(self):
  100. return self.error_msg
上海开阖软件有限公司 沪ICP备12045867号-1