o
    iv-                     @   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u 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   O/home/app/Keep/.python/lib/python3.10/site-packages/boto3/resources/response.pyall_not_none   s
   r	   c           	      C   s   g }| D ]M}|j }|j}|dkrt|j|}n0|dkr$t|j|}n$|dkr1t|t|j}n|dkr<t||j}n|dkrAq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}| r7| dD ]%}|d}|jdkr#|j| }q|jdkr,|j}qtd|j d| |jdkr@i }|S |jdkrIg }|S |jdkrPi }|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 z from map)operation_modelZoutput_shapesplitstrip	type_namemembersmemberr   )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   )r/   r   r   r
   r   r   r   __call__   s   
zRawHandler.__call__N)__name__
__module____qualname____doc__r0   r3   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)r/   r'   r9   r:   r;   r(   r   r   r   r0      s
   
zResourceHandler.__init__c              	   C   s   | j j}| jj|}| jj||| jd}|}d}| jr#t	| j|}t
t| j j|||}	dd |	 D }
|
r[g }tt|
d D ]}d}|rM|| }|| |||	| qC|S t|	 rk| |||	|}|S d}| jdur|t| j| j| jj}|S )r1   )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getr9   Zload_from_definitionr'   r   r   dictr   r   valuesrangelenr   handle_response_itemr	   r(   r,   r)   )r/   r   r   r
   r<   Zjson_definitionresource_clsr   Zsearch_responser   pluraliZresponse_itemr   r   r   r3      sX   	
zResourceHandler.__call__c           	      C   s\   d|j ji}| D ]\}}t|tr|d}|||< q
|di |}|dur,||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   Nr   )metarK   itemsr=   r   popr   )	r/   rH   r   r   Zresource_datakwargsr   r   resourcer   r   r   rG     s   


z$ResourceHandler.handle_response_itemr.   )r4   r5   r6   r7   r0   r3   rG   r   r   r   r   r8      s    
Tr8   )NN)
r   Zbotocorer   r   r   r	   r   r,   r-   r8   r   r   r   r   <module>   s   
.1