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


[XMc@sadZddlmZddlmZddlmZmZddlm	Z	ddl
mZddlm
Z
mZddlZdd	lmZddlZddlZddlZddlZd
ddYZdefd
YZdddddedZdZidd6ZdejfdYZdddYZdej fdYZ dS(sDL{twisted.manhole} L{PB<twisted.spread.pb>} service implementation.
i(t	copyright(tpb(tlogtfailure(tportal(tservice(t
implementst	InterfaceN(tStringIOt	FakeStdIOcBs,eZdZdZdZdZRS(cCs||_||_dS(N(ttypetlist(tselfttype_R((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyt__init__s	cCsFtjd|jtjt|f|jj|j|fdS(Ns%s: %s(RtmsgR
tstringtstriptstrRtappend(Rttext((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytwrite"s)cCsdS(N((R((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytflush&sc	Cs|js
dS|j}g}|d}d}xtdt|jD]}||\}}||krmqEqE||dkr|j||n>td|||!}tj|d}|j||f|}|}qEWdS(sConcatenate adjacent messages of same type into one.

        Greatly cuts down on the number of elements, increasing
        network transport friendliness considerably.
        NiicSs|dS(Ni((tl((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyt<lambda>>st(RtxrangetlenRtmapRtjoin(	Rtinlisttoutlistt	last_typetblock_begintitmtypetmessagetmessages((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytconsolidate)s$		
	(t__name__t
__module__RRRR&(((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR	s			tIManholeClientcBs#eZdZdZdZRS(cCsdS(sOTakes a list of (type, message) pairs to display.

        Types include:
            - "stdout" -- string sent to sys.stdout

            - "stderr" -- string sent to sys.stderr

            - "result" -- string repr of the resulting value
                 of the expression

            - "exception" -- a L{failure.Failure}
        N((tlist_of_messages((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytconsoleGscCsdS(s&Receives an explorer.Explorer
        N((txplorer((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytreceiveExplorerUscCsdS(scList what manholey things I am capable of doing.

        i.e. C{"Explorer"}, C{"Failure"}
        N((((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytlistCapabilitiesYs(R'R(R+R-R.(((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR)Fs		cCsg}td|}	td|}
td|}d}d}
|dkrZt|}n|dkrod}n|dkri}n|dkr|}n|dkrt|rtdnytj}tj}|	t_|
t_zrt|rt|||}
nMyt	||d}Wnt	||d}nX|rYt
|||}
nWd|t_|t_XWnMtj\}}}tj
|||}~|jtj||nX|r|	j||n|
S(	sRun this, directing all output to the specified console.

    If command is callable, it will be called with the args and keywords
    provided.  Otherwise, command will be compiled and eval'd.
    (Wouldn't you like a macro?)

    Returns the command's return value.

    The console is called with a list of (type, message) pairs for
    display, see L{IManholeClient.console}.
    tstdouttstderrt	exceptions,Need a namespace to evaluate the command in.tevaltsingleN((R	tNoneRtcallablet
ValueErrortsysR/R0tapplytcompileR2texc_infoRtFailureRRtfailure2CopyableR&(tcommandR+tglobalNStlocalNStfilenametargstkwtunsafeTracebackstoutputtfakeouttfakeerrterrfiletcodetvaltoutterrteTypeteValttbtfail((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytrunInConsole_sR
								

c	Csddl}g}xJ|jD]?}|j|d|d|d|j|d|dfqWi|d6tj|j|jd6S(sPre-Failure manhole representation of exceptions.

    For compatibility with manhole clients without the "Failure"
    capability.

    A dictionary with two members:
        - 'traceback' -- traceback.extract_tb output; a list of tuples
             (filename, line number, function name, text) suitable for
             feeding to traceback.format_list.

        - 'exception' -- a list of one or more strings, each
             ending in a newline. (traceback.format_exception_only output)
    iNiiit	tracebackR1(t	linecachetframesRtgetlineRQtformat_exception_onlyR
tvalue(RORRRNtf((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyt_failureOldStyles=tSettExplorertPerspectivecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZRS(icCs4i|d6|d6dd6|_i|_||_dS(NRtavatart_(R4tlocalNamespacetclientsR(RR((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyRs
	cCs>|jj}i|d<|djdr:|dd=n|S(NR_R^t__builtins__(t__dict__tcopythas_key(Rtstate((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyt__getstate__s

cCs||j|<djtt|jjjd}|jjit	|dt|d6|d6t
jd6}|jdd|fgt
|_|jd	j|j|jd
|fd|fdS(
sHA client has attached -- welcome them and add them to the list.
        t:itnametyouthosttlongversionR+R/R.tcallbackArgsterrbackArgsN(R_RRRtbrokert	transporttgetHostRtwelcomeMessagetgetattrRRjt
callRemotet_defaultCapabilitiestcapabilitiestaddCallbackst_cbClientCapablet_ebClientCapable(RtclienttidentityRiR((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytattacheds
(	cCs&y|j|=Wntk
r!nXdS(N(R_tKeyError(RRxRy((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytdetacheds
cOsCt||j|jj|jt|jd|d|d|jjS(s:Convience method to "runInConsole with my stuff".
        RARBRC(RPR+Rt	namespaceR^RRC(RR=RARB((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyRPs	cCs|jj}|}d}x|D]}y|jjds|dkr|}xttt|D]]}||ddkrct||dtj	rc||dt
||df||<qcqcWn|jd|n|jd|Wq"tj
k
r|j|dq"Xq"WdS(s/Pass a message to my clients' console.
        R;iR1iR+N(R_tkeysR4RtRcRRt
isinstanceRR;RXRrRt
ProtocolErrorR|(RR$R_torigMessaget
compatMessageRxR"((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR+s"
%cCs_|jj}xI|D]A}y|jd|Wqtjk
rV|j|dqXqWdS(s+Pass an Explorer on to my clients.
        R-N(R_R~RrRRR|R4(Rt
objectLinkR_Rx((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR-s
cCs$|jdd||ffg|S(NtresultsDeferred #%s Result: %r
(R+(RRItdnum((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyt	_cbResults cCs*tjdt||f||_dS(Nsclient %x has %s(RRtidRt(RRtRx((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyRv"scCs%|jttjd|fdS(Ns5Couldn't get capabilities from %s, assuming defaults.(ttraptAttributeErrorRR(RtreasonRx((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyRw&s
	cCstjd||j|}|d
k	r||jd<ddlm}t||r|jd7_|j	dd|jfg|j
|j|jq|j	dt|dfgntjd	d
S(sEvaluate the given expression, with output to the console.

        The result is stored in the local variable '_', and its repr()
        string is sent to the console as a "result" message.
        s>>> %sR]i(tDeferrediRsWaiting for Deferred #%s...
s
s<<<N(
RRRPR4R^ttwisted.internet.deferRRtlastDeferredR+taddBothRtrepr(RtexprRIR((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytperspective_do-s
#cCs>|j|}|r:tjj||}|j|ndS(sBrowse the object obtained by evaluating the identifier.

        The resulting ObjectLink is passed back through the client's
        receiveBrowserObject method.
        N(RPtexplorertexplorerPooltgetExplorerR-(Rt
identifiertobjecttexpl((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytperspective_exploreAscCsit|j|}|re|j|jj||}|j||j|jj|||jndS(sWatch the object obtained by evaluating the identifier.

        Whenever I think this object might have changed, I will pass
        an ObjectLink of it back to the client's receiveBrowserObject
        method.
        N(tNotImplementedErrorRPtbrowsertbrowseObjectR-twatchObject(RRRtoLink((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pytperspective_watchLs
(R'R(RRReRzR|RPR+R-RRvRwRRR(((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR[s													tRealmcBs'eZeejdZdZRS(cCs||_i|_dS(N(Rt_cache(RR((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyRds	cstj|krtdn|jkr=|jnt|jjfd}tj|fS(Nsno interfacecsjdS(N(R|((tptavatarIdtmind(s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR|ps(RtIPerspectiveRRR[RRz(RRRt
interfacesR|((RRRs;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyt
requestAvatarhs(R'R(RRtIRealmRR(((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR`s
	tServicecBs&eZdZeddZdZRS(sB
Hello %(you)s, welcome to Manhole on %(host)s.
%(longversion)s.

cCsJ||_idt|fd6td6|_|rF|jj|ndS(Ns
__manhole%x__R'R7(RCRR7R}tupdate(RRCR}((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyR|s	
cCsF|jj}|dj}||d<|jdrB|d=n|S(sAThis returns the persistent state of this shell factory.
        R}R`(RaRbRc(Rtdicttns((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyRes

N(R'R(RptFalseR4RRe(((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyRus	(((!t__doc__ttwistedRttwisted.spreadRttwisted.pythonRRttwisted.credRttwisted.applicationRtzope.interfaceRRRt	cStringIORRR7RQttypesR	R)R4RRPRXRstAvatarR[RR(((s;/usr/lib/python2.7/dist-packages/twisted/manhole/service.pyt<module>s,)@