%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python2.7/idlelib/
Upload File :
Create Path :
Current File : //usr/local/lib/python2.7/idlelib/rpc.pyo


Pac@sdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZdZdZeje
jeeddZdZdejfd	YZiZe
j
d
Ze
j
d
ZdefdYZd
efdYZdZdefdYZdejefdYZdefdYZ defdYZ!dZ"dZ#defdYZ$dS(sRPC Implementation, originally written for the Python Idle IDE

For security reasons, GvR requested that Idle's Python execution server process
connect to the Idle process, which listens for the connection.  Since Idle has
only one client per server, this was not a limitation.

   +---------------------------------+ +-------------+
   | SocketServer.BaseRequestHandler | | SocketIO    |
   +---------------------------------+ +-------------+
                   ^                   | register()  |
                   |                   | unregister()|
                   |                   +-------------+
                   |                      ^  ^
                   |                      |  |
                   | + -------------------+  |
                   | |                       |
   +-------------------------+        +-----------------+
   | RPCHandler              |        | RPCClient       |
   | [attribute of RPCServer]|        |                 |
   +-------------------------+        +-----------------+

The RPCServer handler class is expected to provide register/unregister methods.
RPCHandler inherits the mix-in class SocketIO, which provides these methods.

See the Idle run.main() docstring for further information on how this was
accomplished in Idle.

iNcCstj|}|S(N(tmarshaltloads(tmstco((s'/usr/local/lib/python2.7/idlelib/rpc.pyt
unpickle_code-scCstj|}t|ffS(N(RtdumpsR(RR((s'/usr/local/lib/python2.7/idlelib/rpc.pytpickle_code2siis	127.0.0.1t	RPCServercBs8eZddZdZdZdZdZRS(cCs/|dkrt}ntjj|||dS(N(tNonet
RPCHandlertSocketServert	TCPServert__init__(tselftaddrthandlerclass((s'/usr/local/lib/python2.7/idlelib/rpc.pyRGs	cCsdS(s@Override TCPServer method, no bind() phase for connecting entityN((R
((s'/usr/local/lib/python2.7/idlelib/rpc.pytserver_bindLscCs|jj|jdS(sOverride TCPServer method, connect() instead of listen()

        Due to the reversed connection, self.server_address is actually the
        address of the Idle Client to which we are connecting.

        N(tsockettconnecttserver_address(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pytserver_activatePscCs|j|jfS(s:Override TCPServer method, return already connected socket(RR(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pytget_requestYscCsyWntk
rntj}|dddIJ|dIJ|dtjjIJ|dI|IJ|dIt|IJtjd||d	IJ|ddIJt	j
d
nXdS(sOverride TCPServer method

        Error message goes to __stderr__.  No error message if exiting
        normally or socket raised EOF.  Other exceptions not handled in
        server code will cause os._exit.

        s
t-i(sUnhandled server exception!s
Thread: %ssClient Address: s	Request: tfiles#
*** Unrecoverable, server exiting!iN(t
SystemExittsyst
__stderr__t	threadingt
currentThreadtgetNametreprt	tracebackt	print_exctost_exit(R
trequesttclient_addressterf((s'/usr/local/lib/python2.7/idlelib/rpc.pythandle_error]s
	

N(t__name__t
__module__RRRRRR&(((s'/usr/local/lib/python2.7/idlelib/rpc.pyREs
				itSocketIOcBseZdZdddZdZdZdZdZdZ	dZ
dZd	Zd
Z
dZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!RS(icCsdtj|_|dk	r'||_n||_|dkrEt}n||_i|_i|_	dS(N(
RRt
sockthreadRt	debuggingtsocktobjecttabletobjtablet	responsestcvars(R
R,R.R+((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs				cCs/|j}d|_|dk	r+|jndS(N(R,Rtclose(R
R,((s'/usr/local/lib/python2.7/idlelib/rpc.pyR1s		cCstjddS(s!override for specific exit actioniN(R!R"(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pytexithookscGsf|js
dS|jdttjj}x"|D]}|dt|}q7Wtj|IJdS(Nt (R+tlocationtstrRRRRR(R
targststa((s'/usr/local/lib/python2.7/idlelib/rpc.pytdebugs	#
cCs||j|<dS(N(R.(R
toidtobject((s'/usr/local/lib/python2.7/idlelib/rpc.pytregisterscCs&y|j|=Wntk
r!nXdS(N(R.tKeyError(R
R:((s'/usr/local/lib/python2.7/idlelib/rpc.pyt
unregisters
cCs|jd|y|\}\}}}}Wntk
r@dSX||jkradd|ffS|j|}|dkri}	t||	d|	fS|dkri}
t||
d|
fSt||sdd|ffSt||}y|d	kr5|||}t|tr+t	|}nd|fS|d
krat
j||||ffdSdd|fSWndt
k
rnQtjk
rn;d
}
tj|
|||fIJtjdtjdSXdS(Ns
localcall:tERRORsBad request formatsUnknown object id: %rt__methods__tOKt__attributes__sUnsupported method name: %rtCALLtQUEUEtQUEUEDsUnsupported message type: %ssU*** Internal Error: rpc.py:SocketIO.localcall()

 Object: %s 
 Method: %s 
 Args: %s
Rt	EXCEPTION(R?sBad request format(REN(RFN(R9t	TypeErrorR.t_getmethodst_getattributesthasattrtgetattrt
isinstancetRemoteObjectt	remotereft
request_queuetputRRRterrorRRRR (R
tseqR#thowR:t
methodnameR6tkwargstobjtmethodst
attributestmethodtrettmsg((s'/usr/local/lib/python2.7/idlelib/rpc.pyt	localcallsL







cCs8|jd|||j||||}|j|S(Nsremotecall:asynccall: (R9t	asynccalltasyncreturn(R
R:RTR6RURR((s'/usr/local/lib/python2.7/idlelib/rpc.pyt
remotecallscCs8|jd|||j||||}|j|S(Nsremotequeue:asyncqueue: (R9t
asyncqueueR^(R
R:RTR6RURR((s'/usr/local/lib/python2.7/idlelib/rpc.pytremotequeuescCsd||||ff}|j}tj|jkrUtj}||j|<n|jd||||||j||f|S(NRCs
asynccall:%d:(tnewseqRRR*t	ConditionR0R9t
putmessage(R
R:RTR6RUR#RRtcvar((s'/usr/local/lib/python2.7/idlelib/rpc.pyR]scCsd||||ff}|j}tj|jkrUtj}||j|<n|jd||||||j||f|S(NRDsasyncqueue:%d:(RbRRR*RcR0R9Rd(R
R:RTR6RUR#RRRe((s'/usr/local/lib/python2.7/idlelib/rpc.pyR`scCsG|jd||j|dd}|jd|||j|S(Ns#asyncreturn:%d:call getresponse(): twaitg?sasyncreturn:%d:response: (R9tgetresponsetdecoderesponse(R
RRtresponse((s'/usr/local/lib/python2.7/idlelib/rpc.pyR^scCs|\}}|dkr|S|dkr,dS|dkrI|jddS|dkrp|jd|jdS|dkr|jd|t|nt||fdS(	NRARERFsdecoderesponse: EXCEPTIONtEOFsdecoderesponse: EOFR?sdecoderesponse: Internal ERROR:(RR9tdecode_interrupthooktRuntimeErrortSystemError(R
RiRStwhat((s'/usr/local/lib/python2.7/idlelib/rpc.pyRhs 


cCs
tdS(tN(tEOFError(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pyRkscCs@y|jddddWntk
r;|jddSXdS(sListen on socket until I/O not ready or EOF

        pollresponse() will loop looking for seq number None, which
        never comes, and exit on EOFError.

        tmyseqRfg?smainloop:returnN(RgRRpR9(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pytmainloop
s


cCsU|j||}|dk	rQ|\}}|dkrQ||j|f}qQn|S(NRA(t_getresponseRt_proxify(R
RqRfRiRSRn((s'/usr/local/lib/python2.7/idlelib/rpc.pyRgscCsEt|trt||jSt|tjrAt|j|S|S(N(RLtRemoteProxytRPCProxyR:ttypestListTypetmapRt(R
RV((s'/usr/local/lib/python2.7/idlelib/rpc.pyRts
cCs|jd|tj|jkrQx|j||}|dk	r(|Sq(Wn}|j|}|jx||jkr|j	qkW|j|}|jd||f|j|=|j|=|j
|SdS(Ns_getresponse:myseq:s-_getresponse:%s: thread woke up: response: %s(R9RRR*tpollresponseRR0tacquireR/Rftrelease(R
RqRfRiRe((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs's"


	


cCs|jd|_}|S(Ni(tnextseq(R
RR((s'/usr/local/lib/python2.7/idlelib/rpc.pyRb=scCs|jd|dytj|}Wn0tjk
rZtjdIt|IJnXtjdt	||}xt	|dkry>t
j
g|jgg\}}}|jj|t
 }Wn ttfk
rtdnX||}qzWdS(Nsputmessage:%d:isCannot pickle:s<issocket no longer exists(R9tpickleRt
PicklingErrorRRRtstructtpacktlentselectR,tsendtBUFSIZEtAttributeErrorRGtIOError(R
tmessageR7trtwtxtn((s'/usr/local/lib/python2.7/idlelib/rpc.pyRdAs$
RoicCs|jt|j|jkrtj|jjggg|\}}}t|dkredSy|jjt	}Wnt
jk
rtnXt|dkrtn|j|7_|jn|j
S(Ni(t_stage0RtbuffertbufneedRR,tfilenoRtrecvRRRQRpt_stage1(R
RfRRRR7((s'/usr/local/lib/python2.7/idlelib/rpc.pyt
pollpacketUs
-
	
cCsj|jdkrft|jdkrf|jd }|jd|_tjd|d|_d|_ndS(Niis<ii(tbufstateRRRtunpackR(R
R7((s'/usr/local/lib/python2.7/idlelib/rpc.pyRes
$
cCsd|jdkr`t|j|jkr`|j|j }|j|j|_d|_d|_|SdS(Niii(RRRR(R
tpacket((s'/usr/local/lib/python2.7/idlelib/rpc.pyRls'		cCs|j|}|dkrdSytj|}Wn]tjk
rtjdIJtjdIt|IJtj	dtjtjdIJnX|S(Ns-----------------------scannot unpickle packet:R(
RRR~RtUnpicklingErrorRRRRtprint_stack(R
RfRR((s'/usr/local/lib/python2.7/idlelib/rpc.pytpollmessagets

c
Csxytjd}Wntjk
r,n,X|\}}|d|ff}|j|y#|j|}|dkrzdSWn-tk
r|jdSt	k
rdSX|\}}|d}|j
d||f|d	krU|j
d||j||}|j
d||f|dkr@|j||fq|dkrqqq||kre|S|jj|d}	|	dk	r|	j
||j|<|	j|	jqqqWdS(
sRHandle messages received on the socket.

        Some messages received may be asynchronous 'call' or 'queue' requests,
        and some may be responses for other threads.

        'call' requests are passed to self.localcall() with the expectation of
        immediate execution, during which time the socket is not serviced.

        'queue' requests are used for tasks (which may block or hang) to be
        processed in a different thread.  These requests are fed into
        request_queue by self.localcall().  Responses to queued requests are
        taken from response_queue and sent across the link with the associated
        sequence numbers.  Messages in the queues are (sequence_number,
        request/response) tuples and code using this module removing messages
        from the request_queue is responsible for returning the correct
        sequence number in the response_queue.

        pollresponse() will loop until a response message with the myseq
        sequence number is received, and will save other responses in
        self.responses and notify the owning thread.

        iRAspollresponse:%d:myseq:%sRCRDspollresponse:%d:localcall:call:s%pollresponse:%d:localcall:response:%sN(RCRD(tresponse_queuetgettQueuetEmptyRdRRRpt
handle_EOFRR9R\R0R{R/tnotifyR|(
R
RqRftqmsgRRRiRtresqRStcv((s'/usr/local/lib/python2.7/idlelib/rpc.pyRzsN




	



cCsq|j|jdxI|jD]>}|j|}|jd|j|<|j|jq!W|jdS(s+action taken upon link being closed by peerRRjN(RjN(	tEOFhookR9R0R{RR/RR|R2(R
tkeyR((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs





cCsdS(sBClasses using rpc client/server can override to augment EOF actionN((R
((s'/usr/local/lib/python2.7/idlelib/rpc.pyRsN("R'R(R}RRR1R2R9R<R>R\R_RaR]R`R^RhRkRrRgRtRsRbRdRRRRRRRRzRR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyR)|s>						*			
	
				
										I	
RMcBseZRS((R'R((((s'/usr/local/lib/python2.7/idlelib/rpc.pyRMscCs t|}|t|<t|S(N(tidR-Ru(RVR:((s'/usr/local/lib/python2.7/idlelib/rpc.pyRNs
RucBseZdZRS(cCs
||_dS(N(R:(R
R:((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs(R'R(R(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRusR	cBs/eZeZdZdZdZdZRS(s#ScCs6||_tj||tjj||||dS(N(tcurrent_handlerR)RR
tBaseRequestHandler(R
R,Rtsvr((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs	cCs|jdS(s(handle() method required by SocketServerN(Rr(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pythandlescCs
t||S(N(Rv(R
R:((s'/usr/local/lib/python2.7/idlelib/rpc.pytget_remote_proxys(R'R(tFalseR+R4RRR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyR	s
		t	RPCClientcBsAeZeZdZdZejejdZ	dZ
dZRS(s#CicCs9tj|||_|jj||jjddS(Ni(Rtlistening_socktbindtlisten(R
taddresstfamilyttype((s'/usr/local/lib/python2.7/idlelib/rpc.pyRscCsw|jj\}}|jr4tjdI|IJn|dtkrWtj||ntjdI|IJtj	dS(Ns****** Connection request from is** Invalid host: (
RtacceptR+RRt	LOCALHOSTR)RRRQ(R
tworking_sockR((s'/usr/local/lib/python2.7/idlelib/rpc.pyR	s	cCs
t||S(N(Rv(R
R:((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs(R'R(RR+R4R}RtAF_INETtSOCK_STREAMRRR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs	
RvcBs8eZdZdZdZdZdZdZRS(cCs||_||_dS(N(tsockioR:(R
RR:((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs	cCs|jdkr|jn|jj|rDt|j|j|S|jdkr`|jn||jkr|jj	|jd|fi}|St
|dS(Nt__getattribute__(t_RPCProxy__methodsRt_RPCProxy__getmethodsRtMethodProxyRR:t_RPCProxy__attributest_RPCProxy__getattributesR_R(R
tnametvalue((s'/usr/local/lib/python2.7/idlelib/rpc.pyt__getattr__s

cCs%|jj|jddi|_dS(NRB((RR_R:R(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pyt__getattributes-scCs%|jj|jddi|_dS(NR@((RR_R:R(R
((s'/usr/local/lib/python2.7/idlelib/rpc.pyt__getmethods1sN(	R'R(RRRRRRR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRvs			cCsx?t|D]1}t||}t|dr
d||<q
q
Wt|tjkrjt|j|nt|tjkrx!|j	D]}t||qWndS(Nt__call__i(
tdirRKRJRRwtInstanceTypeRHt	__class__t	ClassTypet	__bases__(RVRWRtattrtsuper((s'/usr/local/lib/python2.7/idlelib/rpc.pyRH5scCsFx?t|D]1}t||}t|ds
d||<q
q
WdS(NRi(RRKRJ(RVRXRR((s'/usr/local/lib/python2.7/idlelib/rpc.pyRIBsRcBseZdZdZRS(cCs||_||_||_dS(N(RR:R(R
RR:R((s'/usr/local/lib/python2.7/idlelib/rpc.pyRJs		cOs%|jj|j|j||}|S(N(RR_R:R(R
R6RUR((s'/usr/local/lib/python2.7/idlelib/rpc.pyROs!(R'R(RR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRHs	(%t__doc__RR!RRR
RtcPickleR~RRRtcopy_regRwRRRtCodeTypeRRRRR-RORR;R)RMRNRuRR	RRvRHRIR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyt<module>sB		

2c		
	

Zerion Mini Shell 1.0