ff]IddlmZmZddlmZddlmZddlmZGddZ Gdde Z Gd d e Z Gd d e Z eje eje d ZeidZidfdZdZdS))MappingHashable)chain)pvector transformc*eZdZdZdZdZdZdZdS)PMapViewaView type for the persistent map/dict type `PMap`. Provides an equivalent of Python's built-in `dict_values` and `dict_items` types that result from expreessions such as `{}.values()` and `{}.items()`. The equivalent for `{}.keys()` is absent because the keys are instead represented by a `PSet` object, which can be created in `O(1)` time. The `PMapView` class is overloaded by the `PMapValues` and `PMapItems` classes which handle the specific case of values and items, respectively Parameters ---------- m : mapping The mapping/dict-like object of which a view is to be created. This should generally be a `PMap` object. ct|ts4t|trt|}nt dt |d|dS)Nz"PViewMap requires a Mapping object_map) isinstancePMaprpmap TypeErrorobject __setattr__)selfms p/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pyrsistent/_pmap.py__init__zPMapView.__init__sb!T"" F!W%% FGG DEEE4+++++c*t|jSN)lenr rs r__len__zPMapView.__len__"s49~~rc@tt|d)Nz is immutable)rtype)rkvs rrzPMapView.__setattr__%sT$ZZZZ9:::rc tdNz"Persistent maps are not reversiblerrs r __reversed__zPMapView.__reversed__(<===rN)__name__ __module__ __qualname____doc__rrrr$rrr r sZ",,,;;;>>>>>rr c0eZdZdZdZdZdZdZdZdS) PMapValuesaView type for the values of the persistent map/dict type `PMap`. Provides an equivalent of Python's built-in `dict_values` type that result from expreessions such as `{}.values()`. See also `PMapView`. Parameters ---------- m : mapping The mapping/dict-like object of which a view is to be created. This should generally be a `PMap` object. c4|jSrr itervaluesrs r__iter__zPMapValues.__iter__7sy##%%%rc8||jvSrr.)rargs r __contains__zPMapValues.__contains__:sdi**,,,,rcBdtt|dSNz pmap_values()listiterrs r__str__zPMapValues.__str__>!1d4::..1111rcBdtt|dSr5r7rs r__repr__zPMapValues.__repr__Ar;rc||urdSdSNTFr*rxs r__eq__zPMapValues.__eq__Ds 99TTUrN r&r'r(r)r0r3r:r=rBr*rrr,r,+si  &&&---222222rr,c0eZdZdZdZdZdZdZdZdS) PMapItemsa|View type for the items of the persistent map/dict type `PMap`. Provides an equivalent of Python's built-in `dict_items` type that result from expreessions such as `{}.items()`. See also `PMapView`. Parameters ---------- m : mapping The mapping/dict-like object of which a view is to be created. This should generally be a `PMap` object. c4|jSr)r iteritemsrs rr0zPMapItems.__iter__Vsy""$$$rcd|\}}n#t$rYdSwxYw||jvo|j||kS)NF) Exceptionr )rr2rr s rr3zPMapItems.__contains__YsBUa&&&&DI~3$)A,!"33s  cBdtt|dSNz pmap_items(r6r7rs rr:zPMapItems.__str___!0T$t**--0000rcBdtt|dSrKr7rs rr=zPMapItems.__repr__brLrcl||urdSt|t|sdS|j|jkSr?)r rr r@s rrBzPMapItems.__eq__es: 99TTAtDzz** )55Y!&((rNrCr*rrrErEJsi  %%%444 111111)))))rrEcReZdZdZdZfdZedZedZdZ edZ dZ e j Z d Zd Zd Zd Zd ZdZdZdZdZdZdZdZe jZdZeZeZeZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&e&Z'dZ(dZ)d Z*Gd!d"e+Z,d#Z-xZ.S)$ra Persistent map/dict. Tries to follow the same naming conventions as the built in dict where feasible. Do not instantiate directly, instead use the factory functions :py:func:`m` or :py:func:`pmap` to create an instance. Was originally written as a very close copy of the Clojure equivalent but was later rewritten to closer re-assemble the python dict. This means that a sparse vector (a PVector) of buckets is used. The keys are hashed and the elements inserted at position hash % len(bucket_vector). Whenever the map size exceeds 2/3 of the containing vectors size the map is reallocated to a vector of double the size. This is done to avoid excessive hash collisions. This structure corresponds most closely to the built in dict type and is intended as a replacement. Where the semantics are the same (more or less) the same function names have been used but for some cases it is not possible, for example assignments and deletion of values. PMap implements the Mapping protocol and is Hashable. It also supports dot-notation for element access. Random access and insert is log32(n) where n is the size of the map. The following are examples of some common operations on persistent maps >>> m1 = m(a=1, b=3) >>> m2 = m1.set('c', 3) >>> m3 = m2.remove('a') >>> m1 == {'a': 1, 'b': 3} True >>> m2 == {'a': 1, 'b': 3, 'c': 3} True >>> m3 == {'b': 3, 'c': 3} True >>> m3['c'] 3 >>> m3.c 3 )_size_buckets __weakref__ _cached_hashcttt||}||_||_|Sr)superr__new__rPrQ)clssizebucketsr __class__s rrVz PMap.__new__s3T3'',,   rcXt|t|z}||}||fSr)hashr)rYkeyindexbuckets r _get_bucketzPMap._get_buckets+S CLL(f}rct||\}}|r|D]\}}||kr|cSt|r)rr`KeyError)rYr]_r_rr s r_getitemz PMap._getitems[$$Wc22 6    188HHHsmmrcBt|j|Sr)rrdrQrr]s r __getitem__zPMap.__getitem__s}}T]C000rclt||\}}|r|D]\}}||krdSdSdSr?)rr`)rYr]rcr_rs r _containszPMap._containssW$$Wc22 6    188445urc8||j|Sr)rirQrfs rr3zPMap.__contains__s~~dmS111rc*|Sr)iterkeysrs rr0z PMap.__iter__}}rc tdr"r#rs rr$zPMap.__reversed__r%rc ||S#t$r;}tdt|j||d}~wwxYw)Nz{0} has no attribute '{1}')rbAttributeErrorformatrr&)rr]es r __getattr__zPMap.__getattr__sa 9     ,33DJJ4GMM  s A6A  Ac#FK|D] \}}|V dSrrG)rrrcs rrlz PMap.iterkeys8NN$$  DAqGGGG  rc#FK|D] \}}|V dSrru)rrcr s rr/zPMap.itervaluesrvrc#>K|jD]}|r|D] \}}||fV dSr)rQ)rr_rr s rrGzPMap.iteritemssLm  F "DAqQ$JJJJ  rc t|Sr)r,rs rvaluesz PMap.valuess$rc$ddlm}||S)N)PSet)_psetr})rr}s rkeysz PMap.keyss"tDzzrc t|Sr)rErs ritemsz PMap.itemssrc|jSrrPrs rrz PMap.__len__s zrc`dtt|S)Nz pmap({0}))rqstrdictrs rr=z PMap.__repr__s"!!#d4jj//222rc||urdSt|tstSt|t|krdSt|trt |dr"t |dr|j|jkrdS|j|jkrdSt| t| kSt|tr%t| |kSt| t| kS)NTFrS) r rNotImplementedrrhasattrrSrQrrGrrothers rrBz PMap.__eq__s. 5==4%)) "! ! t99E " "5 eT " " 3n-- '%2P2P )U-???u}..t(())T%//2C2C-D-DD D t $ $ 3(())U2 2DNN$$%%ekkmm)<)<<>> m1 = m(a=1, b=2) >>> m2 = m1.set('a', 3) >>> m3 = m1.set('c' ,4) >>> m1 == {'a': 1, 'b': 2} True >>> m2 == {'a': 3, 'b': 2} True >>> m3 == {'a': 1, 'b': 2, 'c': 4} True )evolverset persistentrr]vals rrzPMap.sets.||~~!!#s++66888rct||S)z Return a new PMap without the element specified by key. Raises KeyError if the element is not present. >>> m1 = m(a=1, b=2) >>> m1.remove('a') pmap({'b': 2}) )rremoverrfs rrz PMap.remove!s,||~~$$S))44666rcR ||S#t$r|cYSwxYw)a Return a new PMap without the element specified by key. Returns reference to itself if element is not present. >>> m1 = m(a=1, b=2) >>> m1.discard('a') pmap({'b': 2}) >>> m1 is m1.discard('c') True )rrbrfs rdiscardz PMap.discard,s= ;;s## #   KKK s  &&c |jdg|RS)a, Return a new PMap with the items in Mappings inserted. If the same key is present in multiple maps the rightmost (last) value is inserted. >>> m1 = m(a=1, b=2) >>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35}) == {'a': 17, 'b': 2, 'c': 3, 'd': 35} True c|Srr*)lrs rzPMap.update..EsQr) update_with)rmapss rupdatez PMap.update<s! t66666rc |}|D]H}|D]1\}}||||vr||||n|2I|S)a% Return a new PMap with the items in Mappings maps inserted. If the same key is present in multiple maps the values will be merged using merge_fn going from left to right. >>> from operator import add >>> m1 = m(a=1, b=2) >>> m1.update_with(add, m(a=2)) == {'a': 3, 'b': 2} True The reverse behaviour of the regular merge. Keep the leftmost element instead of the rightmost. >>> m1 = m(a=1) >>> m1.update_with(lambda l, r: l, m(a=2), {'a':3}) pmap({'a': 1}) )rrrr)r update_fnrrmapr]values rrzPMap.update_withGs ,,.. ^ ^C!iikk ^ ^ U C3'>>73<!?!?!?W\]]]] ^!!###rc,||Sr)rrs r__add__z PMap.__add__^s{{5!!!rc0tt|ffSr)rrrs r __reduce__zPMap.__reduce__csd4jj]""rc"t||S)a Transform arbitrarily complex combinations of PVectors and PMaps. A transformation consists of two parts. One match expression that specifies which elements to transform and one transformation function that performs the actual transformation. >>> from pyrsistent import freeze, ny >>> news_paper = freeze({'articles': [{'author': 'Sara', 'content': 'A short article'}, ... {'author': 'Steve', 'content': 'A slightly longer article'}], ... 'weather': {'temperature': '11C', 'wind': '5m/s'}}) >>> short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:25] + '...' if len(c) > 25 else c) >>> very_short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:15] + '...' if len(c) > 15 else c) >>> very_short_news.articles[0].content 'A short article' >>> very_short_news.articles[1].content 'A slightly long...' When nothing has been transformed the original data structure is kept >>> short_news is news_paper True >>> very_short_news is news_paper False >>> very_short_news.articles[0] is news_paper.articles[0] True r)rtransformationss rrzPMap.transformgs4///rc|Srr*rs rcopyz PMap.copys rcTeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd S) PMap._Evolver)_buckets_evolverrP_original_pmapch||_|j|_|j|_dSr)rrQrrrP)r original_pmaps rrzPMap._Evolver.__init__s/"/D $1$:$B$B$D$DD !&,DJJJrcBt|j|Sr)rrdrrfs rrgzPMap._Evolver.__getitem__s==!6<< z%PMap._Evolver.set..s4)b)b)bQWQSUWbAgg2r((B9)b)b)brr|)rr`rrrP _reallocaterextend) rr]rkvr^r_reallocation_requiredr new_bucketrs ` @rrzPMap._Evolver.setsesB ,,T-BCHHME6$'(=$>$> AR$R ! "$$DAqCxxC<<)b)b)b)b)b[a)b)b)bJ;ED1%8#  ).$$&&&88C--- T !!&)))/9%e, a (.$$&&&88C---02t%e, a Krcdt|jz}|dgz}|j}tjd|DD]E\}}t ||z}||r||||f=||fg||<Ft|_|j |dS)Nc3K|]}||V dSrr*)rrAs r z,PMap._Evolver._reallocate..s'+D+D!!+DA+D+D+D+D+D+Dr) rrrr from_iterabler\appendrrr)rnew_sizenew_listrYrr r^s rrzPMap._Evolver._reallocates3t4555H4&(H+6688G++D+Dw+D+D+DDD / /1Q(*E?/UO**Aq62222()1vhHUOO%,II$5$5$7$7D !  ! ( ( 2 2 2 2 2rc4|jSr)ris_dirtyrs rrzPMap._Evolver.is_dirtys(1133 3rc|r1t|j|j|_|jSr)rrrPrrrrs rrzPMap._Evolver.persistents?}} [&*4:t7L7W7W7Y7Y&Z&Z#& &rc|jSrrrs rrzPMap._Evolver.__len__s : rcBt|j|Sr)rrirrfs rr3zPMap._Evolver.__contains__s>>$"7== =rc0||dSr)rrfs r __delitem__zPMap._Evolver.__delitem__s KK     rc.t|j\}}|rNfd|D}t|t|kr |r|nd|j|<|xjdzc_|St d)Nc*g|]\}}|k ||fSr*r*)rrr r]s rrz(PMap._Evolver.remove..s&FFF!QQ#XXq!fXXXrr|z{0})rr`rrrPrbrq)rr]r^r_rs ` rrzPMap._Evolver.removes ,,T-BCHHME6 FFFF6FFF v;;Z00AK3U::QUD)%0JJ!OJJK5<<,,-- -rN)r&r'r( __slots__rrgrrrrrrr3rrr*rr_EvolverrsC  - - -  = = =      B 3 3 3  4 4 4 ' ' '     > > >    . . . . .rrc,||S)a- Create a new evolver for this pmap. For a discussion on evolvers in general see the documentation for the pvector evolver. Create the evolver and perform various mutating updates to it: >>> m1 = m(a=1, b=2) >>> e = m1.evolver() >>> e['c'] = 3 >>> len(e) 3 >>> del e['a'] The underlying pmap remains the same: >>> m1 == {'a': 1, 'b': 2} True The changes are kept in the evolver. An updated pmap can be created using the persistent() function on the evolver. >>> m2 = e.persistent() >>> m2 == {'b': 2, 'c': 3} True The new pmap will share data with the original pmap in the same way that would have been done if only using operations on the pmap. )rrs rrz PMap.evolvers:}}T"""r)/r&r'r(r)rrV staticmethodr`rdrgrir3rgetr0r$rsrlr/rGrzrrrr=rB__ne__r__le____gt____ge__r:rrrrrrr__or__rrrrrr __classcell__)rZs@rrrjs$$JEI \ \111  \ 222 +C >>>    333===$^F333F F F!!! 999 7 7 7 7 7 7$$$."""F###0008[.[.[.[.[.6[.[.[.z#######rrc|r|}n( dt|zpd}n#t$rd}YnwxYw|dgz}t|tst |}|D]C\}}t |}||z}||}|r|||f;||fg||<Dtt|t |S)Nr) rrIr rrrr\rrrr) initialpre_sizerXrYrr hr^r_s r_turbo_mappingrs s7||#(qDD   DDD  dVmG gw ' ' w-- &&1 GGD  & MM1a& ! ! ! ! !fXGENN G gii..w77 8 88s  ++c@|s |dkrtSt||S)a Create new persistent map, inserts all elements in initial into the newly created map. The optional argument pre_size may be used to specify an initial size of the underlying bucket vector. This may have a positive performance impact in the cases where you know beforehand that a large number of elements will be inserted into the map eventually since it will reduce the number of reallocations required. >>> pmap({'a': 13, 'b': 14}) == {'a': 13, 'b': 14} True r) _EMPTY_PMAPr)rrs rrr)s* x1}} '8 , ,,rc t|S)z Creates a new persistent map. Inserts all key value arguments into the newly created map. >>> m(a=13, b=14) == {'a': 13, 'b': 14} True )r)kwargss rrr9s <<rN)collections.abcrr itertoolsrpyrsistent._pvectorrpyrsistent._transformationsrr r,rErrregisterrrrrr*rrrs--------''''''111111#>#>#>#>#>#>#>#>J>))))))))@V#V#V#V#V#6V#V#V#p $999@nR## a - - - - r