o
    <^öh  ã                   @   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 )!Ú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   úb/home/air/websocket/korean/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 )Ú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   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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 )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   >