3 šigบใ@sbddlZddlmZGdd„deƒZGdd„dejƒZGdd „d eƒZGd d „d eƒZd d „Z dS)้N้)ฺcollections_abcc@speZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„ZdS)ฺ DirectedGraphz&A graph structure with directed edges.cCstƒ|_i|_i|_dS)N)ฺsetฺ _verticesฺ _forwardsฺ _backwards)ฺselfฉr ๚=/tmp/pip-build-88gy_88q/pip/pip/_vendor/resolvelib/structs.pyฺ__init__ szDirectedGraph.__init__cCs t|jƒS)N)ฺiterr)r r r r ฺ__iter__szDirectedGraph.__iter__cCs t|jƒS)N)ฺlenr)r r r r ฺ__len__szDirectedGraph.__len__cCs ||jkS)N)r)r ฺkeyr r r ฺ __contains__szDirectedGraph.__contains__cCsBtƒ}t|jƒ|_dd„|jjƒDƒ|_dd„|jjƒDƒ|_|S)z$Return a shallow copy of this graph.cSsi|]\}}t|ƒ|“qSr )r)ฺ.0ฺkฺvr r r ๚ sz&DirectedGraph.copy..cSsi|]\}}t|ƒ|“qSr )r)rrrr r r rs)rrrrฺitemsr)r ฺotherr r r ฺcopys  zDirectedGraph.copycCs:||jkrtdƒ‚|jj|ƒtƒ|j|<tƒ|j|<dS)zAdd a new vertex to the graph.z vertex existsN)rฺ ValueErrorฺaddrrr)r rr r r rs    zDirectedGraph.addcCs\|jj|ƒx$|jj|ƒD]}|j|j|ƒqWx$|jj|ƒD]}|j|j|ƒq@WdS)zCRemove a vertex from the graph, disconnecting all edges from/to it.N)rฺremoverฺpopr)r rฺfฺtr r r r's  zDirectedGraph.removecCs||j|ko||j|kS)N)rr)r rrr r r ฺ connected/szDirectedGraph.connectedcCs6||jkrt|ƒ‚|j|j|ƒ|j|j|ƒdS)zgConnect two existing vertices. Nothing happens if the vertices are already connected. N)rฺKeyErrorrrr)r rrr r r ฺconnect2s zDirectedGraph.connectccs4x.|jjƒD] \}}x|D]}||fVqWq WdS)N)rr)r rฺchildrenrr r r ฺ iter_edges<s zDirectedGraph.iter_edgescCst|j|ƒS)N)r r)r rr r r ฺ iter_childrenAszDirectedGraph.iter_childrencCst|j|ƒS)N)r r)r rr r r ฺ iter_parentsDszDirectedGraph.iter_parentsN)ฺ__name__ฺ __module__ฺ __qualname__ฺ__doc__r rrrrrrr r"r$r%r&r r r r rs rc@sJeZdZddd„Zdd„Zdd„ZeZdd „Zd d „Zd d „Z dd„Z dS)ฺIteratorMappingNcCs||_||_|pi|_dS)N)ฺ_mappingฺ _accessorฺ_appends)r ฺmappingZaccessorZappendsr r r r IszIteratorMapping.__init__cCsdj|j|j|jƒS)Nz!IteratorMapping({!r}, {!r}, {!r}))ฺformatr,r-r.)r r r r ฺ__repr__NszIteratorMapping.__repr__cCst|jp |jƒS)N)ฺboolr,r.)r r r r ฺ__bool__UszIteratorMapping.__bool__cCs||jkp||jkS)N)r,r.)r rr r r rZszIteratorMapping.__contains__c CsJy|j|}Wntk r,t|j|ƒSXtj|j|ƒ|jj|fƒƒS)N)r,r!r r.ฺ itertoolsฺchainr-ฺget)r rrr r r ฺ __getitem__]s zIteratorMapping.__getitem__cs"‡fdd„ˆjDƒ}tjˆj|ƒS)Nc3s|]}|ˆjkr|VqdS)N)r,)rr)r r r ๚ esz+IteratorMapping.__iter__..)r.r4r5r,)r ฺmorer )r r rdszIteratorMapping.__iter__cs&t‡fdd„ˆjDƒƒ}tˆjƒ|S)Nc3s|]}|ˆjkrdVqdS)rN)r,)rr)r r r r8isz*IteratorMapping.__len__..)ฺsumr.rr,)r r9r )r r rhszIteratorMapping.__len__)N) r'r(r)r r1r3ฺ __nonzero__rr7rrr r r r r+Hs r+c@s4eZdZdZdd„Zdd„Zdd„ZeZdd „Zd S) ฺ_FactoryIterableViewa:Wrap an iterator factory returned by `find_matches()`. Calling `iter()` on this class would invoke the underlying iterator factory, making it a "collection with ordering" that can be iterated through multiple times, but lacks random access methods presented in built-in Python sequence types. cCs ||_dS)N)ฺ_factory)r ฺfactoryr r r r vsz_FactoryIterableView.__init__cCsdjt|ƒjt|jƒƒƒS)Nz{}({}))r0ฺtyper'ฺlistr=)r r r r r1ysz_FactoryIterableView.__repr__c Cs*yt|jƒƒWntk r$dSXdS)NFT)ฺnextr=ฺ StopIteration)r r r r r3|s z_FactoryIterableView.__bool__cCs|jƒS)N)r=)r r r r r…sz_FactoryIterableView.__iter__N) r'r(r)r*r r1r3r;rr r r r r<ms r<c@s4eZdZdZdd„Zdd„Zdd„ZeZdd „Zd S) ฺ_SequenceIterableViewzฒWrap an iterable returned by find_matches(). This is essentially just a proxy to the underlying sequence that provides the same interface as `_FactoryIterableView`. cCs ||_dS)N)ฺ _sequence)r ฺsequencer r r r sz_SequenceIterableView.__init__cCsdjt|ƒj|jƒS)Nz{}({}))r0r?r'rD)r r r r r1“sz_SequenceIterableView.__repr__cCs t|jƒS)N)r2rD)r r r r r3–sz_SequenceIterableView.__bool__cCs t|jƒS)N)r rD)r r r r r›sz_SequenceIterableView.__iter__N) r'r(r)r*r r1r3r;rr r r r rC‰s rCcCs,t|ƒrt|ƒSt|tjƒs$t|ƒ}t|ƒS)zCBuild an iterable view from the value returned by `find_matches()`.)ฺcallabler<ฺ isinstancerฺSequencer@rC)ฺmatchesr r r ฺbuild_iter_viewŸs  rJ) r4ฺcompatrฺobjectrฺMappingr+r<rCrJr r r r ฺs  B%