Ñò i'dWc @sMdZddkZddklZlZlZddkZddkl Z l Z l Z l Z l Z lZlZddklZlZddklZlZddklZlZlZddklZdd klZd efd „ƒYZd „Z d „Z!defd„ƒYZ"d„Z#defd„ƒYZ$defd„ƒYZ%dS(sz state.py: provide unique state implementations for the different possible nvlistp (as determined by its flags) iÿÿÿÿN(tENOENTtEINVALtENOMEM(t DATA_TYPE_MAPtNV_UNIQUE_NAMEtNV_UNIQUE_NAME_TYPEtDATA_TYPE_BOOLEANtDATA_TYPE_UNKNOWNtDATA_TYPE_NVLISTtDATA_TYPE_NVLIST_ARRAY(tnvlistptnvpairp(tcfunctutil(tNVPairtNVPairIteratortState(tADD(tLOOKUPt _NVPairFalsecBsVeZdZd„Zed„ƒZed„ƒZed„ƒZd„Zd„Z RS(sœ A fake NVPair (real ones require an nvpairp and a State. Only need this for DATA_TYPE_BOOLEAN where non-existence is interpreted as False. cCs ||_dS(N(t_name(tselftname((s ../state.pyt__init__3scCs|iS(N(R(R((s ../state.pyR6scCstS(N(R(R((s ../state.pytdatatype:scCstS(N(tFalse(R((s ../state.pytvalue>scCsdS(N((Rtnvl((s ../state.pytremoveBscCsd|ifS(sx.__repr__() <==> repr(x)sNVPair: %s = False(R(R((s ../state.pyt__repr__Es( t__name__t __module__t__doc__RtpropertyRRRRR(((s ../state.pyR-s  cCs”d„}|i|i}}|itjo||ƒ}nB|itjo1tg}|D]}|||ƒqZ~ƒ}n|i|ƒ||fS(NcSs’tƒ}ti|ti|ƒdƒ}|djoZ|tjotdƒ‚qŽ|tjotdƒ‚qŽt |dt i |ƒƒ‚n|S(Nisnvlist_dup(): invalid arguments!nvlist_dup(): insufficient memorysnvlist_dup(): %s( R R t nvlist_duptCtbyrefRt TypeErrorRt MemoryErrortOSErrortoststrerror(torigtdupterr((s ../state.pyR"Ns     (RRRR ttupleR(tnvpairtnvlistR"RRt_[1]telem((s ../state.pyt_extract_and_deleteJs 1 csøt|tƒo1|d‡fd†‰‰}dˆf}}n?ti|ƒ\‰‰‡‡fd†}dˆtˆf}}g}t|ƒD]}||ƒo ||qq~}t|ƒo|Sˆtjot ˆƒgSt ||ƒ‚dS(sœ _iter_search(State, str) -> (NVPair, ...) _iter_search(State, (str, int)) -> (NVPair, ...) _iter_search(State, (str, str)) -> (NVPair, ...) Given any State, and a valid key, search for a matching NVPair. If the key is just a str, then datatype will not be checked. If the key is a tuple, then both name and datatype must match. If no matches are found KeyError(key) is raised. cs |iˆjS((R(tp(R(s ../state.pytsss%scs|iˆjo |iˆjS((RR(R3(RR(s ../state.pyR4wss(%s, %s)N( t isinstancetstrtNoneR tnormalize_tuple_keyRRtlenRRtKeyError(tstatetkeytcomparetfmttargsR0tpairtacc((RRs ../state.pyt _iter_searchfs 8  t NVLIteratorcBsYeZdZdd„Zed„ƒZd„Zd„Zd„Z e ƒZ e d„Z RS(s NVLIterator is the least powerful of the NVList states. While you can use the dictionary look-up, that will simply retrieve the first matching key it finds. There may be more. cCs1tt|ƒi|ƒ|idjpt‚dS(Ni(tsuperRCRtflagstAssertionError(Rtnvlp((s ../state.pyRŒscCsdS(Ni((R((s ../state.pyREscCs-ti|ƒ\}}t||||ƒdS(N(R R8R(RR<RRR((s ../state.pyt __setitem__”scCs+x$t||ƒD]}|i|ƒqWdS(N(RBR(RR<R@((s ../state.pyt __delitem__šscCs:t||ƒ}g}|D]}||i|ifq~S(N(RBRR(RR<tpairsR0R@((s ../state.pyt__getitem_helper_state__Ÿsc Cswyt||ƒ}Wn9tj o-}||ijo‚qOt|fgSnXg}|D]}|t||ƒqZ~S(N(RBR:t_NVLIterator__markerRR2(RR<tdefaultRJR,R0R@((s ../state.pyt__pop_helper__¦sN( RRR R7RR!RERHRIRKtobjectRLRN(((s ../state.pyRC„s     c CsXt|tƒptdƒ‚nt|tƒo!|d}}d|f}}n-ti|ƒ\}}d|t|f}}tƒ}t i ||t i |ƒƒ}|t tfjo,|tjo t|ƒSt||ƒ‚n.|djo t|dti|ƒƒ‚nt||ƒ}|o.||ijotd|t|fƒ‚n|S(s” _dict_search(State, str) -> NVPair _dict_search(State, (str, int)) -> NVPair _dict_search(State, (str, str)) -> NVPair Given a NVLDictionary State, and a valid key, search for a matching NVPair. If the key is just a str, then datatype will not be checked. If the key is a tuple, then both name and datatype must match. If no matches are found KeyError(key) is raised. s*can only search by name with NVLDictionarys%ss(%s, %s)isnvlist_lookup_nvpair(): %sN(R5t NVLDictionaryR%R6R7R R8RR R tnvlist_lookup_nvpairR#R$RRRRR:R'R(R)RR( R;R<RRR>R?tnvpR,R@((s ../state.pyt _dict_search´s(       RPcBsYeZdZdd„Zed„ƒZd„Zd„Zd„Z e ƒZ e d„Z RS(s NVLDictionary is the most efficient of the NVList States. It is the only one we don't have to loop to find NVpairs. cCstt|ƒi|ƒdS(N(RDRPR(RRG((s ../state.pyRïscCstS(N(R(R((s ../state.pyREòscCs-ti|ƒ\}}t||||ƒdS(N(R R8R(RR<RRR((s ../state.pyRHöscCs t||ƒ}|i|ƒdS(N(RSR(RR<R@((s ../state.pyRIþscCs"t||ƒ}|i|ifgS(N(RSRR(RR<R@((s ../state.pyRKscCs_yt||ƒ}Wn9tj o-}||ijo‚qOt|fgSnXt||ƒgS(N(RSR:t_NVLDictionary__markerRR2(RR<RMR@R,((s ../state.pyRN sN( RRR R7RR!RERHRIRKRORTRN(((s ../state.pyRPés     tNVLTupleDictionarycBsYeZdZdd„Zed„ƒZd„Zd„Zd„Z e ƒZ e d„Z RS(së This state behaves like a python dictionary which must have keys (str, DATA_TYPE). Unfortunately, without an API like nvlist_lookup_nvpair that takes a datatype, we are slowed down when deleting or popping items. cCstt|ƒi|ƒdS(N(RDRUR(RRG((s ../state.pyR"scCstS(N(R(R((s ../state.pyRE%scCs-ti|ƒ\}}t||||ƒdS(N(R R8R(RR<RRR((s ../state.pyRH)scCs$t||ƒd}|i|ƒdS(Ni(RBR(RR<R@((s ../state.pyRI1scCs€t|tƒo;t||ƒ}g}|D]}||i|ifq*~Sti|ƒ\}}t|||ƒ}||fgS(N(R5R6RBRRR R8R(RR<RJR0R@RRtresult((s ../state.pyRK7s ,c Cswyt||ƒ}Wn9tj o-}||ijo‚qOt|fgSnXg}|D]}|t||ƒqZ~S(N(RBR:t_NVLTupleDictionary__markerRR2(RR<RMRJR,R0R@((s ../state.pyRNDsN( RRR R7RR!RERHRIRKRORWRN(((s ../state.pyRUs    (&R tctypesR#terrnoRRRR(tlibnvpair.constRRRRRRR tlibnvpair.cstructR R t libnvpairR R tlibnvpair.privateRRRt libnvpair.addRtlibnvpair.lookupRRORR2RBRCRSRPRU(((s ../state.pyts   4  0 50