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


pGNc@ sdZddlmZddlZddlZddlZddlmZddlZddlm	Z	ddl
mZmZm
Z
dd.dYZd	e	fd
YZejeidd6d
d6dZdZdagagadZdZdZdZdZdZdZdddZeZdd/dYZ dd0dYZ!ye"Wn>e#k
re!Z"e"j$Z$e"j%Z%e"j&Z&e"j'Z'nXdZ(dZ)dd1d YZ*d!e+fd"YZ,d#d2d$YZ-yt.Wne#k
rda.nXd%Z/d&d'Z0d(d3d)YZ1d*Z2yt3WnMe#k
re-de4ej5d+da3e-d&e4ej6d+dZ7nXd,d4d-YZ8ddl9Z9ddl:Z:e9j;e!yt<Wn$e#k
re8a<t<j=nXdS(5s%
Logging and metrics infrastructure.
i(tdivisionN(tdatetime(t	Interface(tutiltcontexttreflecttILogContextcB seZdZRS(s
    Actually, this interface is just a synoym for the dictionary interface,
    but it serves as a key for the default information in a log.

    I do not inherit from Interface because the world is a cruel place.
    (t__name__t
__module__t__doc__(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRstILogObservercB seZdZdZRS(s
    An observer which can do something with log events.

    Given that most log observers are actually bound methods, it's okay to not
    explicitly declare provision of this interface.
    cC sdS(si
        Log an event.

        @type eventDict: C{dict} with C{str} keys.
        @param eventDict: A dictionary with arbitrary keys.  However, these
            keys are often available:
              - C{message}: A C{tuple} of C{str} containing messages to be
                logged.
              - C{system}: A C{str} which indicates the "system" which is
                generating this event.
              - C{isError}: A C{bool} indicating whether this event represents
                an error.
              - C{failure}: A L{failure.Failure} instance
              - C{why}: Used as header of the traceback in case of errors.
              - C{format}: A string format used in place of C{message} to
                customize the event.  The intent is for the observer to format
                a message by doing something like C{format % eventDict}.
        N((t	eventDict((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt__call__(s(RRR	R(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyR
!sitisErrort-tsystemcO s?tjtj}|j|tji|t6|||S(N(RtgetRtcopytupdatetcall(tctxtfunctargstkwtnewCtx((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytcallWithContextBs
cO sy|j}Wn-tk
r&nd}td|nXyti|d6|||SWn'tk
rtntd|nXdS(s
    Utility method which wraps a function in a try:/except:, logs a failure if
    one occurrs, and uses the system's logPrefix.
    s(buggy logPrefix method)RN(t	logPrefixtKeyboardInterruptterrR(tloggerRRRtlp((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytcallWithLoggerGs

cC s#tjddtdddadS(s
    DEPRECATED in Twisted 2.5.

    Support function for testing frameworks.

    Start keeping errors in a buffer which can be retrieved (and emptied) with
    flushErrors.
    s6log.startKeepingErrors is deprecated since Twisted 2.5tcategoryt
stackleveliiN(twarningstwarntDeprecationWarningt_keepErrors(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytstartKeepingErrors`s	
cG s#tjddtddt|S(s
    DEPRECATED in Twisted 2.5.  See L{TestCase.flushLoggedErrors}.

    Support function for testing frameworks.

    Return a list of errors that occurred since the last call to flushErrors().
    (This will return None unless startKeepingErrors has been called.)
    slog.flushErrors is deprecated since Twisted 2.5. If you need to flush errors from within a unittest, use TestCase.flushLoggedErrors instead.R R!i(R"R#R$t_flushErrors(t
errorTypes((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytflushErrorsos

cG slt}ga|rhxS|D]H}d}x&|D]}|j|r,d}q,q,W|rt|qqWn|S(s)
    PRIVATE. DEPRECATED. DON'T USE.
    ii(t_keptErrorstcheckR(R(tkterktshouldReLogterrT((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyR's


cG s'tjddtddt|dS(s
    DEPRECATED
    s0log.ignoreErrors is deprecated since Twisted 2.5R R!iN(R"R#R$t_ignore(ttypes((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytignoreErrorss
cG s"x|D]}tj|qWdS(s)
    PRIVATE. DEPRECATED. DON'T USE.
    N(t
_ignoreErrorstappend(R1ttype((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyR0s
cC s$tjddtddtdS(s
    DEPRECATED
    s0log.clearIgnores is deprecated since Twisted 2.5R R!iN(R"R#R$t
_clearIgnores(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytclearIgnoress
cC s
gadS(s)
    PRIVATE. DEPRECATED. DON'T USE.
    N(R3(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyR6scK s|dkrtj}nt|tjrtrtrd}x3tD]+}|j|}|rkd}PqFd}qFW|rtj|qqtj|nt	d|d|dd|nVt|t
rt	dtj|d|dd|nt	t|d|dd|dS(s
    Write a failure to the log.

    The C{_stuff} and C{_why} parameters use an underscore prefix to lessen
    the chance of colliding with a keyword argument the application wishes
    to pass.  It is intended that they be supplied with arguments passed
    positionally, not by keyword.

    @param _stuff: The failure to log.  If C{_stuff} is C{None} a new
        L{Failure} will be created from the current exception state.  If
        C{_stuff} is an C{Exception} instance it will be wrapped in a
        L{Failure}.
    @type _stuff: C{NoneType}, C{Exception}, or L{Failure}.

    @param _why: The source of this failure.  This will be logged along with
        C{_stuff} and should describe the context in which the failure
        occurred.
    @type _why: C{str}
    iitfailuretwhyR
N(tNoneR8tFailuret
isinstanceR%R3R+R*R4tmsgt	Exceptiontrepr(t_stufft_whyRtkeepRtr((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs&

(tLoggercB seZdZdZRS(sM
    This represents a class which may 'own' a log. Used by subclassing.
    cC sdS(s
        Override this method to insert custom logging behavior.  Its
        return value will be inserted in front of every line.  It may
        be called more times than the number of output lines.
        R((tself((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs(RRR	R(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRDstLogPublishercB sSeZdZdgZdZdZdZdZdZdddZ
RS(	s5
    Class for singleton log message publishing.
    R=cC s
g|_dS(N(t	observers(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt__init__scC s&t|st|jj|dS(s
        Add a new observer.

        @type other: Provider of L{ILogObserver}
        @param other: A callable object that will be called with each new log
            message (a dict).
        N(tcallabletAssertionErrorRGR4(REtother((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytaddObserverscC s|jj|dS(s%
        Remove an observer.
        N(RGtremove(RERK((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytremoveObserverscO s
tjtpij}|j|||d<tj|d<xtt|jdddD]}y|j||Wqbt	k
rqbt
k
rqb|j|}d|j|<y!|jtj
d|fWnnX||j|<qbXqbWdS(sJ
        Log a new message.

        For example::

        >>> log.msg('Hello, world.')

        In particular, you MUST avoid the forms::

        >>> log.msg(u'Hello, world.')
        >>> log.msg('Hello ', 'world.')

        These forms work (sometimes) by accident and will be disabled
        entirely in the future.
        tmessagettimeiicS sdS(N(R:(tevent((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt<lambda>$ssLog observer %s failed.N(RRRRRRPtxrangetlenRGRtUnicodeEncodeErrort_errR8R;(RERORtactualEventDicttitobserver((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyR=s(

&


cC s |jd|d|dddS(s
        Log a failure.

        Similar in functionality to the global {err} function, but the failure
        gets published only to observers attached to this publisher.

        @param failure: The failure to log.
        @type failure: L{Failure}.

        @param why: The source of this failure.  This will be logged along with
            the C{failure} and should describe the context in which the failure
            occurred.
        @type why: C{str}
        R8R9R
iN(R=(RER8R9((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRV0scC s|d	kr@|jd|dtj|d|d|ddnAtjd
krht|||||nt||||||d	S(s
        Twisted-enabled wrapper around L{warnings.showwarning}.

        If C{file} is C{None}, the default behaviour is to emit the warning to
        the log system, otherwise the original L{warnings.showwarning} Python
        function is called.
        twarningR tfilenametlinenotformats2%(filename)s:%(lineno)s: %(category)s: %(warning)siiN(ii(R:R=Rtqualtsystversion_infot_oldshowwarning(REROR R[R\tfiletline((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytshowwarningBs	
N(RRR	tsynchronizedRHRLRNR=RVR:Rd(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRFs					*	cC sny||}WnYtk
r$nFyd||f}Wqjyd|f}Wqfd}qfXqjXnX|S(s
    Try to format the string C{fmtString} using C{fmtDict} arguments,
    swallowing all errors to always return a string.
    sDInvalid format string or unformattable object in log message: %r, %ss=UNFORMATTABLE OBJECT WRITTEN TO LOG with fmt %r, MESSAGE LOSTsJPATHOLOGICAL ERROR IN BOTH FORMAT STRING AND MESSAGE DETAILS, MESSAGE LOST(R(t	fmtStringtfmtDictttext((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt_safeFormatbs
cC s|d}|sy|drPd|krP|jdp8dd|dj}qd|krrt|d|}qdSnd	jttj|}|S(
s
    Extract text from an event dict passed to a log observer. If it cannot
    handle the dict, it returns None.

    The possible keys of eventDict are:
     - C{message}: by default, it holds the final text. It's required, but can
       be empty if either C{isError} or C{format} is provided (the first
       having the priority).
     - C{isError}: boolean indicating the nature of the event.
     - C{failure}: L{failure.Failure} instance, required if the event is an
       error.
     - C{why}: if defined, used as header of the traceback in case of errors.
     - C{format}: string format used in place of C{message} to customize
       the event. It uses all keys present in C{eventDict} to format
       the text.
    Other keys will be used when applying the C{format}, or ignored.
    ROR
R8R9sUnhandled Errors
R]Nt (RtgetTracebackRitjointmapRtsafe_str(RtedmRh((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyttextFromEventDict|s
*tFileLogObservercB sJeZdZdZdZdZdZdZdZ	dZ
RS(s
    Log observer that writes to a file-like object.

    @type timeFormat: C{str} or C{NoneType}
    @ivar timeFormat: If not C{None}, the format string passed to strftime().
    cC s|j|_|j|_dS(N(twritetflush(REtf((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRHscC s.tj|tj|}|jd|jS(s*
        Return the current local timezone offset from UTC.

        @type when: C{int}
        @param when: POSIX (ie, UTC) timestamp for which to find the offset.

        @rtype: C{int}
        @return: The number of seconds offset from UTC.  West is positive,
        east is negative.
        i<iiiQ(Rtutcfromtimestampt
fromtimestamptdaystseconds(REtwhentoffset((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytgetTimezoneOffsetsc
C s|jdk	r+tj|jtj|S|j|}tj||}tt	|dd}tt	|dd}|dkrd}nd}d|j
|j|j|j
|j|j|||f	S(s
        Format the given UTC value as a string representing that time in the
        local timezone.

        By default it's formatted as a ISO8601-like string (ISO8601 date and
        ISO8601 time separated by a space). It can be customized using the
        C{timeFormat} attribute, which will be used as input for the underlying
        C{time.strftime} call.

        @type when: C{int}
        @param when: POSIX (ie, UTC) timestamp for which to find the offset.

        @rtype: C{str}
        i<iRt+s%%d-%02d-%02d %02d:%02d:%02d%s%02d%02dN(t
timeFormatR:RPtstrftimet	localtimeR{RRutabstinttyeartmonthtdaythourtminutetsecond(RERyttzOffsetttzHourttzMinttzSign((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt
formatTimes	cC st|}|dkrdS|j|d}i|dd6|jddd6}td|}tj|j|d|tj|jdS(NRPRs
s
	Rhs[%(system)s] %(text)s
Rj(	RpR:RtreplaceRiRtuntilConcludesRrRs(RERRhttimeStrRgtmsgStr((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytemits$cC st|jdS(s-
        Start observing log events.
        N(RLR(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytstartscC st|jdS(s,
        Stop observing log events.
        N(RNR(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytstopsN(RRR	R:R}RHR{RRRR(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRqs					tPythonLoggingObservercB s5eZdZddZdZdZdZRS(sL
    Output twisted messages to Python standard library L{logging} module.

    WARNING: specific logging configurations (example: network) can lead to
    a blocking system. Nothing is done here to prevent that, so be sure to not
    use this: code within Twisted, such as twisted.web, assumes that logging
    does not block.
    ttwistedcC stj||_dS(si
        @param loggerName: identifier used for getting logger.
        @type loggerName: C{str}
        N(tloggingt	getLoggerR(REt
loggerName((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRHscC skd|kr|d}n|dr/tj}n	tj}t|}|dkrTdS|jj||dS(s%
        Receive a twisted log entry, format it and bridge it to python.

        By default the logging level used is info; log.err produces error
        level, and you can customize the level by using the C{logLevel} key::

        >>> log.msg('debugging', logLevel=logging.DEBUG)

        tlogLevelR
N(RtERRORtINFORpR:Rtlog(RERtlevelRh((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs


	cC st|jdS(s-
        Start observing log events.
        N(RLR(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRscC st|jdS(s,
        Stop observing log events.
        N(RNR(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs(RRR	RHRRR(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs
		tStdioOnnaStickcB seZdZdZdZdZdZdddZdZ	dZ
dZdZeZ
eZeZeZd	Zd
ZRS(sP
    Class that pretends to be stdout/err, and turns writes into log messages.

    @ivar isError: boolean indicating whether this is stderr, in which cases
                   log messages will be logged as errors.

    @ivar encoding: unicode encoding used to encode any unicode strings
                    written to this object.
    itwbs
<stdio (log)>cC s:||_|dkr$tj}n||_d|_dS(Nt(R
R:R_tgetdefaultencodingtencodingtbuf(RER
R((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRH3s
		cC sdS(N((RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytclose:scC sdS(Ni((RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytfileno=scC sdS(N((RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs@scC stddS(Nscan't read from the log!(tIOError(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytreadCscC st|tr$|j|j}n|j|jd}|d|_|dd!}x'|D]}t|ddd|jq[WdS(Ns
iitprintediR
(R<tunicodetencodeRRtsplitR=R
(REtdatatdtmessagesRO((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRrKs


cC sRxK|D]C}t|tr1|j|j}nt|ddd|jqWdS(NRiR
(R<RRRR=R
(REtlinesRc((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt
writelinesTs
N(RRR	tclosedt	softspacetmodetnameR:RHRRRsRtreadlinet	readlinestseekttellRrR(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyR#s 							cO s6t|trdSt|}t|j|||S(s
    Initialize logging to a specified file.

    @return: A L{FileLogObserver} if a new observer is added, None otherwise.
    N(R<RRqtstartLoggingWithObserverR(RbtaRtflo((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytstartLoggingas
icC sgtstjatt_ntr4tjdant|td|rctt	_
tt	_ndS(s
    Initialize logging to a specified observer. If setStdout is true
    (defaults to yes), also redirect sys.stdout and sys.stderr
    to the specified file.
    sLog opened.N(
RaR"RdtdefaultObserverRR:RLR=tlogfileR_tstdouttlogerrtstderr(RYt	setStdout((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRos	
	

	tNullFilecB s2eZdZdZdZdZdZRS(icC sdS(N((RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRscC sdS(N((REtbytes((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRrscC sdS(N((RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRsscC sdS(N((RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs(RRRRRrRsR(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs
			cC s
tadS(s
    Throw away all logs.
    N(RR(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pytdiscardLogssRtDefaultObservercB s2eZdZejZdZdZdZRS(s
    Default observer.

    Will ignore all non-error messages and send error messages to sys.stderr.
    Will be removed when startLogging() is called for the first time.
    cC s|drd|kr@|jdp(dd|dj}n0djg|dD]}t|^qQd}|jj||jjndS(NR
R8R9sUnhandled Errors
RjRO(RRkRltstrRRrRs(RERRhtm((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt_emits
*0cC st|jdS(N(RLR(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRscC st|jdS(N(RNR(RE((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs(RRR	R_RRRR(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyRs
			((((((((>R	t
__future__RR_RPR"RRtzope.interfaceRttwisted.pythonRRRRR
t
setDefaultRRR%R*R3R&R)R'R2R0R7R6R:RtdeferrRDRFttheLogPublishert	NameErrorRLRNR=RdRiRpRqtobjectRRRaRRRRRtgetattrRRRRt
threadableR8tsynchronizeRR(((s6/usr/lib/python2.7/dist-packages/twisted/python/log.pyt<module>s~
	
									+
m
				
		!S38

			
"