o
    }j6h                     @   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defddZddddedef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   q/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/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      
zRepeated.__getitem__c                 C   s
   t | jS )z"Return the length of the sequence.)lenr   r   r   r   r   __len__:   r   zRepeated.__len__c                 C   s
   | |k S Nr   r   r   r   r   __ne__>   s   
zRepeated.__ne__c                 C   s   t g | 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   reverser   r+   c                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d
e	f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ur| j S t| jdkrt| jd S t| jdr(t| jjdr(| 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	   canaryr   r   r   _pb_type[   s   

zRepeatedComposite._pb_typec                    s8   t  |rdS t|trt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   	to_pythonr<   r   r   r   r   r   r      s   zRepeatedComposite.__getitem__c           
      C   sh  t |tr*t|  |  krt| k r&n td| | | || d S tdt |tr|t| \}}}t |tj	j
sDtd|dkr~t|D ]\}}|| |k r]| ||  | || | qLt|| t| D ]}| |t|  qpd S t|||}	t|t|	krtdt| dt|	 t|	|D ]\}}|| |< qd S tdt|j )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_rH   r   r   r   r&      sB   
 


zRepeatedComposite.__setitem__r'   c                 C   s"   | j | j|}| j|| dS r(   )r   to_protor<   r   r)   )r	   r'   r%   pb_valuer   r   r   r)      s   zRepeatedComposite.insert)r-   r.   r/   r0   r   r<   r   r   r&   r1   r)   __classcell__r   r   rA   r   r5   T   s    
	6r5   )
rI   r8   typingr   proto.utilsr   rJ   MutableSequencer   r5   r   r   r   r   <module>   s   >