Your IP : 172.28.240.42


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


ΔMc@s~dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddkZ
e
ZdejfdYZeZ
dejfd	YZd
efdYZdefd
YZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZieej6eej6eej6eej6eej6eej6eej 6eej!6eej"6eej#6eej$6eej%6eej&6eej'6eej(6Z)dej*fdYZ+d d&d!YZ,d"d'd#YZ-d$d(d%YZ.dS()sSupport for python object introspection and exploration.

Note that Explorers, what with their list of attributes, are much like
manhole.coil.Configurables.  Someone should investigate this further. (TODO)

Also TODO: Determine how much code in here (particularly the function
signature stuff) can be replaced with functions available in the
L{inspect} module available in Python 2.1.
iN(tpb(treflectitPoolcBseZdZRS(cCs{t|}|jj|r)|j|Stjt|t}tj|i}||j|<|j	||||SdS(N(
tidtdatathas_keyt	typeTabletgetttypetExplorerGenericttypestInstanceTypet__init__(tselftobjectt
identifiertoidtklasste((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytgetExplorers
(t__name__t
__module__R(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRstExplorercBsJeZddgZgZdgZdZdZdZdZ	dZ
RS(RRtget_refcountcCs||_||_t||_g|_tj|jd|jg|_tj|jd|jg|_tj|jd|jdS(Nt
propertiestattributeGroupst	accessors(	RRRRRtaccumulateClassListt	__class__RR(R
RR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR5s			
	
	cCsdddg}|j|j|j|ji}x!|D]}t||||<q<Wtj|||d<|jj|d<|S(NRRRtviewt
explorerClass(textendRRtgetattrRt	ViewPointRR(R
tperspectivetalltstatetkey((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytgetStateToCopyForFs
cCs
tj|S(N(tsystgetrefcount(R
R"((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytview_get_refcountSsN(RRRRRtNoneRRRR&R)(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR-s			
R	cBs eZdddgZdZRS(tstrtreprttypenamecCsGtj|||t||_t||_t|j|_dS(N(RRR+R,RRR-(R
RR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRYs(RRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR	VstExplorerImmutablecBseZdgZdZRS(tvaluecCs tj|||||_dS(N(RRR/(R
RR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRcs(RRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR.`s	tExplorerSequencecBs>eZdgZdgZdgZdZdZdZRS(tlentelementstget_elementscCs8tj|||||_t||_g|_dS(N(RRtseqR1R2(R
R4R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRms	cCsit|j|_g}xJt|jD]9}d|j|f}|jtj|j||q(W|S(Ns%s[%s](R1R4txrangeRtappendtexplorerPoolR(R
tltiR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR3us$cCs
|jS(N(R3(R
R"((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytview_get_elementss(RRRRRRR3R:(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR0hs					tExplorerMappingcBsJeZdgZdgZddgZdZdZdZdZRS(R1tkeystget_keystget_itemcCs8tj|||||_t||_g|_dS(N(RRtdctR1R<(R
R?R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs	cCsr|jj}t||_g}xGt|jD]6}d|j|f}|jtj|||q4W|S(Ns
%s.keys()[%s](R?R<R1R5RR6R7R(R
R<R8R9R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR=s!cCs
|jS(N(R=(R
R"((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt
view_get_keysscCs]t|tjkr!|j}n|j|}d|jt|f}tj||}|S(Ns%s[%s](	RR
RRR?RR,R7R(R
R"R%titemR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt
view_get_items
(	RRRRRRR=R@RB(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR;s						tExplorerBuiltincBs&eZdZdddgZdZRS(s
    @ivar name: the name the function was defined as
    @ivar doc: function's docstring, or C{None} if unavailable
    @ivar self: if not C{None}, the function is a method of this object.
    tdoctnameR
cCs;tj||||j|_|j|_|j|_dS(N(RRt__doc__RDRREt__self__R
(R
tfunctionR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs(RRRFRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRCstExplorerInstancecBs,eZdZdgZddgZdZRS(sq
    Attribute groups:
        - B{methods} -- dictionary of methods
        - B{data} -- dictionary of data members

    Note these are only the *instance* methods and members --
    if you want the class methods, you'll have to look up the class.

    TODO: Detail levels (me, me & class, me & class ancestory)

    @ivar klass: the class this is an instance of.
    RtmethodsRc	Cstj|||i}i}xt|D]}|ddkrHq,ntj||gd}t||}t|}|tjkrt	j
||||<q,t	j
||||<q,Wt	j
|j|jd|_
||_||_dS(Nit_t.s
.__class__(RRtdirtstringtjoinR RR
t
MethodTypeR7RRRRRRJ(	R
tinstanceRtmembersRJR9tmIdentifiertmembertmType((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs"
	(RRRFRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRIs	t
ExplorerClasscBs5eZdZddddgZddgZdZRS(s6
    @ivar name: the name the class was defined with
    @ivar doc: the class's docstring
    @ivar bases: a list of this class's base classes.
    @ivar module: the module the class is defined in

    Attribute groups:
        - B{methods} -- class methods
        - B{data} -- other members of the class
    RERDtbasestmoduleRJRc	Cs@tj||||s%|j}ni}i}xt|D]}|ddkrf|dkrfq>ntj||gd}t||}t|}|tj	krt
j||||<q>t
j||||<q>W|j|_t
j||_||_||_t
j|j|d|_t|dd|_dS(NiRKRRLs
.__bases__R(RRRRMRNROR RR
RPR7RREtinspecttgetdocRDRRJt	__bases__RWR*RX(	R
ttheClassRRRRJR9RSRTRU((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs*		(RRRFRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRVs
tExplorerFunctioncBs&eZdddddgZdZRS(RERDtfiletlinet	signaturecCsctj||||j}|j}|jd@o5d}|jd@oHd}|||}t|j| }|jrd}	xjt|t	|j|D]I}
|j|	}t
j|d||	f}|j|
||	d}	qWn|r|j
|dn|r |j|d|n|j|_||_tj||_|j|_|j|_dS(Niiiis%s.func_defaults[%d](RRt	func_codetco_argcounttco_flagst	Signaturetco_varnamest
func_defaultsR5R1R7Rtset_defaulttset_keywordtset_varlistRRER`RYRZRDtco_filenameR^tco_firstlinenoR_(R
RHRtcodetargcountt	takesListt
takesKeywordstnR`ti_dR9tdefault((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs2			

	(RRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR]stExplorerMethodcBseZddgZdZRS(R
RcCs|j}t|tjkr-|jj}ntj|||t||_tj	|j
|d|_tj	|j|d|_
|jr|jjndS(Ns	.im_classs.im_self(tim_funcRR
Rt__call__R]RRR7Rtim_classRtim_selfR
R`tdiscardSelf(R
tmethodRRH((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRDs		(RRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs=stExplorerModulecBs5eZdZdddgZdddgZdZRS(s
    @ivar name: the name the module was defined as
    @ivar doc: documentation string for the module
    @ivar file: the file the module is defined in

    Attribute groups:
        - B{classes} -- the public classes provided by the module
        - B{functions} -- the public functions provided by the module
        - B{data} -- the public data members provided by the module

    ("Public" is taken to be "anything that doesn't start with _")
    RERDR^tclassest	functionsRc	CsGtj|||i}i}i}x|jjD]\}}|ddkrWq5nd||f}t|tjkrtj||||<q5t|tj	krtj||||<q5t|tj
krq5tj||||<q5W|j|_t
j||_t|dd|_||_||_||_dS(NiRKs%s.%st__file__(RRt__dict__titemsRR
t	ClassTypeR7RtFunctionTypet
ModuleTypeRRERYRZRDR R*R^R{R|R(	R
RXRR|R{RR%R/RS((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRfs.				(RRRFRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRzVsRdcBseZdZdZdZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZRS(sI represent the signature of a callable.

    Signatures are immutable, so don't expect my contents to change once
    they've been set.
    iiicCs9||_dgt||_dgt||_dS(N(RER*R1Rrtflavour(R
targNames((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs	cCs|j|S(N(RE(R
targ((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytget_namescCsY|tjkr$|jj|}n|j||jkrKt|j|fStdfSdS(N(
R
t
StringTypeREtindexRt_HAS_DEFAULTtTrueRrtFalseR*(R
R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytget_defaults
cCsE|tjkr$|jj|}n|j|j|<||j|<dS(N(R
RRERRRRr(R
RR/((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRgscCs8|tjkr$|jj|}n|j|j|<dS(N(R
RRERt	_VAR_LISTR(R
R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRiscCs8|tjkr$|jj|}n|j|j|<dS(N(R
RRERt
_KEYWORD_DICTR(R
R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRhscCs8|tjkr$|jj|}n|j||jkS(N(R
RRERRR(R
R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt
is_varlistscCs8|tjkr$|jj|}n|j||jkS(N(R
RRERRR(R
R((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt
is_keywordscCs4|jd|_|jjd|jjddS(sKInvoke me to discard the first argument if this is a bound method.
        iiN(RERrtpopR(R
((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRxscCs4it|jd6t|jd6t|jd6S(NRERRr(ttupleRERRr(R
((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytgetStateToCopyscCs
t|jS(N(R1RE(R
((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt__len__scCsg}xtt|D]}|j|}|j|\}}|r\d||f}nD|j|r{d|f}n%|j|rd|f}n|}|j|qWtj|dS(Ns%s=%ss*%ss**%ss, (	R5R1RRRRR6RNRO(R
targlistRREt
hasDefaultRrta((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt__str__sN(RRRFR*t_FLAVOURLESSRRRRRRRgRiRhRRRxRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRds"									
		tCRUFT_WatchyThingiecBseZdZdZRS(cCs+t||j|j}|j|||S(sWatch the object returned by evaluating the identifier.

        Whenever I think the object might have changed, I'll send an
        ObjectLink of it to the callback.

        WARNING: This calls eval() on its argument!
        (tevaltglobalNamespacetlocalNamespacetwatchObject(R
RtcallbackR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pytwatchIdentifierscCs9t|tjk	r!tdni}tj|j|dx!|jjD]}d||<qMW|j}i}tj	d|jj
t|ft|jf|}tj
|||dd||d<||_x]|D]U}	t||	}
t|
tj
kr|
jdk	rt|}|j|	qqWdS(sWatch the given object.

        Whenever I think the object might have changed, I'll send an
        ObjectLink of it to the callback.

        The identifier argument is used to generate identifiers for
        objects which are members of this one.
        s+Sorry, can only place a watch on Instances.tisWatching%s%XcSs||j||S(N(tbrowseObject(tslfR9tbtcb((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt<lambda>.st_watchEmitChangedN(RR
Rt	TypeErrorRtaddMethodNamesToDictRR~R<RRRt_MonkeysSetattrMixinRPR*R Rwt_WatchMonkeytinstall(R
RRRR?tkRRtclazzNStclazzREtmtmonkey((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs,				
(RRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs	
RcBs8eZdZdZdZdZdZdZRS(sI hang on a method and tell you what I see.

    TODO: Aya!  Now I just do browseObject all the time, but I could
    tell you what got called with what when and returning what.
    cCs
||_dS(s7Make a monkey to hang on this instance object.
        N(RQ(R
RQ((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRRscCs_t|j|d}||k	r[tj||j|jj|jj|<||f|_ndS(s?Install myself on my instance in place of this method.
        N(R RQR*R
RPRR~t	oldMethod(R
tmethodIdentifierR((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRWs
"cCse|jdkrdS|jddkr@t|j|jdn!t|j|jd|jddS(s]Remove myself from this instance and restore the original method.

        (I hope.)
        Nii(RR*tdelattrRQtsetattr(R
((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt	uninstallcs
cOs=|jdr)t|jd||}nd}|j|S(s@Pretend to be the method I replaced, and ring the bell.
        iN(RtapplyR*R(R
RQRtkwtrval((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRurs


N(	RRRFR*RRRRRu(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRJs			RcBseZdZdZRS(sDA mix-in class providing __setattr__ for objects being watched.
    cCsTt|jjddr9|jjdj|||n
||j|<|jdS(s-Set the attribute and ring the bell.
        it__setattr__N(thasattrRR[RR~R(R
Rtv((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRs 
(RRRFR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR~s((((/RFRYRNR'R
tUserDictttwisted.spreadRttwisted.pythonRRRRR7t	CacheableRR	R.R0R;RCRIRVR]RsRzRRRPRRtBuiltinFunctionTypetListTypet	TupleTypetDictTypeRtNoneTypetIntTypet	FloatTypetLongTypetComplexTypeRtCopyableRdRRR(((s</usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt<module>sL0	)
*()/-














eQ4