Your IP : 172.28.240.42


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


5Nc	@s*dZddlZddlZddlZddlZddlmZmZddlm	Z	dd(dYZ
de
fdYZd	e
fd
YZde
fdYZ
d
d)dYZdd*dYZeZejejejejejejejejejg	ZyejejWnek
rCnXdd+dYZdd,dYZdd-dYZ dd.dYZ!dZ"de#fdYZ$ej%dZ&dZ'dZ(dZ)d Z*d!Z+d"d/d#YZ,d$Z-dd%Z/d&d0d'YZ0dS(1s|
AOT: Abstract Object Trees
The source-code-marshallin'est abstract-object-serializin'est persister
this side of Marmalade!
iN(treflecttlog(tcrefutiltNamedcBseZdZRS(cCs
||_dS(N(tname(tselfR((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt__init__s(t__name__t
__module__R(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRstClasscBseZdZRS(cCsd|jS(Ns	Class(%r)(R(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt	getSources(RRR
(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR	stFunctioncBseZdZRS(cCsd|jS(NsFunction(%r)(R(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
#s(RRR
(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR"stModulecBseZdZRS(cCsd|jS(Ns
Module(%r)(R(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
's(RRR
(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR&stInstanceMethodcBseZdZdZRS(cCs_t|tp*t|tp*t|ts@td|n||_||_||_dS(Ns$%s isn't an Instance, Ref, or Deref!(t
isinstancetReftInstancetDereft	TypeErrorRtklasstinstance(RRRtinst((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR,s
-		cCs d|j|jt|jfS(NsInstanceMethod(%r, %r, 
%s)(RRtprettifyR(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
3s(RRRR
(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
+s	t_NoStateObjcBseZRS((RR(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR7sRcBseZedZdZRS(cKset|tjs%td|n||_|tk	rO||_d|_n||_d|_dS(Ns%s isn't a string!ii(Rttypest
StringTypeRRt
NoStateObjtstatetstateIsDict(Rt	classNamet__stateObj__R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRFs			cCs|jr|j}n?t|jtrNt|jjtjrN|jj}nd}|dk	ryd|jt	|fSWqt
k
rd|jt|fSXnd|jt|jfS(NsInstance(%r, %s)(RRRRtobjRtDictTypetNoneRtdictToKWtNonFormattableDictR(Rt	stateDict((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
Qs	*
(RRRRR
(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyREsRcBs,eZdZdZdZdZRS(cGsNt|dkr/|d|_|d|_n|sJd|_d|_ndS(Niii(tlentrefnumRR!(Rtargs((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRbs
	cCs2|jr%td||jfn||_dS(Ns&Error setting id %s, I already have %s(R&t
ValueError(Rtnum((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pytsetRefks	cCs2|jr%td||jfn||_dS(Ns'Error setting obj %s, I already have %s(RR((RR((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pytsetObjps	cCsN|jdkrtdn|jrAd|jt|jfSt|jS(Ns7Don't try to display me before setting an object on me!s
Ref(%d, 
%s)(RR!tRuntimeErrorR&R(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
us
	(RRRR*R+R
(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR`s				RcBs eZdZdZeZRS(cCs
||_dS(N(R&(RR)((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR~scCsd|jS(Ns	Deref(%d)(R&(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
s(RRRR
t__repr__(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR}s		tCopyregcBseZdZdZRS(cCs||_||_dS(N(tloadfuncR(RR/R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRs	cCsd|jt|jfS(NsCopyreg(%r, %s)(R/RR(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
s(RRRR
(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR.s	cCstdt|S(sDPass me an AO, I'll return a nicely-formatted source representation.sapp = (t	indentifyR(tao((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR
sR#cBseZdZRS(s&A dictionary was not formattable.
    (RRt__doc__(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR#ss[a-zA-Z_][a-zA-Z0-9_]*$cCsg}|j}|jxx|D]p\}}t|tjsTtd|ntj|svtd|n|jd|t	|fq#Wdj
|S(Ns%r ain't a strings%r ain't an identifiers
%s=%s,t(titemstsortRRRR#trtmatchtappendRtjoin(tdtoutR4tktv((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR"s
cCst|dr|jSt|}|tkr;t|S|tjkrdg}x=|jD]/\}}|jdt	|t	|fq`W|jt
|rdpddj|S|tjkr+dg}x%|D]}|jdt	|qW|jt
|rd	pd
dj|S|tj
krdg}x%|D]}|jdt	|qJW|jt
|rdpd
dj|Std||fdS(NR
t{s	
%s: %s,s
}t}R3t[s
%s,s
]t]t(s
)t)s/Unsupported type %s when trying to prettify %s.(thasattrR
ttypet_SIMPLE_BUILTINStreprRR R4R8RR%R9tListTypet	TupleTypeR(RttR;R<R=tx((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRs0

	'
	

	

cCsGg}g}||d}d|g}tj|j|dj|S(NcSsl|d	kr|j|n|d
kr5|jn|dkr[|jdt|n
|j|dS(NR@RBR>RARCR?ts  (R@RBR>(RARCR?(R8tpopR%(REtvalR6tctlR;tstack((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyteaters
R3(ttokenizeRMR9(tsR;RQRRRP((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR0scCstj|S(sG
    Pass me an Abstract Object Tree, and I'll unjelly it for you.
    (tAOTUnjelliertunjelly(taot((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pytunjellyFromAOTscBsied6ed6ed6ed6ed6ed6ed6ed6}e|d	r^|j	|Un||U|j
d
re|d
Sed|dS(
s
    Pass me a string of code or a filename that defines an 'app' variable (in
    terms of Abstract Objects!), and I'll execute it and unjelly the resulting
    AOT for you, returning a newly unpersisted Application object!
    RR
R	RRRRR.treadtapps'%s needs to define an 'app', it didn't!N(
RR
R	RRRRR.RDRYthas_keyRXR((tstringOrFiletns((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pytunjellyFromSources

RUcBsMeZdZdZdZdZdZdZdZdZ	RS(sWI handle the unjellying of an Abstract Object Tree.
    See AOTUnjellier.unjellyAO
    cCsi|_g|_g|_dS(N(t
referencesRQtafterUnjelly(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRs		cCs#tj}|j|d||S(sUnjelly a node, later.
        i(Rt_DefertunjellyInto(RtnodeR:((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pytunjellyLaterscCsB|j|}|||<t|tjr>|j||n|S(svUtility method for unjellying one object into another.
        This automates the handling of backreferences.
        (t	unjellyAORRtNotKnowntaddDependant(RRtlocR1to((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRb s

cCsQt|tjr.dg}|j|dn	|g}|jj||fdS(Ni(RRRfR!RgR`R8(RtcallabletresultRP((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt	callAfter*s
		cCs|j|j||dS(sUtility method for unjellying into instances of attributes.

        Use this rather than unjellyAO unless you like surprising bugs!
        Alternatively, you can use unjellyInto on your instance's __dict__.
        N(Rbt__dict__(RRtattrNameR1((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pytunjellyAttribute2scCsd|jj|t|}|tjkr|j}|tkrPtj|j	S|t
tgksqt|trtj
|j	S|tkr3|j	}tj
|j}|j|j}||jkr$|d	krt||St|tjrtj|||Stj|j|||SqtdqV|tkrtj
|j}|j|j}t|drtj|i}	|j|	j|ntj||}	|	S|t kr`|j|j!}
|j"}|j#j$|}|d	kr|
|j#|<nWt|tjr4|j%|
|
|j#|<n(|d	krCnt&d|||f|
S|t'kr|j"}
|j#j$|
}|d	krtj(|
}||j#|
<|S|S|t)krVtj
|j*}|j+|jj,d|}|SnY|t-kr
|S|tj.krag}x8|D]0}|jd	|j/|t0|d|q)W|S|tj1krg}t2}xR|D]J}|jd	t|j/|t0|d|tjrtj3}qqW||S|tj4krFi}xO|j5D]A\}}tj6|}|j/|d||j/|d|qW|Std||jd=d	S(
saUnjelly an Abstract Object and everything it contains.
        I return the real object.
        sinstance method changedt__setstate__s1Multiple references with the same ID: %s, %s, %s!cSs
t||S(N(tapply(Rkt_l((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt<lambda>siisUnsupported AOT type: %siN(7RQR8RERtInstanceTypet	__class__RRtnamedModuleRR	Rt
issubclasstnamedObjectR
RReRRmR!tgetattrRRRft_InstanceMethodt
MethodTypeRRRRDRlRpRRR&R_tgettresolveDependantsR(Rt_DereferenceR.R/RdtaddCallbackRFRHRbR%RIttuplet_TupleR R4t_DictKeyAndValue(RR1RJROtim_nametim_classtim_selfRRRRitrefkeytrefR)tderR/R:RPRKttuple_R<R=tkvd((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRe;s	!	

	
	


!

+
cCsyPdg}|j|d|x%|jD]\}}||dq)W|dSWn9tjdtjdjtt|jnXdS(Nis+Error jellying object! Stacktrace follows::s
(	R!RbR`RtmsgR9tmapRGRQ(RR1RPtfuncR=((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRVs	
"(
RRR2RRdRbRlRoReRV(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRU
s			
				kcCstj|S(s-Convert an object to an Abstract Object Tree.(t
AOTJelliertjelly(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt
jellyToAOTscCs6t|}|r(|jt|n
t|SdS(s
    Pass me an object and, optionally, a file object.
    I'll convert the object to an AOT either return it (if no file was
    specified) or write it to the file.
    N(RtwriteR
(RtfileRW((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt
jellyToSourcesRcBs,eZdZdZdZdZRS(cCsi|_d|_g|_dS(Ni(tpreparedt_ref_idRQ(R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRs		cCs||jt|<dS(saI prepare an object for later referencing, by storing its id()
        and its _AORef in a cache.N(Rtid(Rtaoreftobject((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt
prepareForRefscCs6t|}|jjt||tkr7|}n|tjkryt|jj	t
j|j|j
|j}n|tjkrt|j	}n|tjkrtt
j|}ngt|trtt
j|}n@|tjkrtt
j|}n|jjt|r|jt|}|jrO|j}n&|jd|_|j}|j|t|St}|j|||tj kr|j!t"|j
|ne|tj#kr|j!t$t"|j
|n4|tj%krRi}x6|j&D](\}}|j
|||j
|<qW|j!|n|tj'krt(|dr|j
|j)}	n|j
|j*}	|j!t+t
j|j,|	nit-j.j|rt-j.||\}
}	|j!t/t
j|
|j
|	nt0d|j	|jd=|S(s+I turn an object into an AOT and return it.it__getstate__sUnsupported type: %si(1RERQR8RGRFRR{R
tim_funcRRtqualRt	jellyToAORt
ModuleTypeRt	ClassTypeR	RwtFunctionTypeRtfullFuncNameRR[RR&RR*RRRRHR+RRIRtDictionaryTypeR4RtRDRRmRRutcopy_regtdispatch_tableR.R(RRtobjTypetretvaltoldReftkeyR:R<R=RtunpickleFunc((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRs\	
		

	" %
cCsNy|j|}|SWn0tjdtjdj|jnXdS(Ns+Error jellying object! Stacktrace follows::s
(RRRR9RQ(RRR1((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyR)s
(RRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyRs			U((((((((((1R2RRRStrettwisted.pythonRRttwisted.persistedRRR	RRR
RRRtUnicodeTypetIntTypet	FloatTypetComplexTypetLongTypetNoneTypet	SliceTypetEllipsisTypeRFR8tBooleanTypetAttributeErrorRRRR.R
t	ExceptionR#tcompileR6R"RR0RXR^RURR!RR(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/aot.pyt<module>sB0		

			!