|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + Control-M Services |
| 5 | +
|
| 6 | + Provides access to BMC Control-M Services # noqa: E501 |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 9.22.30 |
| 9 | + Contact: customer_support@bmc.com |
| 10 | + Generated by: https://openapi-generator.tech |
| 11 | +""" |
| 12 | + |
| 13 | + |
| 14 | +import six |
| 15 | + |
| 16 | + |
| 17 | +class OpenApiException(Exception): |
| 18 | + """The base exception class for all OpenAPIExceptions""" |
| 19 | + |
| 20 | + |
| 21 | +class ApiTypeError(OpenApiException, TypeError): |
| 22 | + def __init__(self, msg, path_to_item=None, valid_classes=None, |
| 23 | + key_type=None): |
| 24 | + """ Raises an exception for TypeErrors |
| 25 | +
|
| 26 | + Args: |
| 27 | + msg (str): the exception message |
| 28 | +
|
| 29 | + Keyword Args: |
| 30 | + path_to_item (list): a list of keys an indices to get to the |
| 31 | + current_item |
| 32 | + None if unset |
| 33 | + valid_classes (tuple): the primitive classes that current item |
| 34 | + should be an instance of |
| 35 | + None if unset |
| 36 | + key_type (bool): False if our value is a value in a dict |
| 37 | + True if it is a key in a dict |
| 38 | + False if our item is an item in a list |
| 39 | + None if unset |
| 40 | + """ |
| 41 | + self.path_to_item = path_to_item |
| 42 | + self.valid_classes = valid_classes |
| 43 | + self.key_type = key_type |
| 44 | + full_msg = msg |
| 45 | + if path_to_item: |
| 46 | + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) |
| 47 | + super(ApiTypeError, self).__init__(full_msg) |
| 48 | + |
| 49 | + |
| 50 | +class ApiValueError(OpenApiException, ValueError): |
| 51 | + def __init__(self, msg, path_to_item=None): |
| 52 | + """ |
| 53 | + Args: |
| 54 | + msg (str): the exception message |
| 55 | +
|
| 56 | + Keyword Args: |
| 57 | + path_to_item (list) the path to the exception in the |
| 58 | + received_data dict. None if unset |
| 59 | + """ |
| 60 | + |
| 61 | + self.path_to_item = path_to_item |
| 62 | + full_msg = msg |
| 63 | + if path_to_item: |
| 64 | + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) |
| 65 | + super(ApiValueError, self).__init__(full_msg) |
| 66 | + |
| 67 | + |
| 68 | +class ApiAttributeError(OpenApiException, AttributeError): |
| 69 | + def __init__(self, msg, path_to_item=None): |
| 70 | + """ |
| 71 | + Raised when an attribute reference or assignment fails. |
| 72 | +
|
| 73 | + Args: |
| 74 | + msg (str): the exception message |
| 75 | +
|
| 76 | + Keyword Args: |
| 77 | + path_to_item (None/list) the path to the exception in the |
| 78 | + received_data dict |
| 79 | + """ |
| 80 | + self.path_to_item = path_to_item |
| 81 | + full_msg = msg |
| 82 | + if path_to_item: |
| 83 | + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) |
| 84 | + super(ApiAttributeError, self).__init__(full_msg) |
| 85 | + |
| 86 | + |
| 87 | +class ApiKeyError(OpenApiException, KeyError): |
| 88 | + def __init__(self, msg, path_to_item=None): |
| 89 | + """ |
| 90 | + Args: |
| 91 | + msg (str): the exception message |
| 92 | +
|
| 93 | + Keyword Args: |
| 94 | + path_to_item (None/list) the path to the exception in the |
| 95 | + received_data dict |
| 96 | + """ |
| 97 | + self.path_to_item = path_to_item |
| 98 | + full_msg = msg |
| 99 | + if path_to_item: |
| 100 | + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) |
| 101 | + super(ApiKeyError, self).__init__(full_msg) |
| 102 | + |
| 103 | + |
| 104 | +class ApiException(OpenApiException): |
| 105 | + |
| 106 | + def __init__(self, status=None, reason=None, http_resp=None): |
| 107 | + if http_resp: |
| 108 | + self.status = http_resp.status |
| 109 | + self.reason = http_resp.reason |
| 110 | + self.body = http_resp.data |
| 111 | + self.headers = http_resp.getheaders() |
| 112 | + else: |
| 113 | + self.status = status |
| 114 | + self.reason = reason |
| 115 | + self.body = None |
| 116 | + self.headers = None |
| 117 | + |
| 118 | + def __str__(self): |
| 119 | + """Custom error messages for exception""" |
| 120 | + error_message = "({0})\n"\ |
| 121 | + "Reason: {1}\n".format(self.status, self.reason) |
| 122 | + if self.headers: |
| 123 | + error_message += "HTTP response headers: {0}\n".format( |
| 124 | + self.headers) |
| 125 | + |
| 126 | + if self.body: |
| 127 | + error_message += "HTTP response body: {0}\n".format(self.body) |
| 128 | + |
| 129 | + return error_message |
| 130 | + |
| 131 | + |
| 132 | +class NotFoundException(ApiException): |
| 133 | + |
| 134 | + def __init__(self, status=None, reason=None, http_resp=None): |
| 135 | + super(NotFoundException, self).__init__(status, reason, http_resp) |
| 136 | + |
| 137 | + |
| 138 | +class UnauthorizedException(ApiException): |
| 139 | + |
| 140 | + def __init__(self, status=None, reason=None, http_resp=None): |
| 141 | + super(UnauthorizedException, self).__init__(status, reason, http_resp) |
| 142 | + |
| 143 | + |
| 144 | +class ForbiddenException(ApiException): |
| 145 | + |
| 146 | + def __init__(self, status=None, reason=None, http_resp=None): |
| 147 | + super(ForbiddenException, self).__init__(status, reason, http_resp) |
| 148 | + |
| 149 | + |
| 150 | +class ServiceException(ApiException): |
| 151 | + |
| 152 | + def __init__(self, status=None, reason=None, http_resp=None): |
| 153 | + super(ServiceException, self).__init__(status, reason, http_resp) |
| 154 | + |
| 155 | + |
| 156 | +def render_path(path_to_item): |
| 157 | + """Returns a string representation of a path""" |
| 158 | + result = "" |
| 159 | + for pth in path_to_item: |
| 160 | + if isinstance(pth, six.integer_types): |
| 161 | + result += "[{0}]".format(pth) |
| 162 | + else: |
| 163 | + result += "['{0}']".format(pth) |
| 164 | + return result |
0 commit comments