o
    Mfv                     @   sD   d dl Z d dlZd dlmZ G dd de jjZG dd deZdS )    N)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   d/var/www/html/analyze/labelStudio/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   s0   t |drt| jt|jkS t| jt|kS )Nr   )hasattrtupler   r   otherr   r   r   __eq__0   s   
zRepeated.__eq__c                 C   s
   | j | S )zReturn the given item.r   r   r   r   r   __getitem__5      
zRepeated.__getitem__c                 C   s
   t | jS )z"Return the length of the sequence.)lenr   r   r   r   r   __len__9   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__@   s   zRepeated.__repr__c                 C   s   || j |< d S r   r   )r   r   valuer   r   r   __setitem__C   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'   F   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*   J   s   zRepeated.sortc                 C   s   | j S r   )r   r   r   r   r   r   N   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   r4   r5   copydeepcopyadd)r   canaryr   r   r   _pb_typeZ   s   

zRepeatedComposite._pb_typec                    s*   t  |rdS tdd | D t|kS )NTc                 S   s   g | ]}|qS r   r   ).0ir   r   r   
<listcomp>z   s    z,RepeatedComposite.__eq__.<locals>.<listcomp>)superr   r   r   	__class__r   r   r   w   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 )
isinstancer/   r   popr'   
IndexErrorsliceindicescollectionsabcIterable	TypeError	enumeraterange
ValueErrorzipr   r+   )
r   r   r#   startstopstepr%   item_rG   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-   r.   r   r:   r   r   r$   r/   r'   __classcell__r   r   r?   r   r3   S   s    
6r3   )rH   r6   proto.utilsr   rI   MutableSequencer   r3   r   r   r   r   <module>   s
   >