Your IP : 172.28.240.42


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


[XMc@sdZddlZddlZddlZddlZddlmZdddYZdefdYZej	edefd	YZ
ej	e
d
d
dYZdS(s!
A rotating, browsable log file.
iN(t
threadabletBaseLogFilecBseZdZddgZddZdZeeZdZdZ	dZ
dZd	Zd
Z
dZdZd
ZRS(s<
    The base class for a log file that can be rotated.
    twritetrotatecCs||_||_tjj|||_|dkrstjj|jrstjtj|jtj	|_
n	||_
|jdS(s
        Create a log file.

        @param name: name of the file
        @param directory: directory holding the file
        @param defaultMode: permissions used to create the file. Default to
        current permissions of the file if the file exists.
        N(t	directorytnametostpathtjointNonetexistststattS_IMODEtST_MODEtdefaultModet	_openFile(tselfRRR((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyt__init__s			!(	cOs=tjj|}|tjj|tjj|||S(s=
        Construct a log file from a full file path.
        (RRtabspathtbasenametdirname(tclstfilenametargstkwargstlogPath((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pytfromFullPath*scCs
tdS(sc
        Override with a method to that returns true if the log
        should be rotated.
        N(tNotImplementedError(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pytshouldRotate3scCst|_tjj|jrLt|jdd|_|jjddnf|jdk	rtj
d}zt|jdd|_Wdtj
|Xnt|jdd|_|jdk	rytj|j|jWqtk
rqXndS(s$
        Open the log file.
        sr+iiiisw+N(
tFalsetclosedRRR
tfilet_filetseekRR	tumasktchmodtOSError(RtoldUmask((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR:s	
cCs|jj}|d=|S(NR (t__dict__tcopy(Rtstate((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyt__getstate__SscCs||_|jdS(N(R&R(RR(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyt__setstate__Xs	cCs7|jr#|j|jn|jj|dS(s.
        Write some data to the file.
        N(RtflushRR R(Rtdata((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR\s

cCs|jjdS(s!
        Flush the file.
        N(R R+(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR+escCs#t|_|jjd|_dS(s[
        Close the file.

        The file cannot be used once it has been closed.
        N(tTrueRR tcloseR	(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR.ks	
cCs|j|jdS(s"
        Reopen the log file. This is mainly useful if you use an external log
        rotation tool, which moves under your feet.

        Note that on Windows you probably need a specific API to rename the
        file, as it's not supported to simply use os.rename, for example.
        N(R.R(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pytreopenvs
cCs
t|jS(s>
        Return a LogReader for the current log file.
        (t	LogReaderR(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyt
getCurrentLogsN(t__name__t
__module__t__doc__tsynchronizedR	RRtclassmethodRRR)R*RR+R.R/R1(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRs										tLogFilecBs_eZdZdd
d
dZdZdZdZdZdZ	dZ
d	ZRS(sf
    A log file that can be rotated.

    A rotateLength of None disables automatic log rotation.
    i@BcCs,tj||||||_||_dS(s`
        Create a log file rotating on length.

        @param name: file name.
        @type name: C{str}
        @param directory: path of the log file.
        @type directory: C{str}
        @param rotateLength: size of the log file where it rotates. Default to
            1M.
        @type rotateLength: C{int}
        @param defaultMode: mode used to create the file.
        @type defaultMode: C{int}
        @param maxRotatedFiles: if not None, max number of log files the class
            creates. Warning: it removes all log files above this number.
        @type maxRotatedFiles: C{int}
        N(RRtrotateLengthtmaxRotatedFiles(RRRR8RR9((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRs	cCs#tj||jj|_dS(N(RRR ttelltsize(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRs
cCs|jo|j|jkS(sL
        Rotate when the log file size is larger than rotateLength.
        (R8R;(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRscCs;d|j|f}tjj|s1tdnt|S(sK
        Given an integer, return a LogReader for an old log file.
        s%s.%dsno such logfile exists(RRR
t
ValueErrorR0(Rt
identifierR((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pytgetLogscCs)tj|||jt|7_dS(s.
        Write some data to the file.
        N(RRR;tlen(RR,((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRsc	Cstj|jtjo-tj|jtjs4dS|j}|jxw|D]o}|jdk	r||jkrtj	d|j|fqQtj
d|j|fd|j|dfqQW|jjtj
|jd|j|j
dS(s
        Rotate the file and create a new one.

        If it's not possible to open new logfile, this will fail silently,
        and continue logging to old logfile.
        Ns%s.%dis%s.1(RtaccessRtW_OKRtlistLogstreverseR9R	tremovetrenameR R.R(Rtlogsti((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRs0

2
cCs|g}xetjd|jD]M}y3t|jdd}|rU|j|nWqtk
riqXqW|j|S(sM
        Return sorted list of integers - the old logs' identifiers.
        s%s.*t.i(tglobRtinttsplittappendR<tsort(RtresultRtcounter((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRBs

cCstj|}|d=|S(NR;(RR)(RR(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR)sN(R2R3R4R	RRRR>RRRBR)(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR7s							tDailyLogFilecBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	sFA log file that is rotated daily (at or after midnight localtime)
    cCs3tj||jtj|jd|_dS(Ni(RRttoDateRRRtlastDate(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRs
cCs|j|jkS(s1Rotate when the date has changed since last write(RQRR(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRscGstj|d S(sConvert a unixtime to (year, month, day) localtime tuple,
        or return the current (year, month, day) localtime tuple.

        This function primarily exists so you may overload it with
        gmtime, or some cruft to make unit testing possible.
        i(ttimet	localtime(RR((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRQscCsDydjtt|SWn#djtt|j|SXdS(s>Return the suffix given a (year, month, day) tuple or unixtimet_N(RtmaptstrRQ(Rt	tupledate((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pytsuffixscCsf|j||jkr"|jSd|j|j|f}tjj|s\tdnt|S(s:Given a unix time, return a LogReader for an old log file.s%s.%ssno such logfile exists(	RQRRR1RRYRR
R<R0(RR=R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR>s
cCs/tj||t|j|j|_dS(sWrite some data to the log fileN(RRtmaxRRRQ(RR,((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRscCstj|jtjo-tj|jtjs4dSd|j|j|jf}tjj|ridS|jj	tj
|j||jdS(sRotate the file and create a new one.

        If it's not possible to open new logfile, this will fail silently,
        and continue logging to old logfile.
        Ns%s.%s(RR@RRARRYRRR
R R.RER(Rtnewpath((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRs0
cCstj|}|d=|S(NRR(RR)(RR(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR)'s(R2R3R4RRRQRYR>RRR)(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyRPs			
					R0cBs,eZdZdZddZdZRS(sRead from a log file.cCst|d|_dS(Ntr(RR (RR((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR2si
cCsGg}x:t|D],}|jj}|s2Pn|j|qW|S(sRead a list of lines from the log file.

        This doesn't returns all of the files lines - call it multiple times.
        (trangeR treadlineRL(RtlinesRNRGtline((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyt	readLines5scCs|jjdS(N(R R.(R((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR.Bs(R2R3R4RRaR.(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyR0/s	
(((R4RRIRSRttwisted.pythonRRR7tsynchronizeRPR0(((s:/usr/lib/python2.7/dist-packages/twisted/python/logfile.pyt<module>s0x^
B