a
    [f'                     @   s&   d Z ddlmZ eG dd dZdS )z
This module contains a base type which provides list-style mutations
without specific data storage methods.

See also http://static.aryehleib.com/oldsite/MutableLists.html

Author: Aryeh Leib Taurog.
    )total_orderingc                       s  e Zd ZdZdZdZ f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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'd(Zd)d* Zd+d, ZdAd.d/Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"  Z#S )B	ListMixinay  
    A base class which provides complete list interface.
    Derived classes must call ListMixin's __init__() function
    and implement the following:

    function _get_single_external(self, i):
        Return single item with index i for general use.
        The index i will always satisfy 0 <= i < len(self).

    function _get_single_internal(self, i):
        Same as above, but for use within the class [Optional]
        Note that if _get_single_internal and _get_single_internal return
        different types of objects, _set_list must distinguish
        between the two and handle each appropriately.

    function _set_list(self, length, items):
        Recreate the entire object.

        NOTE: items may be a generator which calls _get_single_internal.
        Therefore, it is necessary to cache the values in a temporary:
            temp = list(items)
        before clobbering the original storage.

    function _set_single(self, i, value):
        Set the single item at index i to value [Optional]
        If left undefined, all mutations will result in rebuilding
        the object using _set_list.

    function __len__(self):
        Return the length

    int _minlength:
        The minimum legal length [Optional]

    int _maxlength:
        The maximum legal length [Optional]

    type or tuple _allowed:
        A type or tuple of allowed item types [Optional]
    r   Nc                    sB   t | ds| j| _t | ds,| j| _| j| _t j|i | d S )N_get_single_internal_set_single)	hasattr_get_single_externalr   _set_single_rebuildr   _assign_extended_slice_rebuild_assign_extended_slicesuper__init__)selfargskwargs	__class__ vC:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\site-packages\django/contrib/gis/geos/mutable_list.pyr   >   s    

zListMixin.__init__c                    sB   t |tr* fddt|t  D S  |} |S dS )z-Get the item(s) at the specified index/slice.c                    s   g | ]}  |qS r   )r   .0ir   r   r   
<listcomp>K   s   z)ListMixin.__getitem__.<locals>.<listcomp>N)
isinstanceslicerangeindiceslen_checkindexr   )r   indexr   r   r   __getitem__H   s    


zListMixin.__getitem__c                    s   t |ttfstd| t}t |tr>|}|g nt||  |t  } fddt|D }|| dS )z0Delete the item(s) at the specified index/slice.%s is not a legal indexc                 3   s    | ]}| vr |V  qd S N)r   r   Z
indexRanger   r   r   	<genexpr>`   s   z(ListMixin.__delitem__.<locals>.<genexpr>N)	r   intr   	TypeErrorr   r   r   r   _rebuild)r   r   origLennewLennewItemsr   r#   r   __delitem__R   s    

zListMixin.__delitem__c                 C   s>   t |tr| || n"| |}| |f | || dS )z-Set the item(s) at the specified index/slice.N)r   r   
_set_slicer   _check_allowedr   r   r   valr   r   r   __setitem__f   s
    

zListMixin.__setitem__c                 C   s   |  g | |S )zadd another list-like objectr   r   otherr   r   r   __add__p   s    zListMixin.__add__c                 C   s   | g || S )zadd to another list-like objectr   r1   r   r   r   __radd__t   s    zListMixin.__radd__c                 C   s   |  | | S )z$add another list-like object to self)extendr1   r   r   r   __iadd__x   s    
zListMixin.__iadd__c                 C   s   |  t| | S multiplyr   listr   nr   r   r   __mul__}   s    zListMixin.__mul__c                 C   s   |  t| | S r7   r9   r;   r   r   r   __rmul__   s    zListMixin.__rmul__c                 C   s<   |dkr| dd= n$t | }t|d D ]}| | q(| S )r8   r   N   )r:   r   r5   )r   r<   cacher   r   r   r   __imul__   s    zListMixin.__imul__c              	   C   sX   t |}t|D ]:}z| | || k}W n ty>   Y  dS 0 |s dS qt | |kS )NFr   r   
IndexErrorr   r2   Zolenr   cr   r   r   __eq__   s    
zListMixin.__eq__c              	   C   sp   t |}t|D ]R}z| | || k }W n ty>   Y  dS 0 |rL|  S || | | k r dS qt | |k S )NTFrB   rD   r   r   r   __lt__   s    
zListMixin.__lt__c                 C   s"   d}| D ]}||kr|d7 }q|S )zStandard list count methodr   r?   r   )r   r/   countr   r   r   r   rH      s
    
zListMixin.countc                 C   s8   t dt| D ]}| | |kr|  S qtd| dS )zStandard list index methodr   z%s not found in objectN)r   r   
ValueError)r   r/   r   r   r   r   r      s    
zListMixin.indexc                 C   s   |g| t | d< dS )zStandard list append methodNr   r   r/   r   r   r   append   s    zListMixin.appendc                 C   s   || t | d< dS )zStandard list extend methodNrJ   )r   valsr   r   r   r5      s    zListMixin.extendc                 C   s(   t |tstd| |g| ||< dS )zStandard list insert methodr!   N)r   r%   r&   r.   r   r   r   insert   s    
zListMixin.insertc                 C   s   | | }| |= |S )zStandard list pop methodr   )r   r   resultr   r   r   pop   s    zListMixin.popc                 C   s   | |  |= dS )zStandard list remove methodN)r   rK   r   r   r   remove   s    zListMixin.removec                 C   s   | ddd | dd< dS )zStandard list reverse methodrO   Nr   r   r   r   r   reverse   s    zListMixin.reverseFc                 C   s   t | ||d| dd< dS )zStandard list sort method)keyrS   N)sorted)r   rT   rS   r   r   r   sort   s    zListMixin.sortc                 C   sN   |r|| j k rtd| j  | jd ur>|| jkr>td| j | || d S )NzMust have at least %d itemszCannot have more than %d items)
_minlengthrI   
_maxlengthZ	_set_list)r   r)   r*   r   r   r   r'      s
    zListMixin._rebuildc                 C   s   |  t||d d|g d S Nr?   )r,   r   )r   r   valuer   r   r   r      s    zListMixin._set_single_rebuildc                 C   sV   t | }d|  kr|k r$n n|S | |  kr:dk rFn n|| S td| d S )Nr   zinvalid index: %s)r   rC   )r   r   lengthr   r   r   r      s    zListMixin._checkindexc                    s,   t  dr(d fdd|D v r(tdd S )N_allowedFc                    s   g | ]}t | jqS r   )r   r\   )r   r/   r   r   r   r          z,ListMixin._check_allowed.<locals>.<listcomp>z*Invalid type encountered in the arguments.)r   r&   )r   itemsr   r   r   r-      s    
zListMixin._check_allowedc                 C   sx   zt |}W n ty&   tdY n0 | | t| }||\}}}|jdu rd| ||| n| |||| dS )z&Assign values to a slice of the objectz&can only assign an iterable to a sliceN)r:   r&   r-   r   r   step_assign_simple_slicer
   )r   r   values	valueListr(   startstopr_   r   r   r   r,      s    

zListMixin._set_slicec                    sl   t |||}t|t|kr4tdt|t|f t tt|| fdd} |  dS )z2Assign an extended slice by rebuilding entire listBattempt to assign sequence of size %d to extended slice of size %dc                  3   s2   t  D ]$} | v r |  V  q| V  qd S r"   r   r   r   r)   ZnewValsr   r   r   r*     s    z:ListMixin._assign_extended_slice_rebuild.<locals>.newItemsN)r   r   rI   dictzipr'   )r   rc   rd   r_   rb   	indexListr*   r   rh   r   r	     s    z(ListMixin._assign_extended_slice_rebuildc                 C   sX   t |||}t|t|kr4tdt|t|f t||D ]\}}| || q>dS )z9Assign an extended slice by re-assigning individual itemsre   N)r   r   rI   rj   r   )r   rc   rd   r_   rb   rk   r   r/   r   r   r   r
     s    z ListMixin._assign_extended_slicec                    sL   t  t   t  } fdd}||  dS )z5Assign a simple slice; Can assign slice of any lengthc                  3   sL   t  d D ]:} | kr"E d H  |  k r| k s:| kr| V  qd S rY   rf   rg   r(   r   rc   rd   rb   r   r   r*   1  s    
z0ListMixin._assign_simple_slice.<locals>.newItemsN)r   maxr'   )r   rc   rd   rb   r)   r*   r   rl   r   r`   +  s
    
	zListMixin._assign_simple_slice)rO   )NF)$__name__
__module____qualname____doc__rW   rX   r   r    r+   r0   r3   r4   r6   r=   r>   rA   rF   rG   rH   r   rL   r5   rN   rQ   rR   rS   rV   r'   r   r   r-   r,   r	   r
   r`   __classcell__r   r   r   r   r      s@   )





r   N)rq   	functoolsr   r   r   r   r   r   <module>   s   