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.

160 lines
5.0 KiB

2 years ago
  1. # coding: utf-8
  2. """
  3. Seaweedfs Master Server API
  4. The Seaweedfs Master Server API allows you to store blobs # noqa: E501
  5. The version of the OpenAPI document: 3.43.0
  6. Generated by: https://openapi-generator.tech
  7. """
  8. class OpenApiException(Exception):
  9. """The base exception class for all OpenAPIExceptions"""
  10. class ApiTypeError(OpenApiException, TypeError):
  11. def __init__(self, msg, path_to_item=None, valid_classes=None,
  12. key_type=None):
  13. """ Raises an exception for TypeErrors
  14. Args:
  15. msg (str): the exception message
  16. Keyword Args:
  17. path_to_item (list): a list of keys an indices to get to the
  18. current_item
  19. None if unset
  20. valid_classes (tuple): the primitive classes that current item
  21. should be an instance of
  22. None if unset
  23. key_type (bool): False if our value is a value in a dict
  24. True if it is a key in a dict
  25. False if our item is an item in a list
  26. None if unset
  27. """
  28. self.path_to_item = path_to_item
  29. self.valid_classes = valid_classes
  30. self.key_type = key_type
  31. full_msg = msg
  32. if path_to_item:
  33. full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
  34. super(ApiTypeError, self).__init__(full_msg)
  35. class ApiValueError(OpenApiException, ValueError):
  36. def __init__(self, msg, path_to_item=None):
  37. """
  38. Args:
  39. msg (str): the exception message
  40. Keyword Args:
  41. path_to_item (list) the path to the exception in the
  42. received_data dict. None if unset
  43. """
  44. self.path_to_item = path_to_item
  45. full_msg = msg
  46. if path_to_item:
  47. full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
  48. super(ApiValueError, self).__init__(full_msg)
  49. class ApiAttributeError(OpenApiException, AttributeError):
  50. def __init__(self, msg, path_to_item=None):
  51. """
  52. Raised when an attribute reference or assignment fails.
  53. Args:
  54. msg (str): the exception message
  55. Keyword Args:
  56. path_to_item (None/list) the path to the exception in the
  57. received_data dict
  58. """
  59. self.path_to_item = path_to_item
  60. full_msg = msg
  61. if path_to_item:
  62. full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
  63. super(ApiAttributeError, self).__init__(full_msg)
  64. class ApiKeyError(OpenApiException, KeyError):
  65. def __init__(self, msg, path_to_item=None):
  66. """
  67. Args:
  68. msg (str): the exception message
  69. Keyword Args:
  70. path_to_item (None/list) the path to the exception in the
  71. received_data dict
  72. """
  73. self.path_to_item = path_to_item
  74. full_msg = msg
  75. if path_to_item:
  76. full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
  77. super(ApiKeyError, self).__init__(full_msg)
  78. class ApiException(OpenApiException):
  79. def __init__(self, status=None, reason=None, http_resp=None):
  80. if http_resp:
  81. self.status = http_resp.status
  82. self.reason = http_resp.reason
  83. self.body = http_resp.data
  84. self.headers = http_resp.getheaders()
  85. else:
  86. self.status = status
  87. self.reason = reason
  88. self.body = None
  89. self.headers = None
  90. def __str__(self):
  91. """Custom error messages for exception"""
  92. error_message = "({0})\n"\
  93. "Reason: {1}\n".format(self.status, self.reason)
  94. if self.headers:
  95. error_message += "HTTP response headers: {0}\n".format(
  96. self.headers)
  97. if self.body:
  98. error_message += "HTTP response body: {0}\n".format(self.body)
  99. return error_message
  100. class NotFoundException(ApiException):
  101. def __init__(self, status=None, reason=None, http_resp=None):
  102. super(NotFoundException, self).__init__(status, reason, http_resp)
  103. class UnauthorizedException(ApiException):
  104. def __init__(self, status=None, reason=None, http_resp=None):
  105. super(UnauthorizedException, self).__init__(status, reason, http_resp)
  106. class ForbiddenException(ApiException):
  107. def __init__(self, status=None, reason=None, http_resp=None):
  108. super(ForbiddenException, self).__init__(status, reason, http_resp)
  109. class ServiceException(ApiException):
  110. def __init__(self, status=None, reason=None, http_resp=None):
  111. super(ServiceException, self).__init__(status, reason, http_resp)
  112. def render_path(path_to_item):
  113. """Returns a string representation of a path"""
  114. result = ""
  115. for pth in path_to_item:
  116. if isinstance(pth, int):
  117. result += "[{0}]".format(pth)
  118. else:
  119. result += "['{0}']".format(pth)
  120. return result