m -Ec@sdZdklZdkZdkZdkZdkZdkZdkZdk Z dk Z dk Z dk Z e e idZy dkZWnej odkZnXdfdYZde fdYZdefd YZd fd YZeZd efd YZdfdYZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%e%Z&dZ'dZ(dZ)dZ*dZ+d Z,d!Z-dd"Z/dd#Z0d$Z1dd%Z2dd&Z3ddd'Z4dd(Z5dd)Z6d*Z7d+Z8d,Z9d-Z:d.Z;e8dddddd/Z<d0Z=d1Z>dS(2st Standardized versions of various cool and/or strange things that you can do with Python's reflection capabilities. (s nested_scopesNttSettablecBs tZdZdZdZRS(sQ A mixin class for syntactic sugar. Lets you assign attributes by calling with keyword arguments; for example, C{x(a=b,c=d,y=z)} is the same as C{x.a=b;x.c=d;x.y=z}. The most useful place for this is where you don't want to name a variable, but you do want to set some attributes; for example, C{X()(y=z,a=b)}. cKs||dS(N(tselftkw(RR((tn/home/radix/Projects/Twisted/branches/releases/twisted-core-2.5.x-2329-2/Twisted.exp/twisted/python/reflect.pyt__init__+scKs1x*|iD]\}}t|||q W|S(N(RtitemstkeytvaltsetattrR(RRRR((Rt__call__.s (t__name__t __module__t__doc__RR (((RR#s  t AccessorTypecBstZdZdZRS(s;Metaclass that generates properties automatically. This is for Python 2.2 and up. Using this metaclass for your class will give you explicit accessor methods; a method called set_foo, will automatically create a property 'foo' that uses set_foo as a setter method. Same for get_foo and del_foo. Note that this will only work on methods that are present on class creation. If you add methods after the class is defined they will not automatically become properties. Likewise, class attributes will only be used if they are present upon class creation, and no getter function was set - if a getter is present, the class attribute will be ignored. This is a 2.2-only alternative to the Accessor mixin - just set in your class definition:: __metaclass__ = AccessorType c Csuti||||h}dddg}xu|iD]g} t || } xOt dD]A}| i||o'| |i| ddddg|RCRAR?((RR,s:           (R R R R,(((RR8s t QueueMethodcBs tZdZdZdZRS(s- I represent a method that doesn't exist yet.cCs||_||_dS(N(RRtcalls(RRRE((RRs cGs|ii|i|fdS(N(RREtappendRtargs(RRG((RR s(R R R RR (((RRDs  c Cstidtdd|i}|i}|i}|i | }|i }g} | id||f|o|t|}| id|| id|| | idxEt||D]/}||}| id||||fqWn| S( sA this is more documentation for myself than useful code. sH[v2.5] Use inspect.getargspec instead of twisted.python.reflect.funcinfot stacklevelis$The function %s accepts %s argumentssIt requires %s argumentssThe arguments required are: %ssadditional arguments are:s%s which has a default ofN(twarningstwarntDeprecationWarningtfunctiont func_codetcodet func_nameRt co_argcounttargct co_varnamestargvt func_defaultstdefaultstoutRFtlentrequiredR$R%tj( RLRNRR%RXRSRYRURQRV((Rtfuncinfos*         'iiicCsWtti||id|i}t||j otd||fn|S(Nt.sCouldn't find %s as %s.(tstrtpicklet whichmoduletfuncR tqualNamet namedObjectt Exception(R_R`((Rt fullFuncNames&cCs|id|iS(s#Return full import path of a class.R[N(tclazzR R (Rd((RR3"scCs]t|tijp tdt|i}t||i d}|djo|Sn|S(Nsmust be a class...( RRdttypest ClassTypetAssertionErrort namedModuleR tmoduleR"R R(t currclass(RdRiRj((Rt getcurrent&s   cCs)t|do |iSn t|SdS(stReturn the class or type of object 'obj'. Returns sensible result for oldstyle and newstyle instances and types.R1N(R)R<R1R(R<((RtgetClass.s cCst|tijpt|tijot||Sn|i}t |}t |}t ||o&||jot Sq||_t SntSdS(N(RtinstRet InstanceTypeRdRft isinstanceR1tclRktcl2t issubclasstWAStIStISNT(RmRdRpRq((Rtisinst9s,     cCsIt|}|idd}|}x|D]}t||}q,W|S(sReturn a module given its name.R[iN(t __import__RttopLeveltsplittpackagestmtpR"(RR|R{RxRz((RRhIs cCs?ti|d}tti|d d}t||dS(s,Get a fully named module-global object. R[iN(tstringRyRt classSplitRhtjoinRiR"(RR~Ri((RRaSscCs|id}d}|}x|pydi|}t|}Wqt j o}t i }t t i|ddjo@yt i|=Wntj onX|d|d|dn|iqXqW|}x!|dD]}t||}qW|S(sKGet a fully named package, module, module-global object, or attribute. R[iiiN(RRytnamesR(ttopLevelPackaget moduleNamesRt trialnameRwt ImportErrortsystexc_infoRWt tracebackt extract_tbtmodulestKeyErrortpopR<tnR"(RRR<RRRRR((RtnamedAny\s.   cCs:tt|i|i}ttt|i|_|S(N( R"RhRdR R ttupletmapt_reclasst __bases__(Rd((RR{sc Js |idp||dtexecstwisted.python.reflect.macrosiitmacro_R[N(t identifiersRRtsourcetfilenamet codeplacetcompileRNRRtsmttprmtnewRitmacrostcountR\t macronamettprmmtmymodR Rtdict( RRRRRNRRRRRRRR((Rtmacros,        cCs#y |iSWnt|SnXdS(N(RBR1R(RB((Rt_determineClasss cCsKt|}y |iSWn-yt|SWqGdt|SqGXnXdS(Ns(RRBtcR R\tid(RBR((Rt_determineClassNames  cCssyt|SWn^ti}tid|t|}|i}t |}d|||f}|SnXdS(ssafe_repr(anything) -> string Returns a string representation of an object, or a string containing a traceback, if that object's __repr__ raised an exception. tfiles&<%s instance at %s with repr error %s>N( treprtotStringIOtioRt print_stackRtwhatitgetvaluetswronRtgwithtyou(RRRRRR((Rt safe_reprs    cCscyt|SWnNdititi}t|}t |}d|||fSnXdS(ssafe_str(anything) -> string Returns a string representation of an object, or a string containing a traceback, if that object's __str__ raised an exception. s s%<%s instance at %s with str error %s>N( R\RRRtformat_exceptionRRtstrExcRtclsNameRtobId(RRRR((Rtsafe_strs  cCsg}t||||S(sallYourBase(classObj, baseClass=None) -> list of all base classes that are subclasses of baseClass, unless it is None, in which case all bases will be added. N(tltaccumulateBasestclassObjt baseClass(RRR((Rt allYourBasescCsVxO|iD]D}|djpt||o|i|nt|||q WdS(N( RRtbaseRR(RrRRFR(RRRR((RRs  cCs h}t||||iS(sAA list of method names with a given prefix in a given class. N(tdcttaddMethodNamesToDictRtprefixR (RRR((RtprefixedMethodNamesscCsx$|iD]}t||||q W|djp||ijo|xy|ii D]d\}}|t |}t|tijo2|t | |jot |od|| dict this goes through 'classObj' (and its bases) and puts method names starting with 'prefix' in 'dict' with a value of 1. if baseClass isn't None, methods will only be added if classObj is-a baseClass If the class in question has the methods 'prefix_methodname' and 'prefix_methodname2', the resulting dict should look something like: {"methodname": 1, "methodname2": 1}. iN(RRRRRRRR(RRRtmethodRWtoptNameRRet FunctionType(RRRRRRRR((RRs   :cCs h}t||||iS(s?A list of methods with a given prefix on a given instance. N(RtaccumulateMethodsR<Rtvalues(R<RR((RtprefixedMethodsscCs|p |i}nx$|iD]}t||||qWx~|ii D]m\}}|t |}t|tijo;|t | |jo$t |ot||||