U
    Zf2                     @   s(   d d Z e Zdd ZG dd dZdS )c                 K   s   | |t f |dS )N)Z	operationlocationparams)dict)namer   kwargs r   //tmp/pip-unpacked-wheel-47crqvv_/dash/_patch.py
_operation   s    r   c                 C   s   t | trtdd S )Nz&a slice is not a valid index for patch)
isinstanceslice	TypeError)objr   r   r   validate_slice   s    
r   c                   @   s   e Zd ZdZd8ddZdd Zdd Zd d	d
dZd d	ddZdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd9d2d3Zd4d5 Zd6d7 ZdS ):Patchz
    Patch a callback output value

    Act like a proxy of the output prop value on the frontend.

    Supported prop types: Dictionaries and lists.
    Nc                 C   s<   |d k	r|| _ n|r|j pg | _ |d k	r2|j| _ng | _d S N	_location_operations)selfr   parentr   r   r   __init__   s    
zPatch.__init__c                 C   s   t | S r   )varsr   r   r   r   __getstate__!   s    zPatch.__getstate__c                 C   s   t | | d S r   )r   update)r   stater   r   r   __setstate__$   s    zPatch.__setstate__)returnc                 C   s   t | t| j|g | dS )N)r   r   )r   r   r   r   itemr   r   r   __getitem__'   s    zPatch.__getitem__c                 C   s2   |dkrt |dkr| jS |dkr(| jS | |S )Ntolistr   r   )AttributeErrorr   r   r   r   r   r   r   __getattr__+   s    zPatch.__getattr__c                 C   s$   |dkr|| j |< n| || d S )Nr   )__dict____setitem__r   keyvaluer   r   r   __setattr__5   s    zPatch.__setattr__c                 C   s   |  | d S r   )__delitem__r   r   r   r   __delattr__;   s    zPatch.__delattr__c                 C   s6   t | |tkrd S | jtd| j|g |d d S )NZAssignr'   )r   _noopr   appendr   r   r%   r   r   r   r$   >   s    
zPatch.__setitem__c                 C   s&   t | | jtd| j|g  d S )NZDelete)r   r   r-   r   r   )r   r&   r   r   r   r)   K   s    zPatch.__delitem__c                 C   s@   t |ttfr| | n| jtd| j|d | js<| S tS )NZAddr+   )	r	   listtupleextendr   r-   r   r   r,   r   otherr   r   r   __iadd__O   s    zPatch.__iadd__c                 C   s&   | j td| j|d | js"| S tS )NZSubr+   r   r-   r   r   r,   r1   r   r   r   __isub__X   s    zPatch.__isub__c                 C   s&   | j td| j|d | js"| S tS )NZMulr+   r4   r1   r   r   r   __imul__^   s    zPatch.__imul__c                 C   s&   | j td| j|d | js"| S tS )NZDivr+   r4   r1   r   r   r   __itruediv__d   s    zPatch.__itruediv__c                 C   s   | j |d | js| S tS )N)E)r   r   r,   r1   r   r   r   __ior__j   s    zPatch.__ior__c                 C   s   t dd S )Nz6Patch objects are write-only, you cannot iterate them.)r   r   r   r   r   __iter__p   s    zPatch.__iter__c                 C   s   d| j  dS )Nz!<write-only dash.Patch object at >)r   r   r   r   r   __repr__s   s    zPatch.__repr__c                 C   s   | j td| j|d dS )z!Add the item to the end of a listZAppendr+   Nr   r-   r   r   r   r   r   r   r-   v   s    zPatch.appendc                 C   s   | j td| j|d dS )z#Add the item to the start of a listZPrependr+   Nr=   r   r   r   r   prependz   s    zPatch.prependc                 C   s   | j td| j||d dS )z#Add the item at the index of a listZInsert)r'   indexNr=   )r   r?   r   r   r   r   insert~   s    zPatch.insertc                 C   s   | j td| j dS )zRemove all items in a listZClearNr=   r   r   r   r   clear   s    zPatch.clearc                 C   s   | j td| j dS )z(Reversal of the order of items in a listZReverseNr=   r   r   r   r   reverse   s    zPatch.reversec                 C   s8   t |ttfst| d| jtd| j|d dS )z&Add all the items to the end of a listz should be a list or tupleZExtendr+   N)r	   r.   r/   r   r   r-   r   r   r   r   r   r   r0      s    zPatch.extendc                 C   s   | j td| j|d dS )z-filter the item out of a list on the frontendZRemover+   Nr=   r   r   r   r   remove   s    zPatch.removec                 K   s.   |pi }| | | jtd| j|d dS )z9Merge a dict or keyword arguments with another dictionaryZMerger+   N)r   r   r-   r   r   )r   r8   Fr'   r   r   r   r      s    
zPatch.updatec                 C   s   t dd S )NzOsort is reserved for future use, use brackets to access this key on your object)KeyErrorr   r   r   r   sort   s    z
Patch.sortc                 C   s   d| j dS )N__dash_patch_update)rG   
operations)r   r   r   r   r   to_plotly_json   s    zPatch.to_plotly_json)NN)N)__name__
__module____qualname____doc__r   r   r   r   r"   r(   r*   r$   r)   r3   r5   r6   r7   r9   r:   r<   r-   r>   r@   rA   rB   r0   rC   r   rF   rI   r   r   r   r   r      s6   

	
r   N)r   objectr,   r   r   r   r   r   r   <module>   s   