Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/lib/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/lib/persist.pyc


Tc@sddlZddlZddlZddlZdddddddd	gZeZdefd
YZd	efdYZ	defdYZ
defd
YZejdj
ZdZdZdefdYZdefdYZdefdYZdS(iNtPersistt
PickleBackendtBPickleBackendtpath_string_to_tupletpath_tuple_to_stringt
RootedPersisttPersistErrortPersistReadOnlyErrorcBseZRS((t__name__t
__module__(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR#scBseZRS((RR	(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR'scBs"eZdZdddZdZdZdZeeeZ	eeZ
dZdZdZ
ddZeed	Zeeed
ZeeeedZeeedZdeeed
ZeedZeeedZeeedZeedZdZRS(sPersist a hierarchical database of key=>value pairs.

    There are three different kinds of option maps, regarding the
    persistence and priority that maps are queried.

      - hard - Options are persistent.
      - soft - Options are not persistent, and have a higher priority
           than persistent options.
      - weak - Options are not persistent, and have a lower priority
           than persistent options.

    @ivar filename: The name of the file where persist data is saved
        or None if no filename is available.

    cCs|dkrt}n||_|j|_i|_i|_t|_t|_	||_
||_|dk	rtj
j|r|j|ndS(s
        @param backend: The backend to use. If none is specified,
            L{BPickleBackend} will be used.
        @param filename: The default filename to save to and load from. If
            specified, and the file exists, it will be immediately
            loaded. Specifying this will also allow L{save} to be called
            without any arguments to save the persist.
        N(tNoneRt_backendtnewt_hardmapt_softmapt_weakmaptFalset	_readonlyt	_modifiedt_configtfilenametostpathtexiststload(tselftbackendR((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt__init__=s								cCs|jS(N(R(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt
_get_readonlySscCst||_dS(N(tboolR(Rtflag((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt
_set_readonlyVscCs|jS(N(R(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt
_get_modifiedYscCs
t|_dS(s(Set the database status as non-modified.N(RR(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pytreset_modified_scCs|jrtdndS(sRAssert if the object is writable

        @raise: L{PersistReadOnlyError}
        s"Configuration is in readonly mode.N(RR(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pytassert_writablecs	csfd}tjjtjjsV|rCdStdntjjdkry|dSyjj_Wn$|rdStdnXdS(sLoad a persisted database.csod}tjj|rktjj|dkrkyjj|_Wntd|nXtSt	S(Ns.oldisBroken configuration file at %s(
RRtisfiletgetsizeRRR
RtTrueR(tfilepathold(tfilepathR(s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pytload_oldns
NsFile not found: %sisBroken configuration file at %s(	RRt
expanduserR#RR$RRR
(RR'R(((RR's9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRks		cCs|dkr6|jdkr*tdn|j}ntjj|}tjj|rqtj||dntjj|}|rtjj	|rtj
|n|jj||j
dS(sSave the persist to the given C{filepath}.

        If None is specified, then the filename passed during construction will
        be used.

        If the destination file already exists, it will be renamed
        to C{<filepath>.old}.
        sNeed a filename!s.oldN(R
RRRRR)R#trenametdirnametisdirtmakedirsRtsaveR
(RR'R+((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR.s	c
Cs|tk	r!|jj|}nt|}t}|}x|r|}|jd}|jj||}|tkr|r|t| }ntdt	|t
|t|fn||kr<Pq<q<W||k	r
||k	r|jj|||}qn||kr|}nxt
rt|dkrbt	|dtkrYg}	qhi}	n|}	|jj|||	}|tkrtdt	|t	|fn|sPn|}|jd}q"W|S(NisCan't traverse %r (%r): %rsCan't traverse %r with %r(tNOTHINGRtcopytlisttpoptgettNotImplementedtlenRttypeRtstrtsetR%tint(
RtobjRtdefaulttsetvaluetqueuetmarkertnewobjtelemtnewvalue((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt	_traversesJ					cCst|tkr!t|}nt}|rH|j|j||}n|ri|j|j||}n|r|j|j||}nf|j|j||}||kr|j|j||}||kr|j|j||}qn|S(N(R6R7RR/RBRR
R(RRtsoftthardtweakR>tvalue((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt	_getvaluesc	Cs||j||||}t}||kr.tS||kr>tS|jj||}|tkrxtdt|n|S(NsCan't check %r for containment(	RGR/RR%RthasR4RR6(	RRRFRCRDRER:R>tresult((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRHscCsc|j||||}|tkr(gS|jj|}|tkr_tdt|n|S(NsCan't return keys for %s(RGR/RtkeysR4RR6(RRRCRDRER:RI((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRJscCs8|j||||}|tkr(|S|jj|S(N(RGR/RR0(RRR;RCRDRERF((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR3scCs|stt|tkr-t|}n|r?|j}n.|rQ|j}n|jt|_|j	}|j
||d|dS(NR<(tAssertionErrorR6R7RRRR"R%RR
RB(RRRFRCREtmap((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR8s
		cCs|stt|tkr-t|}n|r?|j}n.|rQ|j}n|jt|_|j	}|r|j
||}t|tkr||krdSn|tj
f}|j
||d|dS(NR<(RKR6R7RRRR"R%RR
RBR1tsystmaxint(RRRFtuniqueRCRERLtcurrent((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pytadds 
		cCsd|stt|tkr-t|}n|r?|j}n.|rQ|j}n|jt|_|j	}t
}x|r_||kr|j||d }|d}t}	n|j||}|}t}	t}
||k	r'|j
j|||	}
|
tkr'td|t|fq'n|j
j|r[||k	rN|}q\|d }qvPqvW|
S(NisCan't remove %r from %r(RKR6R7RRRR"R%RR
R/RBRRtremoveR4Rtempty(RRRFRCRERLR>R:R@tisvalueRI((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRRs>
			
		
cCs|p	|s|jnt|tkr:t|}nt|tkr[t|}nt}t}|j|||p|||}||k	r|j|d|d||j||||t	}n|S(NRCRE(
R"R6R7RRR/RGRRR8R%(RtoldpathtnewpathRCRERIR>RF((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pytmove>s
	cCs
t||S(sv
        Rebase the database hierarchy.

        @return: A L{RootedPersist} using this L{Persist} as parent.
        (R(RR((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pytroot_atNsN(RR	t__doc__R
RRRR tpropertytreadonlytmodifiedR!R"RR.R/RBRRGRHRJR3R8RQRRRWRX(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR+s*						 +	%cBseZdZdZedZedZdZee	e	e	dZ
e	e	e	dZd
e	e	e	dZ
e	e	dZe	e	e	d	Zee	e	d
Ze	e	dZdZRS(sxRoot a L{Persist}'s tree at a particular branch.

    This class shares the same interface of L{Persist} and provides a shortcut
    to access the nodes of a particular branch in a L{Persist}'s tree.

    The chosen branch will be viewed as the root of the tree of the
    L{RootedPersist} and all operations will be forwarded to the parent
    L{Persist} as appropriate.
    cCs:||_t|tkr-t||_n	||_dS(s
        @param parent: the parent L{Persist}.
        @param root: a branch of the parent L{Persist}'s tree, that
            will be used as root of this L{RootedPersist}.
        N(tparentR6R7Rtroot(RR]R^((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRbs	cCs
|jjS(N(R]R[(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt<lambda>nscCs
|jjS(N(R]R\(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR_oscCs|jjdS(N(R]R"(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR"qscCsDt|tkr!t|}n|jj|j|||||S(N(R6R7RR]RHR^(RRRFRCRDRE((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRHtscCsAt|tkr!t|}n|jj|j||||S(N(R6R7RR]RJR^(RRRCRDRE((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRJyscCsDt|tkr!t|}n|jj|j|||||S(N(R6R7RR]R3R^(RRR;RCRDRE((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR3~scCsAt|tkr!t|}n|jj|j||||S(N(R6R7RR]R8R^(RRRFRCRE((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR8scCsDt|tkr!t|}n|jj|j|||||S(N(R6R7RR]RQR^(RRRFRORCRE((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRQscCsAt|tkr!t|}n|jj|j||||S(N(R6R7RR]RRR^(RRRFRCRE((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRRscCsit|tkr!t|}nt|tkrBt|}n|jj|j||j|||S(N(R6R7RR]RWR^(RRURVRCRE((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRWscCs8t|tkr!t|}n|jj|j|S(N(R6R7RR]RXR^(RR((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRXsN(RR	RYRRZR[R\R"R/RRHRJR
R3R8RQRRRWRX(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRWs			s(\[-?\d+\])|(?<!\\)\.cCsd|krd|kr|fSg}t|}x|D]}|r8|ddkr|ddkry|jt|dd!Wqtk
rtd|qXq|j|jddq8q8Wt|S(	sConvert a L{Persist} path string to a path tuple.

    Examples:

        >>> path_string_to_tuple("ab")
        ("ab",)
        >>> path_string_to_tuple("ab.cd")
        ("ab", "cd"))
        >>> path_string_to_tuple("ab[0][1]")
        ("ab", 0, 1)
        >>> path_string_to_tuple("ab[0].cd[1]")
        ("ab", 0, "cd", 1)

    Raises L{PersistError} if the given path string is invalid.
    t.t[iit]isInvalid path index: %rs\.(t
_splitpathtappendR9t
ValueErrorRtreplacettuple(RRIttokensttoken((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRs
 
 cCslg}xV|D]N}t|tkr<|dcd|7<q
|jt|jddq
Wdj|S(Nis[%d]R`s\.(R6R9RdR7Rftjoin(RRIR@((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRs
#tBackendcBskeZdZdZdZdZedZdZdZ	dZ
dZd	Zd
Z
RS(sD
    Base class for L{Persist} backends implementing hierarchical storage
    functionality.

    Each node of the hierarchy is an object of type C{dict}, C{list}
    or C{tuple}. A node can have zero or more children, each child can be
    another node or a leaf value compatible with the backend's serialization
    mechanism.

    Each child element is associated with a unique key, that can be used to
    get, set or remove the child itself from its containing node. If the node
    object is of type C{dict}, then the child keys will be the keys of the
    dictionary, otherwise if the node object is of type C{list} or C{tuple}
    the child element keys are the indexes of the available items, or the value
    of items theselves.

    The root node object is always a C{dict}.

    For example:

        >>> backend = Backend()
        >>> root = backend.new()
        >>> backend.set(root, "foo", "bar")
        'bar'
        >>> egg = backend.set(root, "egg", [1, 2, 3])
        >>> backend.set(egg, 0, 10)
        10
        >>> root
        {'foo': 'bar', 'egg': [10, 2, 3]}
    cCs
tdS(N(tNotImplementedError(R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRscCs
tdS(N(Rl(RR'((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRscCs
tdS(N(Rl(RR'RL((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR.scCst|tkr'|j||}nyt|ttfkrt|tkr|y||}Wqtk
rx|}qXq||kr|}q|}nt}|S(s(Lookup a child in the given node object.(R6tdictR3RgR1R9t
IndexErrorR4(RR:R@t_markerR?((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR3s

		cCst|tkr#|}||<nt|tkrt|tkrt|}||kru|jd|}n7|dkrt||kr|jddd}n|}||<nt	}|S(s:Set the value of the given child in the given node object.iN(
R6RmR1R9R5RdR
tabstinsertR4(RR:R@RFR?tlenobj((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR8s$
		cCst}t|tkr7||kr||=t}qnt|tkr|rt|tkry||=t}Wqtk
rqXq||krg|D]}||kr|^q|(t}qnt}|S(sRemove a the given child in the given node object.

        @param isvalue: In case the node object is a C{list}, a boolean
            indicating if C{elem} is the index of the child or the value
            of the child itself.
        (RR6RmR%R1R9RnR4(RR:R@RTRItx((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRRs"

&cCs)t|ttfkr%tj|S|S(sCopy a node or a value.(R6RmR1R0tdeepcopy(RRF((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR03s
cCs|S(s.Whether the given node object has no children.((RR:((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRS9scCs&t|dd}|r"||StS(s?Whether the given node object contains the given child element.t__contains__N(tgetattrR
R4(RR:R@tcontains((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRH=s
cCsEt|dd}|r|St|tkrAtt|StS(s?Return the keys of the child elements of the given node object.RJN(RvR
R6R1trangeR5R4(RR:RJ((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRJDs(RR	RYRRR.R/R3R8RRR0RSRHRJ(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRks								cBs,eZdZdZdZdZRS(cCsddl}||_dS(Ni(tcPicklet_pickle(RRy((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRPscCsiS(N((R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRTscCs2t|}z|jj|SWd|jXdS(N(topenRzRtclose(RR'tfile((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRWscCs;t|d}z|jj||dWd|jXdS(Ntwi(R{RztdumpR|(RR'RLR}((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR.^s(RR	RRRR.(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRNs			cBs,eZdZdZdZdZRS(cCsddlm}||_dS(Ni(tbpickle(t
landscape.libRt_bpickle(RR((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRhscCsiS(N((R((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRlscCs8t|}z|jj|jSWd|jXdS(N(R{RtloadstreadR|(RR'R}((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRoscCs>t|d}z|j|jj|Wd|jXdS(NR~(R{twriteRtdumpsR|(RR'RLR}((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyR.vs(RR	RRRR.(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyRfs			(RRMR0tret__all__tobjectR/t	ExceptionRRRRtcompiletsplitRcRRRkRR(((s9/usr/lib/python2.7/dist-packages/landscape/lib/persist.pyt<module>s$			-I