| 56 | |
| 57 | |
| 58 | class ClientExceptionsFactory: |
| 59 | def __init__(self): |
| 60 | self._client_exceptions_cache = {} |
| 61 | |
| 62 | def create_client_exceptions(self, service_model): |
| 63 | """Creates a ClientExceptions object for the particular service client |
| 64 | |
| 65 | :type service_model: botocore.model.ServiceModel |
| 66 | :param service_model: The service model for the client |
| 67 | |
| 68 | :rtype: object that subclasses from BaseClientExceptions |
| 69 | :returns: The exceptions object of a client that can be used |
| 70 | to grab the various different modeled exceptions. |
| 71 | """ |
| 72 | service_name = service_model.service_name |
| 73 | if service_name not in self._client_exceptions_cache: |
| 74 | client_exceptions = self._create_client_exceptions(service_model) |
| 75 | self._client_exceptions_cache[service_name] = client_exceptions |
| 76 | return self._client_exceptions_cache[service_name] |
| 77 | |
| 78 | def _create_client_exceptions(self, service_model): |
| 79 | cls_props = {} |
| 80 | code_to_exception = {} |
| 81 | for error_shape in service_model.error_shapes: |
| 82 | exception_name = str(error_shape.name) |
| 83 | exception_cls = type(exception_name, (ClientError,), {}) |
| 84 | cls_props[exception_name] = exception_cls |
| 85 | code = str(error_shape.error_code) |
| 86 | code_to_exception[code] = exception_cls |
| 87 | cls_name = str(get_service_module_name(service_model) + 'Exceptions') |
| 88 | client_exceptions_cls = type( |
| 89 | cls_name, (BaseClientExceptions,), cls_props |
| 90 | ) |
| 91 | return client_exceptions_cls(code_to_exception) |
no outgoing calls