Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/persisted/journal/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyc


[XMc@s1dZddlmZddlZddlZyddlZWnek
r]ddlZnXddlm	Z	m
Z
dddYZdefdYZd	e
fd
YZ
de
fdYZd
ddYZdddYZdddYZedZdddYZedZdS(s)Basic classes and interfaces for journal.i(t
nested_scopesN(t
implementst	InterfacetJournalcBsDeZdZdZdZdZdZdZdZRS(s}All commands to the system get routed through here.

    Subclasses should implement the actual snapshotting capability.
    cCs(||_||_|jj|_dS(N(tlogtjournaledServicetgetCurrentIndextlatestIndex(tselfRR((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyt__init__s		cCs\|j}||jkrXx:|jj|dD]\}}|j|j|q2WndS(sRun all commands from log that haven't been run yet.

        This method should be run on startup to ensure the snapshot
        is up-to-date.
        iN(tgetLastSnapshotRRtgetCommandsSincetexecuteR(Rt
snapshotIndextcmdtimetcommand((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyt
updateFromLog$s#cCs;tj}|jj||}|j|j|||S(sLog and execute a command.(ttimeRt
logCommandtaddCallbackt_reallyExecute(RRtrunTimetd((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pytexecuteCommand/scCs"|j|j|}||_|S(s-Callback called when logging command is done.(RRR(RtindexRRtresult((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR6s	cCs
tdS(s0Return command index of the last snapshot taken.N(tNotImplementedError(R((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR
<scOs
tdS(sSave journal to disk, returns Deferred of finish status.

        Subclasses may choose whatever signature is appropriate, or may
        not implement this at all.
        N(R(Rtargstkwargs((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pytsync@s(	t__name__t
__module__t__doc__R	RRRR
R(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRs					t
MemoryJournalcBs)eZdZdZdZdZRS(s6Prevayler-like journal that dumps from memory to disk.cCs||_tjj|r|y%tjt|d\|_}Wn,tttj	fk
rnd\|_}nX||nd|_|dtj|||dS(Ntrbi(iN(
tpathtostexiststpickletloadtopentlastSynctIOErrortOSErrortUnpicklingErrortNoneRR	(RRRR#tloadedCallbacktobj((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR	Ms	%
	
cCs|jS(N(R)(R((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR
ZscCsHt|jd}tj|j|f|d|j|j|_dS(Ntwbi(R(R#R&tdumpRtcloseR)(RR/tf((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR]s
(RRR R	R
R(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR!Js	
	tICommandcBseZdZdZRS(s@A serializable command which interacts with a journaled service.cCsdS(s"Run the command and return result.N((RR((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRhs(RRR R(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR4estICommandLogcBs)eZdZdZdZdZRS(sInterface for command log.cCsdS(s`Add a command and its run time to the log.

        @return: Deferred of command index.
        N((RR((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRoscCsdS(s-Return index of last command that was logged.N((((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRuscCsdS(sReturn commands who's index >= the given one.

        @return: list of (time, command) tuples, sorted with ascending times.
        N((R((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRxs(RRR RRR(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR5ls		tLoadingServicecBseZdZdZRS(s7Base class for journalled service used with Wrappables.cCs
tdS(s'Return object of specified type and id.N(R(RtobjTypetobjId((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyt
loadObjects(RRR R9(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR6st	WrappablecBseZdZdZdZRS(s0Base class for objects used with LoadingService.cCs
tdS(s5Return uid for loading with LoadingService.loadObjectN(R(R((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pytgetUidsN(RRR R-t
objectTypeR;(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR:stWrapperCommandcBs3eZeedidZdZdZRS(cCsC||_|j|_|j|_||_||_||_dS(N(R/R;R8R<R7t
methodNameRR(RR>R/RR((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR	s			cCsRt|ds*|j|j|j}n	|j}t||j|j|jS(NR/(	thasattrR9R7R8R/tgetattrR>RR(RtsvctcommandTimeR/((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRs	cCs|jj}|d=|S(NR/(t__dict__tcopy(RR((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyt__getstate__s((RRRR4R	RRE(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR=s
	csfd}|S(sWrap a method so it gets turned into command automatically.

    For use with Wrappables.

    Usage::

        | class Foo(Wrappable):
        |     objectType = "foo"
        |     def getUid(self):
        |         return self.id
        |     def _bar(self, x):
        |         return x + 1
        |
        |     bar = command('_bar')

    The resulting callable will have signature identical to wrapped
    function, except that it expects journal as first argument, and
    returns a Deferred.
    cs|j|||S(N(R(R/tjournalRR(R>tcmdClass(sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pytwrappers((R>RGRH((RGR>sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRstServiceWrapperCommandcBs<eZeedidZdZdZdZRS(cCs||_||_||_dS(N(R>RR(RR>RR((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyR	s		cCst||j|j|jS(N(R@R>RR(RRARB((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRscCsd|j|j|jfS(Ns#<ServiceWrapperCommand: %s, %s, %s>(R>RR(R((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyt__repr__scCs*t|dr"t|j|jSdSdS(NRCi(R?tcmpRC(Rtother((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyt__cmp__s((RRRR4R	RRJRM(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRIs

		csfd}|S(sWrap methods into commands for a journalled service.

    The resulting callable will have signature identical to wrapped
    function, except that it expects journal as first argument, and
    returns a Deferred.
    cs|j||S(N(R(R/RFRR(R>RG(sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyRHs((R>RGRH((RGR>sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pytserviceCommands((((((R t
__future__RR$RtcPickleR&tImportErrortzope.interfaceRRRR!R4R5R6R:R=RRIRN(((sB/usr/lib/python2.7/dist-packages/twisted/persisted/journal/base.pyt<module>	s"
1