U
    ´.¬b®-  ã                   @   sZ   d dl Z d dlmZ ddlmZ dd„ Zddd„Zd	d
„ ZG dd„ dƒZG dd„ dƒZ	dS )é    N)Ú
xform_nameé   )Úget_data_memberc                 C   s   | D ]}|dkr dS qdS )zÍ
    Return True if all elements of the iterable are not None (or if the
    iterable is empty). This is like the built-in ``all``, except checks
    against None, so 0 and False are allowable values.
    NFT© )ÚiterableÚelementr   r   ú</tmp/pip-unpacked-wheel-7h_bjh9e/boto3/resources/response.pyÚall_not_none   s    r	   c           	      C   sª   g }| D ]œ}|j }|j}|dkr0t |j|¡}nb|dkrHt |j|¡}nJ|dkrbt|t|jƒƒ}n0|dkrxt||jƒ}n|dkr„qnt	d|› �ƒ‚| 
t|ƒ|f¡ q|S )aË  
    Builds a mapping of identifier names to values based on the
    identifier source location, type, and target. Identifier
    values may be scalars or lists depending on the source type
    and location.

    :type identifiers: list
    :param identifiers: List of :py:class:`~boto3.resources.model.Parameter`
                        definitions
    :type parent: ServiceResource
    :param parent: The resource instance to which this action is attached.
    :type params: dict
    :param params: Request parameters sent to the service.
    :type raw_response: dict
    :param raw_response: Low-level operation response.
    :rtype: list
    :return: An ordered list of ``(name, value)`` identifier tuples.
    ÚresponseZrequestParameterÚ
identifierÚdataÚinputzUnsupported source type: )ÚsourceÚtargetÚjmespathÚsearchÚpathÚgetattrr   Únamer   ÚNotImplementedErrorÚappend)	ÚidentifiersÚparentÚparamsÚraw_responseÚresultsr   r   r   Úvaluer   r   r   Úbuild_identifiers    s"    r   c                 C   sž   d}|  |¡}|j}| rl|  d¡D ]H}| d¡}|jdkrF|j| }q"|jdkrX|j}q"td |j|¡ƒ‚q"|jdkr|i }n|jdkrŒg }n|jdkrši }|S )a�  
    Creates an appropriate empty response for the type that is expected,
    based on the service model's shape type. For example, a value that
    is normally a list would then return an empty list. A structure would
    return an empty dict, and a number would return None.

    :type search_path: string
    :param search_path: JMESPath expression to search in the response
    :type operation_name: string
    :param operation_name: Name of the underlying service operation.
    :type service_model: :ref:`botocore.model.ServiceModel`
    :param service_model: The Botocore service model
    :rtype: dict, list, or None
    :return: An appropriate empty value
    NÚ.z[0123456789]$Z	structureÚlistz&Search path hits shape type {} from {}Úmap)	Úoperation_modelZoutput_shapeÚsplitÚstripÚ	type_nameÚmembersÚmemberr   Úformat)Úsearch_pathÚoperation_nameÚservice_modelr
   r!   ÚshapeÚitemr   r   r   Úbuild_empty_responseN   s.    



 ÿÿ


r-   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
RawHandleraG  
    A raw action response handler. This passed through the response
    dictionary, optionally after performing a JMESPath search if one
    has been defined for the action.

    :type search_path: string
    :param search_path: JMESPath expression to search in the response
    :rtype: dict
    :return: Service response
    c                 C   s
   || _ d S ©N)r(   )Úselfr(   r   r   r   Ú__init__�   s    zRawHandler.__init__c                 C   s"   | j r| j dkrt | j |¡}|S )á,  
        :type parent: ServiceResource
        :param parent: The resource instance to which this action is attached.
        :type params: dict
        :param params: Request parameters sent to the service.
        :type response: dict
        :param response: Low-level operation response.
        ú$)r(   r   r   )r0   r   r   r
   r   r   r   Ú__call__�   s    
zRawHandler.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r1   r4   r   r   r   r   r.   �   s   r.   c                   @   s*   e Zd ZdZd	dd„Zdd„ Zdd„ ZdS )
ÚResourceHandleraf  
    Creates a new resource or list of new resources from the low-level
    response based on the given response resource definition.

    :type search_path: string
    :param search_path: JMESPath expression to search in the response

    :type factory: ResourceFactory
    :param factory: The factory that created the resource class to which
                    this action is attached.

    :type resource_model: :py:class:`~boto3.resources.model.ResponseResource`
    :param resource_model: Response resource model.

    :type service_context: :py:class:`~boto3.utils.ServiceContext`
    :param service_context: Context about the AWS service

    :type operation_name: string
    :param operation_name: Name of the underlying service operation, if it
                           exists.

    :rtype: ServiceResource or list
    :return: New resource instance(s).
    Nc                 C   s"   || _ || _|| _|| _|| _d S r/   )r(   ÚfactoryÚresource_modelr)   Úservice_context)r0   r(   r:   r;   r<   r)   r   r   r   r1   º   s
    zResourceHandler.__init__c              	   C   sø   | j j}| jj |¡}| jj||| jd�}|}d}| jrFt 	| j|¡}t
t| j j|||ƒƒ}	dd„ |	 ¡ D ƒ}
|
r´g }tt|
d ƒƒD ]*}d}|rš|| }| |  |||	|¡¡ q†n@t|	 ¡ ƒrÒ|  |||	|¡}n"d}| jdk	rôt| j| j| jjƒ}|S )r2   )Úresource_nameZsingle_resource_json_definitionr<   Nc                 S   s   g | ]}t |tƒr|‘qS r   )Ú
isinstancer   )Ú.0Úvr   r   r   Ú
<listcomp>ò   s     
 z,ResourceHandler.__call__.<locals>.<listcomp>r   )r;   Útyper<   Zresource_json_definitionsÚgetr:   Zload_from_definitionr(   r   r   Údictr   r   ÚvaluesÚrangeÚlenr   Úhandle_response_itemr	   r)   r-   r*   )r0   r   r   r
   r=   Zjson_definitionÚresource_clsr   Zsearch_responser   ÚpluralÚiZresponse_itemr   r   r   r4   È   sf    	ÿý   ÿÿ   ÿÿ   ÿ
ýzResourceHandler.__call__c           	      C   sX   d|j ji}| ¡ D ]$\}}t|tƒr0| d¡}|||< q|f |Ž}|dk	rT||j _|S )a�  
        Handles the creation of a single response item by setting
        parameters and creating the appropriate resource instance.

        :type resource_cls: ServiceResource subclass
        :param resource_cls: The resource class to instantiate.
        :type parent: ServiceResource
        :param parent: The resource instance to which this action is attached.
        :type identifiers: dict
        :param identifiers: Map of identifier names to value or values.
        :type resource_data: dict or None
        :param resource_data: Data for resource attributes.
        :rtype: ServiceResource
        :return: New resource instance.
        Úclientr   N)ÚmetarL   Úitemsr>   r   Úpopr   )	r0   rI   r   r   Zresource_dataÚkwargsr   r   Úresourcer   r   r   rH     s     ÿ



z$ResourceHandler.handle_response_item)N)r5   r6   r7   r8   r1   r4   rH   r   r   r   r   r9       s
    ú
Tr9   )NN)
r   Zbotocorer   r   r   r	   r   r-   r.   r9   r   r   r   r   Ú<module>   s   
.3