o _'@s&dZddlmZeGdddZdS)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_orderingcs eZdZdZdZdZfddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd@d'd(Zd)d*Zd+d,ZdAd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?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] rNcsBt|ds |j|_t|ds|j|_|j|_tj|i|dS)N_get_single_internal _set_single) hasattr_get_single_externalr_set_single_rebuildr_assign_extended_slice_rebuild_assign_extended_slicesuper__init__)selfargskwargs __class__F/usr/lib/python3/dist-packages/django/contrib/gis/geos/mutable_list.pyr >s  zListMixin.__init__cs>t|trfddt|tDS|}|S)z-Get the item(s) at the specified index/slice.csg|]}|qSr)r.0ir rr Ksz)ListMixin.__getitem__..) isinstanceslicerangeindiceslen _checkindexr)r indexrrr __getitem__Hs    zListMixin.__getitem__cst|ttfs td|t}t|tr|}|gnt|||t}fddt|D}||dS)z0Delete the item(s) at the specified index/slice.%s is not a legal indexc3s"|] }|vr|VqdSN)rr indexRanger rr ^sz(ListMixin.__delitem__..N) rintr TypeErrorrrrr_rebuild)r rorigLennewLennewItemsrr#r __delitem__Ps     zListMixin.__delitem__cCs@t|tr |||dS||}||f|||dS)z-Set the item(s) at the specified index/slice.N)rr _set_slicer_check_allowedrr rvalrrr __setitem__ds   zListMixin.__setitem__cCs|g||S)zadd another list-like objectrr otherrrr__add__nzListMixin.__add__cCs|g||S)zadd to another list-like objectrr2rrr__radd__rr5zListMixin.__radd__cCs|||S)z$add another list-like object to self)extendr2rrr__iadd__vs zListMixin.__iadd__cC|t||Smultiplyrlistr nrrr__mul__{r5zListMixin.__mul__cCr9r:r<r>rrr__rmul__r5zListMixin.__rmul__cCs>|dkr |dd=|St|}t|dD]}||q|S)r;rN)r=rr7)r r?cacherrrr__imul__s  zListMixin.__imul__c CsXt|}t|D]}z ||||k}Wn tyYdSw|s%dSqt||kSNFrr IndexErrorr r3olenrcrrr__eq__s   zListMixin.__eq__c Cspt|}t|D])}z ||||k}Wn tyYdSw|r&|S||||kr1dSqt||kS)NTFrFrHrrr__lt__s   zListMixin.__lt__cCs"d}|D] }||kr|d7}q|S)zStandard list count methodrrBr)r r0countrrrrrMs zListMixin.countcCs4tdt|D] }|||kr|Sqtd|)zStandard list index methodrz%s not found in object)rr ValueError)r r0rrrrrs   zListMixin.indexcCs|g|t|d<dS)zStandard list append methodNrr r0rrrappendszListMixin.appendcCs||t|d<dS)zStandard list extend methodNrO)r valsrrrr7szListMixin.extendcCs(t|ts td||g|||<dS)zStandard list insert methodr!N)rr&r'r/rrrinserts  zListMixin.insertcCs||}||=|S)zStandard list pop methodr)r rresultrrrpopsz ListMixin.popcCs|||=dS)zStandard list remove methodN)rrPrrrremoveszListMixin.removecCs|ddd|dd<dS)zStandard list reverse methodrTNrrrrrreversezListMixin.reverseFcCst|||d|dd<dS)zStandard list sort method)keyrXN)sorted)r rZrXrrrsortrYzListMixin.sortcCsN|r||jkrtd|j|jdur||jkrtd|j|||dS)NzMust have at least %d itemszCannot have more than %d items) _minlengthrN _maxlength _set_list)r r*r+rrrr(s zListMixin._rebuildcCs|t||dd|gdSNrB)r-r)r rvaluerrrrszListMixin._set_single_rebuildcCsJt|}d|kr|kr|S| |krdkr||Std|)Nrzinvalid index: %s)rrG)r rlengthrrrrs zListMixin._checkindexcs0tdrdfdd|DvrtddSdS)N_allowedFcsg|]}t|jqSr)rrc)rr0rrrrsz,ListMixin._check_allowed..z*Invalid type encountered in the arguments.)rr')r itemsrrrr.s zListMixin._check_allowedcCsvzt|}Wn tytdw||t|}||\}}}|jdur1||||dS|||||dS)z&Assign values to a slice of the objectz&can only assign an iterable to a sliceN)r=r'r.rrstep_assign_simple_slicer )r rvalues valueListr)startstoprerrrr-s    zListMixin._set_slicecslt|||}t|t|krtdt|t|fttt||fdd}|dS)z2Assign an extended slice by rebuilding entire listBattempt to assign sequence of size %d to extended slice of size %dc3s4tD]}|vr|Vq|VqdSr"rrrr*newValsr rrr+s   z:ListMixin._assign_extended_slice_rebuild..newItemsN)rrrNdictzipr()r rirjrerh indexListr+rrnrr s z(ListMixin._assign_extended_slice_rebuildcCsXt|||}t|t|krtdt|t|ft||D] \}}|||qdS)z9Assign an extended slice by re-assigning individual itemsrkN)rrrNrqr)r rirjrerhrrrr0rrrr s z ListMixin._assign_extended_slicecsLttt}fdd}||dS)z5Assign a simple slice; Can assign slice of any lengthc3sNtdD]}|krEdH|kr$|ks|kr$|VqdSr`rlrmr)r rirjrhrrr+-s  z0ListMixin._assign_simple_slice..newItemsN)rmaxr()r rirjrhr*r+rrsrrf's   zListMixin._assign_simple_slice)rTrE)$__name__ __module__ __qualname____doc__r]r^r r r,r1r4r6r8r@rArDrKrLrMrrQr7rSrVrWrXr\r(rrr.r-r r rf __classcell__rrrrrsB)        rN)rx functoolsrrrrrrs