a
    !fv                     @   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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   c/var/www/html/python-backend/venv/lib/python3.9/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   s    zRepeated.__getitem__c                 C   s
   t | jS )z"Return the length of the sequence.)lenr   r   r   r   r   __len__9   s    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   reversec                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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u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   r4   r5   copydeepcopyadd)r   Z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       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   Z	to_pythonr9   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 )
isinstancer/   r   popr'   
IndexErrorsliceindicescollectionsabcIterable	TypeError	enumeraterange
ValueErrorzipr   r+   )
r   r   r"   startstopstepr%   item_rF   r   r   r   r#      s<    
"
zRepeatedComposite.__setitem__r$   c                 C   s"   | j | j|}| j|| dS r&   )r   Zto_protor9   r   r'   )r   r%   r"   Zpb_valuer   r   r   r'      s    zRepeatedComposite.insert)r+   r,   r-   r.   r   r9   r   r   r#   r/   r'   __classcell__r   r   r?   r   r3   S   s   
6r3   )rG   r6   Zproto.utilsr   rH   MutableSequencer   r3   r   r   r   r   <module>   s   >