o
    ÓèFhv  ã                   @   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 )!ÚRepeatedz¾A 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   ú[/var/www/html/loop/nvenv/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 )ÚRepeatedCompositezÊA 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rštdt|ƒ› dt|	ƒ› �ƒ‚t|	|ƒD ]\}}|| |< qŸd 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
   >