ó i'dWc@sÖdZddlZddlmZddlmZddlZddlmZm Z m Z ddl m Z m Z ddlmZddlmZd efd „ƒYZd efd „ƒYZd efd„ƒYZdS(s private: classes used by the individual State implementations and NVList. NVPair: wrapper around nvpairp. NVPairIterator: Iterator for all NVList states. next() returns NVPair objects. NVKeysIterator: Iteratoer for all NVList states. next() returns a tuple of (str, int) where str is the name, and int is in DATA_TYPES. State: provide the (abstract) base class for NVLIterator, NVLDictionary, NVLTupleDictionary. State is where __del__ is implemented. If a State object is garbage collected, the nvlist_t it is holding onto will have nvlist_free called on it. This means that NVPair should hang on to a reference to the State object that created it. Same for any NVList returned from an NVPair, or any other means, e.g. __getitem__(). ALL reference tracking happens in this module alone. iÿÿÿÿN(tIterator(tEINVAL(t DATA_TYPE_MAPtDATA_TYPE_NVLISTtDATA_TYPE_NVLIST_ARRAY(tnvlistptnvpairp(tcfunc(tVALUEtNVPaircBsVeZdZd„Zed„ƒZed„ƒZed„ƒZd„Zd„Z RS(sclass to wrap nvpairpcCsRt|tƒstdƒ‚nt|tƒs<tdƒ‚n||_||_dS(Ns(state must be a libnvpair.abstract.StatesNVPair must be given an nvpairp(t isinstancetStatet TypeErrorRt_statet_as_parameter_(tselftstatetnvp((s ../private.pyt__init__Es  cCs tj|ƒS(s(name of this NVPair, always an ASCII str(Rt nvpair_name(R((s ../private.pytnamePscCs+t|dƒs$tj|ƒ|_n|jS(s<datatype of this NVPair, an int in libnvpair.const.DATA_TYPEt _datatype(thasattrRt nvpair_typeR(R((s ../private.pytdatatypeUscCsdt|j|ƒ}|jtkr1|j|_n/|jtkr`x|D]}|j|_qGWn|S(svalue stored in NVPair(RRRR t_refR(Rtresulttelem((s ../private.pytvalue]s cCs\tj||ƒ}|dkrX|tkr9tdƒ‚nt|dtj|ƒƒ‚ndS(Nis(nvlist_remove_nvpair(): invalid argumentsnvlist_remove_nvpair(): %s(Rtnvlist_remove_nvpairRR tOSErrortoststrerror(Rtnvlterr((s ../private.pytremovehs    cCsd|jt|j|jfS(sx.__repr__() <==> repr(x)sNVPair: %s <%s> = %s(RRRR(R((s ../private.pyt__repr__ps  ( t__name__t __module__t__doc__RtpropertyRRRR#R$(((s ../private.pyR Bs  tNVPairIteratorcBs#eZdZed„Zd„ZRS(s@class to manage iterating over the _NVPair objects in an NVList.cCsst|tƒstdƒ‚nt|tƒs<tdƒ‚n||_d|_itjt 6tj t 6||_ dS(Ns(state must be a libnvpair.abstract.Statesforward must be a bool( R R R tboolR tNonet_invpRtnvlist_next_nvpairtTruetnvlist_prev_nvpairtFalset _function(RRtforward((s ../private.pyRzs   cCsI|j|j|jƒ|_|js0tƒ‚nt|j|jƒ}|S(s2x.next() -> the next value, or raise StopIteration(R1R R,t StopIterationR (Rtpair((s ../private.pytnextˆs   (R%R&R'R.RR5(((s ../private.pyR)xs R cBseZdZejZd d„Zd„Zej d„ƒZ ej d„ƒZ ej d„ƒZ ej d„ƒZd„Zej d„ƒZRS( sª Abstract Base Class for all the NVList states. The state is determined by the flags of the NVList. State does not change, it is set at allocation time. cCs>t|tƒstdƒ‚n||_t|dƒ |_dS(Ns$NVLIterator must be given an nvlistpR(R RR RRt_track(Rtnvlp((s ../private.pyR›s cCs&|jrtj|ƒnd|_dS(N(R6Rt nvlist_freeR+R(R((s ../private.pyt__del__¡s cCs t‚dS(N(tNotImplementedError(R((s ../private.pytflags¨scCs t‚dS(N(R:(RtkeyR((s ../private.pyt __setitem__¬scCs t‚dS(N(R:(RR<((s ../private.pyt __delitem__°scCsdS(s+__getitem_helper__(key) -> result, datatypeN((RR<((s ../private.pyt__getitem_helper_state__´scsD‡fd†}ˆj|ƒ}g|D]\}}|||ƒ^q%S(s+__getitem_helper__(key) -> result, datatypecsK|tkrˆ|_n)|tkrAx|D]}ˆ|_q+Wn||fS(N(RRR(RRR(R(s ../private.pytfixitem¿s     (R?(RR<R@RRR((Rs ../private.pyt__getitem_helper__¹scCs t‚dS(N(R:(RR<tdefault((s ../private.pyt__pop_helper__ÊsN(R%R&R'tabctABCMetat __metaclass__R+RR9tabstractpropertyR;tabstractmethodR=R>R?RARC(((s ../private.pyR ‘s    (R'RDt collectionsRterrnoRRtlibnvpair.constRRRtlibnvpair.cstructRRt libnvpairRtlibnvpair.valueRtobjectR R)R (((s ../private.pyt4s  6