ž ©ÿfÙQc@sýdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZdd„Zdd„Ze je jeeƒddZd ZGd d „d ejƒZiZe jdƒZe jdƒZGd d „d eƒZGdd„deƒZdd„ZGdd„deƒZGdd„dejeƒZ Gdd„deƒZ!Gdd„deƒZ"dd„Z#dd„Z$Gdd„deƒZ%d d!„Z&dS("uRPC Implemention, 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(umarshaluloads(umsuco((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu unpickle_code.su unpickle_codecCstj|ƒ}t|ffS(N(umarshaludumpsu unpickle_code(ucoums((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu pickle_code3su pickle_codeiiu 127.0.0.1cBsS|EeZdZd dd„Zdd„Zdd„Zdd„Zd d „Zd S( u RPCServercCs/|dkrt}ntjj|||ƒdS(N(uNoneu RPCHandleru socketserveru TCPServeru__init__(uselfuaddru handlerclass((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__init__Hs  uRPCServer.__init__cCsdS(u@Override TCPServer method, no bind() phase for connecting entityN((uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu server_bindMsuRPCServer.server_bindcCs|jj|jƒdS(uÎ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(usocketuconnectuserver_address(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuserver_activateQsuRPCServer.server_activatecCs|j|jfS(u:Override TCPServer method, return already connected socket(usocketuserver_address(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu get_requestZsuRPCServer.get_requestc Csåy‚Wn×tk r‚YnÃtj}tdddd|ƒtdd|ƒtdtjƒjd|ƒtd|d|ƒtdt|ƒd|ƒtj d|ƒtd d|ƒtddd|ƒt j d ƒYnXd S( uÜOverride 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. u u-i(ufileuUnhandled server exception!u Thread: %suClient Address: u Request: u# *** Unrecoverable, server exiting!iN( u SystemExitusysu __stderr__uprintu threadingucurrent_threadunameurepru tracebacku print_excuosu_exit(uselfurequestuclient_addressuerf((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu handle_error^s  uRPCServer.handle_errorN( u__name__u __module__u __qualname__uNoneu__init__u server_binduserver_activateu get_requestu handle_error(u __locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu RPCServerFs   u RPCServercBsv|EeZdZdZd:d:dd„Zdd„Zdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*Zd+ZdZd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Z d6d7„Z!d8d9„Z"d:S(;uSocketIOicCsdtjƒ|_|dk r'||_n||_|dkrEt}n||_i|_i|_ dS(N( u threadingucurrent_threadu sockthreaduNoneu debuggingusocku objecttableuobjtableu responsesucvars(uselfusockuobjtableu debugging((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__init__s       uSocketIO.__init__cCs/|j}d|_|dk r+|jƒndS(N(usockuNoneuclose(uselfusock((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyucloseŒs   uSocketIO.closecCstjdƒdS(u!override for specific exit actioniN(uosu_exit(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuexithook’suSocketIO.exithookcGsi|js dS|jdttjƒjƒ}x"|D]}|dt|ƒ}q4Wt|dtjƒdS(Nu ufile( u debuggingulocationustru threadingucurrent_threadunameuprintusysu __stderr__(uselfuargsusua((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyudebug–s    uSocketIO.debugcCs||j|}|j|}|jƒd|j|<|jƒ|jƒq!W|jƒdS(u+action taken upon link being closed by peeru handle_EOFuEOFN(uEOFN( uEOFhookudebugucvarsuacquireuNoneu responsesunotifyureleaseuexithook(uselfukeyucv((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu handle_EOFÖs      uSocketIO.handle_EOFcCsdS(uBClasses using rpc client/server can override to augment EOF actionN((uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuEOFhookãsuSocketIO.EOFhookN(#u__name__u __module__u __qualname__unextsequNoneu__init__ucloseuexithookudebuguregisteru unregisteru localcallu remotecallu remotequeueu asynccallu asyncqueueu asyncreturnudecoderesponseudecode_interrupthookumainloopu getresponseu_proxifyu _getresponseunewsequ putmessageubuffubufneedubufstateu pollpacketu_stage0u_stage1u pollmessageu pollresponseu handle_EOFuEOFhook(u __locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuSocketIO}s>      .               I uSocketIOcBs|EeZdZdS(u RemoteObjectN(u__name__u __module__u __qualname__(u __locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu RemoteObjectésu RemoteObjectcCs t|ƒ}|t|sF                 2ÿm