• File: rpc.cpython-37.opt-1.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/rpc.cpython-37.opt-1.pyc
  • Date Modified: 10/26/2026 8:08 PM
  • File size: 19.14 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

NjR@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddZddZd*ddZGd	d
d
ejZdZdZGd
dde
jZiZedZedZGdddeZGdddeZddZ GdddeZ!Gddde
j"eZ#GdddeZ$GdddeZ%ddZ&dd Z'Gd!d"d"eZ(d#d$Z)e*d%krdd&l+m,Z,e,d'd(d)dS)+aRPC 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.

NcCst|}|S)z*Return code object from marshal string ms.)marshalloads)mscor0/opt/alt/python37/lib64/python3.7/idlelib/rpc.py
unpickle_code-s
rcCst|}t|ffS)zBReturn unpickle function and tuple with marshalled co code object.)rdumpsr)rrrrrpickle_code3s
r
cCs$t}t||}|||S)z.Return pickled (or marshalled) string for obj.)ioBytesIOCodePicklerdumpgetvalue)objZprotocolfprrrr	9s

r	c@s"eZdZejeiZeejdS)r
N)	__name__
__module____qualname__typesCodeTyper
dispatch_tableupdatecopyregrrrrr
Bs
r
i z	127.0.0.1c@s6eZdZdddZddZddZdd	Zd
dZdS)
	RPCServerNcCs |dkrt}tj|||dS)N)
RPCHandlersocketserver	TCPServer__init__)selfaddrZhandlerclassrrrrLszRPCServer.__init__cCsdS)z@Override TCPServer method, no bind() phase for connecting entityNr)r rrrserver_bindQszRPCServer.server_bindcCs|j|jdS)zOverride 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)socketZconnectserver_address)r rrrserver_activateUszRPCServer.server_activatecCs|j|jfS)z:Override TCPServer method, return already connected socket)r#r$)r rrrget_request^szRPCServer.get_requestcCsyWntk
rYntj}td|dtd|dtdtj|dtd||dtdt||dtj	|dtd|dtd|dt
d	YnXd
S)zOverride 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.

        z)
----------------------------------------)filezUnhandled server exception!z
Thread: %szClient Address: z	Request: z#
*** Unrecoverable, server exiting!z(----------------------------------------rN)
SystemExitsys
__stderr__print	threadingcurrent_threadnamerepr	traceback	print_excos_exit)r requestZclient_addressZerfrrrhandle_errorbszRPCServer.handle_error)N)rrrrr"r%r&r5rrrrrJs

	rc@seZdZdZd;ddZddZddZd	d
ZddZd
dZ	ddZ
ddZddZddZ
ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+Zd,ZdZd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Z d9d:Z!dS)<SocketIOrNcCs@t|_|dk	r||_||_|dkr*t}||_i|_i|_dS)N)	r,r-
sockthread	debuggingsockobjecttableobjtable	responsescvars)r r9r;r8rrrrs
zSocketIO.__init__cCs |j}d|_|dk	r|dS)N)r9close)r r9rrrr>szSocketIO.closecCstddS)z!override for specific exit actionrN)r2r3)r rrrexithookszSocketIO.exithookcGsR|js
dS|jdttj}x|D]}|dt|}q(Wt|tjddS)N )r')	r8locationstrr,r-r.r+r)r*)r argssarrrdebugs
zSocketIO.debugcCs||j|<dS)N)r;)r oidobjectrrrregisterszSocketIO.registercCs&y|j|=Wntk
r YnXdS)N)r;KeyError)r rGrrr
unregisterszSocketIO.unregisterc
Cs|d|y|\}\}}}}Wntk
r4dSX||jkrNdd|ffS|j|}|dkrvi}	t||	d|	fS|dkri}
t||
d|
fSt||sdd|ffSt||}y^|d	kr|||}t|trt	|}d|fS|d
krt
||||ffdSdd|fSWntk
r,Ynt
k
rBYnptk
rXYnZtk
r~}
zd
|
fSd}
~
XYn4d}t||||ftjdtjtjddSdS)Nz
localcall:)ERRORzBad request formatrLzUnknown object id: %r__methods__OK__attributes__zUnsupported method name: %rCALLQUEUE)QUEUEDNzUnsupported message type: %sCALLEXCzU*** Internal Error: rpc.py:SocketIO.localcall()

 Object: %s 
 Method: %s 
 Args: %s
)r')	EXCEPTIONN)rF	TypeErrorr;_getmethods_getattributeshasattrgetattr
isinstanceRemoteObject	remoteref
request_queueZputr(KeyboardInterruptOSError	Exceptionr+r)r*r0r1)r seqr4howrG
methodnamerCkwargsrmethods
attributesmethodZretZexmsgrrr	localcallsT








zSocketIO.localcallcCs(|d|||||||}||S)Nzremotecall:asynccall: )rF	asynccallasyncreturn)r rGrcrCrdrarrr
remotecallszSocketIO.remotecallcCs(|d|||||||}||S)Nzremotequeue:asyncqueue: )rF
asyncqueuerk)r rGrcrCrdrarrrremotequeueszSocketIO.remotequeuecCs`d||||ff}|}t|jkr8t}||j|<|d||||||||f|S)NrPz
asynccall:%d:)newseqr,r-r7	Conditionr=rF
putmessage)r rGrcrCrdr4racvarrrrrjs
zSocketIO.asynccallcCs`d||||ff}|}t|jkr8t}||j|<|d||||||||f|S)NrQzasyncqueue:%d:)ror,r-r7rpr=rFrq)r rGrcrCrdr4rarrrrrrms
zSocketIO.asyncqueuecCs6|d||j|dd}|d||||S)Nz#asyncreturn:%d:call getresponse(): g?)waitzasyncreturn:%d:response: )rFgetresponsedecoderesponse)r raresponserrrrkszSocketIO.asyncreturncCs|\}}|dkr|S|dkr dS|dkr6|ddS|dkrT|d|dS|dkrp|d|t||d	kr|d
||t||dS)NrNrRrTzdecoderesponse: EXCEPTIONEOFzdecoderesponse: EOFrLzdecoderesponse: Internal ERROR:rSzdecoderesponse: Call Exception:)rFdecode_interrupthookRuntimeErrorSystemError)r rvrbwhatrrrrus&

zSocketIO.decoderesponsecCstdS)N)EOFError)r rrrrxszSocketIO.decode_interrupthookcCs6y|jdddWntk
r0|ddSXdS)zListen on socket until I/O not ready or EOF

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

        Ng?)myseqrszmainloop:return)rtr}rF)r rrrmainloops

zSocketIO.mainloopcCs6|||}|dk	r2|\}}|dkr2|||f}|S)NrN)_getresponse_proxify)r r~rsrvrbr{rrrrt#szSocketIO.getresponsecCs4t|trt||jSt|tr0tt|j|S|S)N)rZRemoteProxyRPCProxyrGlistmapr)r rrrrr+s


zSocketIO._proxifycCs|d|t|jkr:x|||}|dk	r|SqWnb|j|}|x||jkrb|qNW|j|}|d||f|j|=|j|=|	|SdS)Nz_getresponse:myseq:z-_getresponse:%s: thread woke up: response: %s)
rFr,r-r7pollresponser=acquirer<rsrelease)r r~rsrvrrrrrr3s"


zSocketIO._getresponsecCs|jd|_}|S)N)nextseq)r rarrrroIszSocketIO.newseqc	Cs|d|dyt|}Wn,tjk
rJtdt|tjdYnXt	dt
||}xnt
|dkry0tg|jgg\}}}|j
|dt}Wn ttfk
rtdYnX||d}qbWdS)Nzputmessage:%d:rzCannot pickle:)r'z<izsocket no longer exists)rFr	pickleZ
PicklingErrorr+r/r)r*structZpacklenselectr9sendBUFSIZEAttributeErrorrUr_)r messagerDrwxnrrrrqMszSocketIO.putmessagecCs|t|j|jkrt|jggg|\}}}t|dkrFdSy|jt}Wnt	k
rnt
YnXt|dkrt
|j|7_||S)Nr)_stage0rbuffbufneedrr9filenoZrecvrr_r}_stage1)r rsrrrrDrrr
pollpacketas
zSocketIO.pollpacketcCsR|jdkrNt|jdkrN|jdd}|jdd|_td|d|_d|_dS)Nrrz<i)bufstaterrrZunpackr)r rDrrrrqs
zSocketIO._stage0cCsP|jdkrLt|j|jkrL|jd|j}|j|jd|_d|_d|_|SdS)Nrrr)rrrr)r packetrrrrxszSocketIO._stage1cCs||}|dkrdSyt|}WnVtjk
rztdtjdtdt|tjdtj	tjdtdtjdYnX|S)Nz-----------------------)r'zcannot unpickle packet:)
rrrZUnpicklingErrorr+r)r*r/r0print_stack)r rsrrrrrpollmessages
zSocketIO.pollmessagec
Cs`xXytd}Wntjk
r(Yn X|\}}|d|ff}||y||}|dkr`dSWn.tk
r~|dStk
rdSX|\}}|d}|	d||f|dkr|	d||
||}|	d||f|dkr|||fq|d	krqq||kr|S|j|d}	|	dk	r|	||j
|<|	|	qqWdS)
aRHandle 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.

        rrNNzpollresponse:%d:myseq:%s)rPrQzpollresponse:%d:localcall:call:z%pollresponse:%d:localcall:response:%srPrQ)response_queuegetqueueZEmptyrqrr}
handle_EOFrrFrir=rr<notifyr)
r r~rsZqmsgrarvrZresqrbcvrrrrsL





zSocketIO.pollresponsecCsZ||dx:|jD]0}|j|}|d|j|<||qW|dS)z+action taken upon link being closed by peerr)rwNN)EOFhookrFr=rr<rrr?)r keyrrrrrs


zSocketIO.handle_EOFcCsdS)zBClasses using rpc client/server can override to augment EOF actionNr)r rrrrszSocketIO.EOFhook)NN)"rrrrrr>r?rFrIrKrirlrnrjrmrkrurxrrtrrrorqrrrrrrrrrrrrrrr6s>
.


I
r6c@seZdZdS)r[N)rrrrrrrr[sr[cCst|}|t|<t|S)N)idr:r)rrGrrrr\sr\c@seZdZddZdS)rcCs
||_dS)N)rG)r rGrrrrszRemoteProxy.__init__N)rrrrrrrrrsrc@s,eZdZdZdZddZddZddZd	S)
rFz#ScCs(||_t||tj||||dS)N)Zcurrent_handlerr6rrBaseRequestHandler)r r9r!ZsvrrrrrszRPCHandler.__init__cCs|dS)z(handle() method required by socketserverN)r)r rrrhandleszRPCHandler.handlecCs
t||S)N)r)r rGrrrget_remote_proxy	szRPCHandler.get_remote_proxyN)rrrr8rArrrrrrrrs
rc@s:eZdZdZdZdZejejfddZ	ddZ
dd	Zd
S)	RPCClientFz#CrcCs*t|||_|j||jddS)Nr)r#listening_sockZbindZlisten)r addressZfamilytyperrrrszRPCClient.__init__cCsV|j\}}|jr$td|tjd|dtkr>t||ntd|tjdt	dS)Nz****** Connection request from )r'rz** Invalid host: )
racceptr8r+r)r*	LOCALHOSTr6rr_)r Zworking_sockrrrrrszRPCClient.acceptcCs
t||S)N)r)r rGrrrr#szRPCClient.get_remote_proxyN)rrrr8rArr#ZAF_INETZSOCK_STREAMrrrrrrrr
s
rc@s4eZdZdZdZddZddZddZdd	ZdS)
rNcCs||_||_dS)N)sockiorG)r rrGrrrr,szRPCProxy.__init__cCsp|jdkr||j|r.t|j|j|S|jdkr@|||jkrd|j|jd|fi}|St	|dS)N__getattribute__)
_RPCProxy__methods_RPCProxy__getmethodsrMethodProxyrrG_RPCProxy__attributes_RPCProxy__getattributesrlr)r r.valuerrr__getattr__0s



zRPCProxy.__getattr__cCs|j|jddi|_dS)NrOr)rrlrGr)r rrrZ__getattributes>s
zRPCProxy.__getattributescCs|j|jddi|_dS)NrMr)rrlrGr)r rrrZ__getmethodsBs
zRPCProxy.__getmethods)	rrrrrrrrrrrrrr'srcCsTx*t|D]}t||}t|r
d||<q
Wt|trPx|jD]}t||q>WdS)Nr)dirrYcallablerZr	__bases__rV)rrer.attrsuperrrrrVFs

rVcCs0x*t|D]}t||}t|s
d||<q
WdS)Nr)rrYr)rrfr.rrrrrWQs
rWc@seZdZddZddZdS)rcCs||_||_||_dS)N)rrGr.)r rrGr.rrrrZszMethodProxy.__init__cOs|j|j|j||}|S)N)rrlrGr.)r rCrdrrrr__call___szMethodProxy.__call__N)rrrrrrrrrrXsrcCs~|dkrdSdt_t|}ytj|Wn<tk
rfd}||d}||d}tj|YnXtjd|t_dS)z9Override standard display hook to use non-locale encodingNasciibackslashreplacestrict
)	builtins_r/r)stdoutwriteUnicodeEncodeErrorencodedecode)rtextencodingbytesrrrdisplayhookgsr__main__)mainzidlelib.idle_test.test_rpcr)	verbosity)N)-__doc__rrrrr2rrrr#rrr)r,r0rrr
r	ZPicklerr
rrrrr:ZQueuer]rrHr6r[r\rrrrrrVrWrrrZunittestrrrrr<module>sR
	2

k