U
    #FZh                     @   sP   d dl Z d dlZd dlmZ d dlmZ G dd de jjZG dd deZ	dS )    N)Iterable)cached_propertyc                   @   s   e Zd Z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edddZdddeedddZedd ZdS )RepeatedzA view around a mutable sequence in protocol buffers.

    This implements the full Python MutableSequence interface, but all methods
    modify the underlying field container directly.
    N)
proto_typec                C   s   || _ || _|| _dS )a  Initialize a wrapper around a protobuf repeated field.

        Args:
            sequence: A protocol buffers repeated field.
            marshal (~.MarshalRegistry): An instantiated marshal, used to
                convert values going to and from this map.
        N)_pb_marshal_proto_type)selfsequencemarshalr    r   i/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/proto/marshal/collections/repeated.py__init__   s    zRepeated.__init__c                 C   s   t | | jdd | jdS )z%Copy this object and return the copy.N)r   )typepbr   r	   r   r   r   __copy__)   s    zRepeated.__copy__c                 C   s   | j |= dS )zDelete the given item.Nr   r	   keyr   r   r   __delitem__-   s    zRepeated.__delitem__c                 C   s>   t |drt| jt|jkS t|tr:t| jt|kS dS )Nr   F)hasattrtupler   
isinstancer   r	   otherr   r   r   __eq__1   s    
zRepeated.__eq__c                 C   s
   | j | S )zReturn the given item.r   r   r   r   r   __getitem__6   s    zRepeated.__getitem__c                 C   s
   t | jS )z"Return the length of the sequence.)lenr   r   r   r   r   __len__:   s    zRepeated.__len__c                 C   s
   | |k S Nr   r   r   r   r   __ne__>   s    zRepeated.__ne__c                 C   s
   t | S r    )reprr   r   r   r   __repr__A   s    zRepeated.__repr__c                 C   s   || j |< d S r    r   )r	   r   valuer   r   r   __setitem__D   s    zRepeated.__setitem__indexc                 C   s   | j || dS z2Insert ``value`` in the sequence before ``index``.N)r   insert)r	   r'   r$   r   r   r   r)   G   s    zRepeated.insertFr   reversec                C   s   | j j||d dS )zStable sort *IN PLACE*.r*   N)r   sort)r	   r   r+   r   r   r   r,   K   s    zRepeated.sortc                 C   s   | j S r    )r   r   r   r   r   r   O   s    zRepeated.pb)__name__
__module____qualname____doc__r   r   r   r   r   r   r!   r#   r%   intr)   strboolr,   propertyr   r   r   r   r   r      s   r   c                       sJ   e Zd ZdZedd Z fddZdd Zdd	 Ze	d
ddZ
  ZS )RepeatedCompositezA view around a mutable sequence of messages in protocol buffers.

    This implements the full Python MutableSequence interface, but all methods
    modify the underlying field container directly.
    c                 C   sh   | j dk	r| j S t| jdkr,t| jd S t| jdrPt| jjdrP| jjjS t| j	 }t|S )z2Return the protocol buffer type for this sequence.Nr   _message_descriptor_concrete_class)
r   r   r   r   r   r6   r7   copydeepcopyadd)r	   Zcanaryr   r   r   _pb_type[   s    
 
zRepeatedComposite._pb_typec                    s8   t  |rdS t|tr4tdd | D t|kS dS )NTc                 S   s   g | ]}|qS r   r   ).0ir   r   r   
<listcomp>|   s     z,RepeatedComposite.__eq__.<locals>.<listcomp>F)superr   r   r   r   r   	__class__r   r   r   x   s    zRepeatedComposite.__eq__c                 C   s   | j | j| j| S r    )r   Z	to_pythonr;   r   r   r   r   r   r      s    zRepeatedComposite.__getitem__c           
      C   sj  t |trPt|  |  kr(t| k rDn n| | | || ntdnt |trR|t| \}}}t |tj	j
std|dkrt|D ]2\}}|| |k r| ||  | || | qt|| t| D ]}| |t|  qnXt|||}	t|t|	kr2tdt| dt|	 t|	|D ]\}}|| |< q<ntdt|j d S )Nz"list assignment index out of rangezcan only assign an iterable   z#attempt to assign sequence of size z to extended slice of size z-list indices must be integers or slices, not )r   r1   r   popr)   
IndexErrorsliceindicescollectionsabcr   	TypeError	enumeraterange
ValueErrorzipr   r-   )
r	   r   r$   startstopstepr'   item_rF   r   r   r   r%      s4    
"
zRepeatedComposite.__setitem__r&   c                 C   s"   | j | j|}| j|| dS r(   )r   Zto_protor;   r   r)   )r	   r'   r$   Zpb_valuer   r   r   r)      s    zRepeatedComposite.insert)r-   r.   r/   r0   r   r;   r   r   r%   r1   r)   __classcell__r   r   r@   r   r5   T   s   
	6r5   )
rG   r8   typingr   Zproto.utilsr   rH   MutableSequencer   r5   r   r   r   r   <module>   s
   >