U
    m/e                     @   s8   d dl mZ d dlmZ G dd dZG dd dZdS )    )ClientError)get_service_module_namec                   @   s(   e Zd ZeZdd Zdd Zdd ZdS )BaseClientExceptionsc                 C   s
   || _ dS )a  Base class for exceptions object on a client

        :type code_to_exception: dict
        :param code_to_exception: Mapping of error codes (strings) to exception
            class that should be raised when encountering a particular
            error code.
        N)_code_to_exception)selfcode_to_exception r   9/tmp/pip-unpacked-wheel-3gylhwtm/botocore/errorfactory.py__init__   s    zBaseClientExceptions.__init__c                 C   s   | j || jS )aN  Retrieves the error class based on the error code

        This is helpful for identifying the exception class needing to be
        caught based on the ClientError.parsed_reponse['Error']['Code'] value

        :type error_code: string
        :param error_code: The error code associated to a ClientError exception

        :rtype: ClientError or a subclass of ClientError
        :returns: The appropriate modeled exception class for that error
            code. If the error code does not match any of the known
            modeled exceptions then return a generic ClientError.
        )r   getr   )r   
error_coder   r   r	   	from_code   s    zBaseClientExceptions.from_codec                 C   s6   dd | j  D }t|  d| dd| d S )Nc                 S   s   g | ]
}|j qS r   )__name__).0exception_clsr   r   r	   
<listcomp>/   s   z4BaseClientExceptions.__getattr__.<locals>.<listcomp>z object has no attribute z. Valid exceptions are: z, )r   valuesAttributeErrorjoin)r   nameZexception_cls_namesr   r   r	   __getattr__.   s    z BaseClientExceptions.__getattr__N)r   
__module____qualname__r   r
   r   r   r   r   r   r	   r      s   
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )ClientExceptionsFactoryc                 C   s
   i | _ d S )N)_client_exceptions_cache)r   r   r   r	   r
   :   s    z ClientExceptionsFactory.__init__c                 C   s.   |j }|| jkr$| |}|| j|< | j| S )a  Creates a ClientExceptions object for the particular service client

        :type service_model: botocore.model.ServiceModel
        :param service_model: The service model for the client

        :rtype: object that subclasses from BaseClientExceptions
        :returns: The exceptions object of a client that can be used
            to grab the various different modeled exceptions.
        )service_namer   _create_client_exceptions)r   service_modelr   Zclient_exceptionsr   r   r	   create_client_exceptions=   s
    



z0ClientExceptionsFactory.create_client_exceptionsc           
      C   sl   i }i }|j D ]6}t|j}t|tfi }|||< t|j}|||< qtt|d }t|tf|}	|	|S )NZ
Exceptions)Zerror_shapesstrr   typer   r   r   r   )
r   r   Z	cls_propsr   Zerror_shapeexception_namer   codeZcls_nameZclient_exceptions_clsr   r   r	   r   M   s    



  z1ClientExceptionsFactory._create_client_exceptionsN)r   r   r   r
   r   r   r   r   r   r	   r   9   s   r   N)Zbotocore.exceptionsr   Zbotocore.utilsr   r   r   r   r   r   r	   <module>   s   (