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/sob.pyc


[XMc@sadZddlZddlZyddlZWnek
rMddlZnXyddlZWnek
r}ddlZnXddlm	Z	m
Z
ddlmZddl
mZddlmZmZdZdZd	efd
YZdddYZeZd
ejfdYZddZddZdZddddd	dgZdS(s`
Save and load Small OBjects to and from files, using various formats.

Maintainer: Moshe Zadka
iN(tlogtruntime(tmd5(tstyles(t
implementst	InterfacecCsgddlm}t||j}|rA|d|j|7}n|jt|jd j|S(Ni(tAESt i(t
Crypto.CipherRtlent
block_sizetnewRtdigesttencrypt(t
passphrasetdatatciphertleftover((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt_encrypts
cCs6ddlm}|jt|jd j|S(Ni(Ri(RRRRRtdecrypt(RRR((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt_decrypt%stIPersistablecBs)eZdZdZddddZRS(s9An object which can be saved in several formats to a filecCsdS(sWSet desired format.

        @type style: string (one of 'pickle' or 'source')
        N((tstyle((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pytsetStyle.scCsdS(sxSave object to file.

        @type tag: string
        @type filename: string
        @type passphrase: string
        N((ttagtfilenameR((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pytsave4sN(t__name__t
__module__t__doc__RtNoneR(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyR*s	t
PersistentcBsWeZeedZdZdZdZdZdZ	ddddZRS(tpicklecCs||_||_dS(N(toriginaltname(tselfR!R"((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt__init__Cs	cCs
||_dS(sWSet desired format.

        @type style: string (one of 'pickle' or 'source')
        N(R(R#R((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyRGscCs~|r|}|d}n[|rNd|j||f}d|j||f}n&d|j|f}d|j|f}||fS(Ns-2s
%s-%s-2.%ss%s-%s.%ss%s-2.%ss%s.%s(R"(R#RtextRt	finalname((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt_getFilenameNs
cCstt|d}|dkr.||j|n8tj}||j||jt||j|jdS(Ntwb(topenRR!tStringIOtwriteRtgetvaluetclose(R#RRtdumpFunctfts((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt	_saveTempZscCsA|jdkr(ddlm}d}nd}d}||fS(Ntsourcei(t
jellyToSourcettascSstj||ddS(Ni(R tdump(tobjtfile((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyR.isttap(Rttwisted.persisted.aotR3(R#R.R%((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt	_getStyleds		cCs|j\}}|r%d|}n|j|||\}}tjd|jd|d|j|||tjdkrtj	j
|rtj|ntj||tjddS(sxSave object to file.

        @type tag: string
        @type filename: string
        @type passphrase: string
        tesSaving s application to s...twin32sSaved.N(
R:R'RtmsgR"R1RtplatformTypetostpathtisfiletremovetrename(R#RRRR%R.R&((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyRns
 !N(RRRRRR$RR'R1R:RR(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyR=s
				
	
t_EverythingEphemeralcBs eZdZdZdZRS(icCs
||_dS(sS
        @param mainMod: The '__main__' module that this class will proxy.
        N(tmainMod(R#RE((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyR$scCsVyt|j|SWn;tk
rQ|jr3qRtjd|tjSnXdS(Ns#Warning!  Loading from __main__: %s(tgetattrREtAttributeErrortinitRunRR=Rt	Ephemeral(R#tkey((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt__getattr__s
	(RRRHR$RK(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyRDs	c	Csd}|dkr%ddlm}ntjd}}|retjt|t|dj}nt||}tt	j
d}|t	j
d<d|_z||}Wd|jt	j
d<Xt
jd	|_t|d}|dk	r|j|n|S(
sLoad an object from a file.

    Deserialize an object from a file. The file can be encrypted.

    @param filename: string
    @param style: string (one of 'pickle' or 'source')
    @param passphrase: string
    trR2i(tunjellyFromSourcetrbt__main__iNi(R9RMR tloadR*RR)treadRDtsystmodulesRHRERt	doUpgradeRRR(	RRRtmodet_loadtfpteetvaluetpersistable((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyRPs(	
	
	cBsw|rd}nd}e||}i|d6}|r_|j}e||}|||Un
|||U||}|S(s)Load the value of a variable in a Python file.

    Run the contents of the file, after decrypting if C{passphrase} is
    given, in a namespace and return the result of the variable
    named C{variable}.

    @param filename: string
    @param variable: string
    @param passphrase: string
    RNRLt__file__(R)RQR(RtvariableRRUtfileObjtdRRY((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pytloadValueFromFiles	



cCsOtjj|d}idd6dd6dd6dd6dd6d	d
6d	d6|S(Nitpythons.tacs.etacs.pyR s.taps.etapR2s.tass.etas(R?R@tsplitext(RR%((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt	guessTypesR_RPt
PersistantRb((RR?RRtcPickleR tImportErrort	cStringIOR*ttwisted.pythonRRttwisted.python.hashlibRttwisted.persistedRtzope.interfaceRRRRRRRcRIRDRRPR_Rbt__all__(((s9/usr/lib/python2.7/dist-packages/twisted/persisted/sob.pyt<module>
s0

		D$