%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.pyc


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.

iNcCs+tj|}t|tjs't|S(N(tmarshaltloadst
isinstancettypestCodeTypetAssertionError(tmstco((s'/usr/local/lib/python2.7/idlelib/rpc.pyt
unpickle_code-scCs4t|tjsttj|}t|ffS(N(RRRRRtdumpsR(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.pyRGs	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(Rtrequesttclient_addressterf((s'/usr/local/lib/python2.7/idlelib/rpc.pythandle_error]s
	

N(t__name__t
__module__RRRRRR*(((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(
RR t
sockthreadRt	debuggingtsocktobjecttabletobjtablet	responsestcvars(RR0R2R/((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs				cCs/|j}d|_|dk	r+|jndS(N(R0Rtclose(RR0((s'/usr/local/lib/python2.7/idlelib/rpc.pyR5s		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/tlocationtstrRR R!RR(Rtargststa((s'/usr/local/lib/python2.7/idlelib/rpc.pytdebugs	#
cCs||j|<dS(N(R2(Rtoidtobject((s'/usr/local/lib/python2.7/idlelib/rpc.pytregisterscCs&y|j|=Wntk
r!nXdS(N(R2tKeyError(RR>((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(RCsBad request format(RIN(RJN(R=t	TypeErrorR2t_getmethodst_getattributesthasattrtgetattrRtRemoteObjectt	remotereft
request_queuetputRRRterrorRRR#R$(RtseqR'thowR>t
methodnameR:tkwargstobjtmethodst
attributestmethodtrettmsg((s'/usr/local/lib/python2.7/idlelib/rpc.pyt	localcallsL







cCs8|jd|||j||||}|j|S(Nsremotecall:asynccall: (R=t	asynccalltasyncreturn(RR>RWR:RXRU((s'/usr/local/lib/python2.7/idlelib/rpc.pyt
remotecallscCs8|jd|||j||||}|j|S(Nsremotequeue:asyncqueue: (R=t
asyncqueueRa(RR>RWR:RXRU((s'/usr/local/lib/python2.7/idlelib/rpc.pytremotequeuescCsd||||ff}|j}tj|jkrUtj}||j|<n|jd||||||j||f|S(NRGs
asynccall:%d:(tnewseqRR R.t	ConditionR4R=t
putmessage(RR>RWR:RXR'RUtcvar((s'/usr/local/lib/python2.7/idlelib/rpc.pyR`scCsd||||ff}|j}tj|jkrUtj}||j|<n|jd||||||j||f|S(NRHsasyncqueue:%d:(ReRR R.RfR4R=Rg(RR>RWR:RXR'RURh((s'/usr/local/lib/python2.7/idlelib/rpc.pyRcscCsG|jd||j|dd}|jd|||j|S(Ns#asyncreturn:%d:call getresponse(): twaitg?sasyncreturn:%d:response: (R=tgetresponsetdecoderesponse(RRUtresponse((s'/usr/local/lib/python2.7/idlelib/rpc.pyRascCs|\}}|dkr|S|dkr,dS|dkrI|jddS|dkrp|jd|jdS|dkr|jd|t|nt||fdS(	NRERIRJsdecoderesponse: EXCEPTIONtEOFsdecoderesponse: EOFRCsdecoderesponse: Internal ERROR:(RR=tdecode_interrupthooktRuntimeErrortSystemError(RRlRVtwhat((s'/usr/local/lib/python2.7/idlelib/rpc.pyRks 


cCs
tdS(tN(tEOFError(R((s'/usr/local/lib/python2.7/idlelib/rpc.pyRnscCs@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.

        tmyseqRig?smainloop:returnN(RjRRsR=(R((s'/usr/local/lib/python2.7/idlelib/rpc.pytmainloop
s


cCsU|j||}|dk	rQ|\}}|dkrQ||j|f}qQn|S(NRE(t_getresponseRt_proxify(RRtRiRlRVRq((s'/usr/local/lib/python2.7/idlelib/rpc.pyRjscCsEt|trt||jSt|tjrAt|j|S|S(N(RtRemoteProxytRPCProxyR>RtListTypetmapRw(RRY((s'/usr/local/lib/python2.7/idlelib/rpc.pyRws
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(R=RR R.tpollresponseRR4tacquireR3Ritrelease(RRtRiRlRh((s'/usr/local/lib/python2.7/idlelib/rpc.pyRv's"


	


cCs|jd|_}|S(Ni(tnextseq(RRU((s'/usr/local/lib/python2.7/idlelib/rpc.pyRe=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(R=tpickleR	t
PicklingErrorRRR"tstructtpacktlentselectR0tsendtBUFSIZEtAttributeErrorRKtIOError(RtmessageR;trtwtxtn((s'/usr/local/lib/python2.7/idlelib/rpc.pyRgAs$
RricCs|jt|j|jkrtj|jjggg|\}}}t|dkredSy|jjt	}Wnt
jk
rtnXt|dkrtn|j|7_|jn|j
S(Ni(t_stage0RtbuffertbufneedRR0tfilenoRtrecvRRRTRst_stage1(RRiRRRR;((s'/usr/local/lib/python2.7/idlelib/rpc.pyt
pollpacketUs
-
	
cCsj|jdkrft|jdkrf|jd }|jd|_tjd|d|_d|_ndS(Niis<ii(tbufstateRRRtunpackR(RR;((s'/usr/local/lib/python2.7/idlelib/rpc.pyRes
$
cCsd|jdkr`t|j|jkr`|j|j }|j|j|_d|_d|_|SdS(Niii(RRRR(Rtpacket((s'/usr/local/lib/python2.7/idlelib/rpc.pyRls'		cCs|j|}|dkrdSytj|}Wn]tjk
rtjdIJtjdIt|IJtj	dtjtjdIJnX|S(Ns-----------------------scannot unpickle packet:R(
RRRRtUnpicklingErrorRRR"R#tprint_stack(RRiRR((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.

        iREspollresponse:%d:myseq:%sRGRHspollresponse:%d:localcall:call:s%pollresponse:%d:localcall:response:%sN(RGRH(tresponse_queuetgettQueuetEmptyRgRRRst
handle_EOFRR=R_R4R}R3tnotifyR~(
RRtRitqmsgRURlRtresqRVtcv((s'/usr/local/lib/python2.7/idlelib/rpc.pyR|sN




	



cCsq|j|jdxI|jD]>}|j|}|jd|j|<|j|jq!W|jdS(s+action taken upon link being closed by peerRRmN(RmN(	tEOFhookR=R4R}RR3RR~R6(RtkeyR((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,RRRR5R6R=R@RBR_RbRdR`RcRaRkRnRuRjRwRvReRgRRRRRRRR|RR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyR-|s>						*			
	
				
										I	
RPcBseZRS((R+R,(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRPscCs t|}|t|<t|S(N(tidR1Rx(RYR>((s'/usr/local/lib/python2.7/idlelib/rpc.pyRQs
RxcBseZdZRS(cCs
||_dS(N(R>(RR>((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs(R+R,R(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRxsR
cBs/eZeZdZdZdZdZRS(s#ScCs6||_tj||tjj||||dS(N(tcurrent_handlerR-RRtBaseRequestHandler(RR0Rtsvr((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs	cCs|jdS(s(handle() method required by SocketServerN(Ru(R((s'/usr/local/lib/python2.7/idlelib/rpc.pythandlescCs
t||S(N(Ry(RR>((s'/usr/local/lib/python2.7/idlelib/rpc.pytget_remote_proxys(R+R,tFalseR/R8RRR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyR
s
		t	RPCClientcBsAeZeZdZdZejejdZ	dZ
dZRS(s#CicCs9tj|||_|jj||jjddS(Ni(Rtlistening_socktbindtlisten(Rtaddresstfamilyttype((s'/usr/local/lib/python2.7/idlelib/rpc.pyRscCsw|jj\}}|jr4tjdI|IJn|dtkrWtj||ntjdI|IJtj	dS(Ns****** Connection request from is** Invalid host: (
RtacceptR/RRt	LOCALHOSTR-RRRT(Rtworking_sockR((s'/usr/local/lib/python2.7/idlelib/rpc.pyR	s	cCs
t||S(N(Ry(RR>((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs(R+R,RR/R8RRtAF_INETtSOCK_STREAMRRR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs	
RycBs8eZdZdZdZdZdZdZRS(cCs||_||_dS(N(tsockioR>(RRR>((s'/usr/local/lib/python2.7/idlelib/rpc.pyRs	cCs|jdkr|jn|jj|rDt|j|j|S|jdkr`|jn||jkr|jj	|jd|fi}|St
|dS(Nt__getattribute__(t_RPCProxy__methodsRt_RPCProxy__getmethodsRtMethodProxyRR>t_RPCProxy__attributest_RPCProxy__getattributesRbR(Rtnametvalue((s'/usr/local/lib/python2.7/idlelib/rpc.pyt__getattr__s

cCs%|jj|jddi|_dS(NRF((RRbR>R(R((s'/usr/local/lib/python2.7/idlelib/rpc.pyt__getattributes-scCs%|jj|jddi|_dS(NRD((RRbR>R(R((s'/usr/local/lib/python2.7/idlelib/rpc.pyt__getmethods1sN(	R+R,RRRRRRR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRys			cCsx?t|D]1}t||}t|dr
d||<q
q
Wt|tjkrjt|j|nt|tjkrx!|j	D]}t||qWndS(Nt__call__i(
tdirRORNRRtInstanceTypeRLt	__class__t	ClassTypet	__bases__(RYRZRtattrtsuper((s'/usr/local/lib/python2.7/idlelib/rpc.pyRL5scCsFx?t|D]1}t||}t|ds
d||<q
q
WdS(NRi(RRORN(RYR[RR((s'/usr/local/lib/python2.7/idlelib/rpc.pyRMBsRcBseZdZdZRS(cCs||_||_||_dS(N(RR>R(RRR>R((s'/usr/local/lib/python2.7/idlelib/rpc.pyRJs		cOs%|jj|j|j||}|S(N(RRbR>R(RR:RXR((s'/usr/local/lib/python2.7/idlelib/rpc.pyROs!(R+R,RR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyRHs	(%t__doc__RR%RRRRtcPickleRRRR#tcopy_regRRRR
RRRRRR1RRRR?R-RPRQRxRR
RRyRLRMR(((s'/usr/local/lib/python2.7/idlelib/rpc.pyt<module>sB		

2c		
	

Zerion Mini Shell 1.0