3 § f‘R ã @ s” d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlZddlZdd„ Zdd„ Zd+dd„ZG d d „ d ejƒZd,Zd ZG dd„ de jƒZi ZejdƒZejdƒZG dd„ deƒZG dd„ deƒZdd„ Z G dd„ deƒZ!G dd„ de j"eƒZ#G dd„ deƒZ$G dd„ deƒZ%dd„ Z&d d!„ Z'G d"d#„ d#eƒZ(d$d%„ Z)e*d&k�r�dd'l+m,Z, e,d(d)d*� dS )-a RPC 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. é Nc C s t j| ƒ}t|tjƒst‚|S )z*Return code object from marshal string ms.)ÚmarshalÚloadsÚ isinstanceÚtypesÚCodeTypeÚAssertionError)ÚmsÚco© r ú0/opt/alt/python36/lib64/python3.6/idlelib/rpc.pyÚ unpickle_code- s r c C s$ t | tjƒst‚tj| ƒ}t|ffS )zBReturn unpickle function and tuple with marshalled co code object.)r r r r r Údumpsr )r r r r r Úpickle_code3 s r c C s$ t jƒ }t||ƒ}|j| ƒ |jƒ S )z.Return pickled (or marshalled) string for obj.)ÚioÚBytesIOÚCodePicklerÚdumpÚgetvalue)ÚobjZprotocolÚfÚpr r r r 9 s r c @ s" e Zd ZejeiZejejƒ dS )r N) Ú__name__Ú __module__Ú__qualname__r r r Údispatch_tableÚupdateÚcopyregr r r r r B s r é i z 127.0.0.1c @ s6 e Zd Zddd„Zdd„ Zdd„ Zdd „ Zd d„ ZdS ) Ú RPCServerNc C s |d krt }tjj| ||ƒ d S )N)Ú RPCHandlerÚsocketserverÚ TCPServerÚ__init__)ÚselfÚaddrZhandlerclassr r r r" L s zRPCServer.__init__c C s dS )z@Override TCPServer method, no bind() phase for connecting entityNr )r# r r r Úserver_bindQ s zRPCServer.server_bindc C s | j j| jƒ dS )zÎOverride 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)ÚsocketZconnectÚserver_address)r# r r r Úserver_activateU s zRPCServer.server_activatec C s | j | jfS )z:Override TCPServer method, return already connected socket)r&