o
    .&ßa�  ã                   @   s<   d dl mZ d dlmZ G dd„ deƒZG dd„ deƒ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   ú7/usr/lib/python3/dist-packages/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   s,   dd„ | j  ¡ D ƒ}td| |d |¡f ƒ‚)Nc                 S   s   g | ]}|j ‘qS r   )Ú__name__)Ú.0Úexception_clsr   r   r	   Ú
<listcomp>/   s    ÿz4BaseClientExceptions.__getattr__.<locals>.<listcomp>z7%r object has no attribute %r. Valid exceptions are: %sz, )r   ÚvaluesÚAttributeErrorÚjoin)r   ÚnameÚ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
   9   s   
z ClientExceptionsFactory.__init__c                 C   s.   |j }|| jv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   Úclient_exceptionsr   r   r	   Úcreate_client_exceptions<   s
   




z0ClientExceptionsFactory.create_client_exceptionsc           
      C   sl   i }i }|j D ]}t|jƒ}t|tfi ƒ}|||< t|jƒ}|||< qtt|ƒd ƒ}t|tf|ƒ}	|	|ƒS )NÚ
Exceptions)Úerror_shapesÚstrr   Útyper   r   r   r   )
r   r   Ú	cls_propsr   Úerror_shapeÚexception_namer   ÚcodeÚcls_nameÚclient_exceptions_clsr   r   r	   r   L   s   



ÿz1ClientExceptionsFactory._create_client_exceptionsN)r   r   r   r
   r    r   r   r   r   r	   r   8   s    r   N)Úbotocore.exceptionsr   Úbotocore.utilsr   Úobjectr   r   r   r   r   r	   Ú<module>   s   '