V Qc@sdZddlZddlZdddYZdddYZdddYZd efd YZed didd 6Zd Z e dkre ndS(s?Tracing metaclass. XXX This is very much a work in progress. iNtTraceMetaClasscBs>eZdZdZdZdZdZdZdZ RS(sUMetaclass for tracing. Classes defined using this metaclass have an automatic tracing feature -- by setting the __trace_output__ instance (or class) variable to a file object, trace messages about all calls are written to the file. The trace formatting can be changed by defining a suitable __trace_call__ method. icCs(||_||_||_d|_dS(Ni(t__name__t __bases__t_TraceMetaClass__dictt_TraceMetaClass__inited(tselftnametbasestdict((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyt__init__s   cCsiy|j|SWnStk rdx6|jD]+}y|j|SWq)tk rSq)Xq)Wt|nXdS(N(RtKeyErrorRt __getattr__tAttributeError(RRtbase((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR s  cCs*|js||j|4s(tTracingInstancet __meta_init__R R tapply(Rtargstkwtinsttinit((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyt__call__.s    N( Rt __module__t__doc__RR R RRRt__trace_output__(((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR s    RcBs)eZdZdZdZdZRS(s9Helper class to represent an instance of a tracing class.cGs|j|d|dS(Ns (twrite(RtfptfmtR((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyt__trace_call__=scCs ||_dS(N(t_TracingInstance__class(Rtklass((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR@scCsy|jj|}Wntk r2t|nXt|tjkrL|S|jjd|}|j sv|dkrt|||St |||SdS(Nt.R!( R"R R ttypettypest FunctionTypeRRtNotTracingWrappertTracingWrapper(RRtrawtfullname((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR Cs  (RRRR!RR (((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR:s  R(cBseZdZdZRS(cCs||_||_||_dS(N(RtfuncR(RRR,R((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR Ss  cOst|j|jf||S(N(RR,R(RRR((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyRWs(RRR R(((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR(Rs R)cBseZdZRS(cOs|jj|jjd|j|j||y#t|j|jf||}WnMtj\}}}|jj|jjd|j|||||n'X|jj|jjd|j||SdS(Ns#calling %s, inst=%s, args=%s, kw=%ss'returning from %s with exception %s: %ssreturning from %s with value %s(RR!RRRR,tsystexc_info(RRRtrvtttvttb((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR[s# (RRR(((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR)ZstTracedRcCsdtfdYadtfdYatd}|GH|jGH|jdGH|jdGH|jdGH|jd GH|jd GH|jGHtjGHtjGHtjGHtjGHt}|GH|jdGH|jdGH|jGHdS( NtCcBs/eZddZdZdZejZRS(icSs ||_dS(N(tx(RR5((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR sscSs ||_dS(N(R5(RR5((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pytm1tscSs |j|S(N(R5(Rty((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pytm2us(RRR R6R8R-tstdoutR(((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR4rs   tDcBseZdZdZRS(cSsd|fGHtj||S(NsD.m2(%r)(R4R8(RR7((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR8xs N(RRR8RR(((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyR:ws iidi i!ii(R3R4R:R5R6R8R (R5R7((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyt_testps(  t__main__((((( RR&R-RRR(R)RR3R;R(((s./usr/lib64/python2.7/Demo/metaclasses/Trace.pyts1