Your IP : 216.73.217.7
�
��f�Qc@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZdd�Zdd�Zejejee�ddZd ZGd
d�dej�ZiZe jd�Ze jd�ZGdd
�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.pyupickle_code3supickle_codeiiu 127.0.0.1cBsS|EeZdZddd�Zdd�Zdd�Zdd�Zd d
�ZdS(u RPCServercCs/|dkrt}ntjj|||�dS(N(uNoneu
RPCHandlerusocketserveru TCPServeru__init__(uselfuaddruhandlerclass((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.pyuserver_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.pyuget_requestZsuRPCServer.get_requestcCs�y�Wn�tk
r�Yn�tj}tdddd|�tdd|�tdtj�jd|�td|d|�tdt|�d|�tj d|�td d|�tddd|�t
jd
�YnXdS(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.pyuhandle_error^s
uRPCServer.handle_errorN( u__name__u
__module__u__qualname__uNoneu__init__userver_binduserver_activateuget_requestuhandle_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 dd
�Z
dd�Zdd�Zdd�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 debuggingusockuobjecttableuobjtableu 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|<dS(N(uobjtable(uselfuoiduobject((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuregister�suSocketIO.registercCs'y|j|=Wntk
r"YnXdS(N(uobjtableuKeyError(uselfuoid((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu
unregister�s
uSocketIO.unregistercCs-|jd|�y|\}\}}}}Wntk
rDdSYnX||jkredd|ffS|j|}|dkr�i} t|| �d| fS|dkr�i}
t||
�d|
fSt||�s�dd|ffSt||�}y�|d kr9|||�}t|t�r/t |�}nd|fS|d
kret
j||||ff�dSdd|fSWn�t
k
r��Yn�tk
r��Yn�tjk
r��Ynstk
r�}
zd
|
fSWYdd}
~
XnEd}t||||fdtj�tjdtj�dSYnXdS(Nu
localcall:uERRORuBad request formatuUnknown object id: %ru__methods__uOKu__attributes__uUnsupported method name: %ruCALLuQUEUEuQUEUEDuUnsupported message type: %suCALLEXCuU*** Internal Error: rpc.py:SocketIO.localcall()
Object: %s
Method: %s
Args: %s
ufileu EXCEPTION(uERRORuBad request format(uQUEUEDN(u EXCEPTIONN(udebugu TypeErroruobjtableu_getmethodsu_getattributesuhasattrugetattru
isinstanceuRemoteObjectu remoterefu
request_queueuputuNoneu
SystemExituKeyboardInterruptusocketuerroru Exceptionuprintusysu
__stderr__u tracebacku print_exc(uselfusequrequestuhowuoidu
methodnameuargsukwargsuobjumethodsu
attributesumethoduretuexumsg((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu localcall�sT
uSocketIO.localcallcCs8|jd||�|j||||�}|j|�S(Nuremotecall:asynccall: (udebugu asynccalluasyncreturn(uselfuoidu
methodnameuargsukwargsuseq((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu
remotecall�suSocketIO.remotecallcCs8|jd||�|j||||�}|j|�S(Nuremotequeue:asyncqueue: (udebugu
asyncqueueuasyncreturn(uselfuoidu
methodnameuargsukwargsuseq((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuremotequeue�suSocketIO.remotequeuecCs�d||||ff}|j�}tj�|jkrUtj�}||j|<n|jd|||||�|j||f�|S(NuCALLu
asynccall:%d:(unewsequ threadingucurrent_threadu
sockthreadu Conditionucvarsudebugu
putmessage(uselfuoidu
methodnameuargsukwargsurequestusequcvar((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu asynccall�suSocketIO.asynccallcCs�d||||ff}|j�}tj�|jkrUtj�}||j|<n|jd|||||�|j||f�|S(NuQUEUEuasyncqueue:%d:(unewsequ threadingucurrent_threadu
sockthreadu Conditionucvarsudebugu
putmessage(uselfuoidu
methodnameuargsukwargsurequestusequcvar((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu
asyncqueue�suSocketIO.asyncqueuecCsG|jd|�|j|dd�}|jd||�|j|�S(Nu#asyncreturn:%d:call getresponse(): uwaitg�������?uasyncreturn:%d:response: (udebugugetresponseudecoderesponse(uselfusequresponse((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuasyncreturn�suSocketIO.asyncreturncCs�|\}}|dkr|S|dkr,dS|dkrI|jd�dS|dkrp|jd�|j�dS|dkr�|jd|�t|��n|d kr�|jd
|�|�nt||��dS(NuOKuQUEUEDu EXCEPTIONudecoderesponse: EXCEPTIONuEOFudecoderesponse: EOFuERRORudecoderesponse: Internal ERROR:uCALLEXCudecoderesponse: Call Exception:(uNoneudebugudecode_interrupthookuRuntimeErroruSystemError(uselfuresponseuhowuwhat((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyudecoderesponse�s&
uSocketIO.decoderesponsecCs
t�dS(uN(uEOFError(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyudecode_interrupthooksuSocketIO.decode_interrupthookcCsDy|jdddd�Wn#tk
r?|jd�dSYnXdS(u�Listen on socket until I/O not ready or EOF
pollresponse() will loop looking for seq number None, which
never comes, and exit on EOFError.
umysequwaitg�������?umainloop:returnN(ugetresponseuNoneuEOFErrorudebug(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyumainloops
uSocketIO.mainloopcCsU|j||�}|dk rQ|\}}|dkrQ||j|�f}qQn|S(NuOK(u_getresponseuNoneu_proxify(uselfumysequwaituresponseuhowuwhat((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyugetresponsesuSocketIO.getresponsecCsHt|t�rt||j�St|t�rDtt|j|��S|S(N(u
isinstanceuRemoteProxyuRPCProxyuoidulistumapu_proxify(uselfuobj((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu_proxify's
uSocketIO._proxifycCs�|jd|�tj�|jkrPx�|j||�}|dk r(|Sq(n}|j|}|j�x||jkr�|j �qjW|j|}|jd||f�|j|=|j|=|j
�|SdS(Nu_getresponse:myseq:u-_getresponse:%s: thread woke up: response: %s(udebugu threadingucurrent_threadu
sockthreadupollresponseuNoneucvarsuacquireu responsesuwaiturelease(uselfumysequwaituresponseucvar((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu_getresponse/s"
uSocketIO._getresponsecCs|jd|_}|S(Ni(unextseq(uselfuseq((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyunewseqEsuSocketIO.newseqcCs*|jd|d�ytj|�}Wn4tjk
r^tdt|�dtj��YnXtj dt
|��|}x�t
|�dkr%yDtjg|jgg�\}}}|jj
|dt��}Wn;ttfk
r�td��Yq~tjk
r�Yq~X||d�}q~WdS(Nuputmessage:%d:iuCannot pickle:ufileu<iusocket no longer exists(udebugupickleudumpsu
PicklingErroruprintureprusysu
__stderr__ustructupackulenuselectusockusenduBUFSIZEuAttributeErroru TypeErroruOSErrorusocketuerror(uselfumessageusuruwuxun((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu
putmessageIs $ uSocketIO.putmessagesicCs�|j�t|j�|jkr�tj|jj�ggg|�\}}}t|�dkredSy|jjt �}Wnt
jk
r�t�YnXt|�dkr�t�n|j|7_|j�n|j
�S(Ni(u_stage0ulenubuffubufneeduselectusockufilenouNoneurecvuBUFSIZEusocketuerroruEOFErroru_stage1(uselfuwaituruwuxus((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu
pollpacket`s
-
uSocketIO.pollpacketcCsv|jdkrrt|j�dkrr|jdd�}|jdd�|_tjd|�d|_d|_ndS(Niiu<ii(ubufstateulenubuffustructuunpackubufneed(uselfus((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu_stage0ps
$uSocketIO._stage0cCsp|jdkrlt|j�|jkrl|jd|j�}|j|jd�|_d|_d|_|SdS(Niii(ubufstateulenubuffubufneed(uselfupacket((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu_stage1ws' uSocketIO._stage1cCs�|j|�}|dkrdSytj|�}Wnmtjk
r�tddtj�tdt|�dtj�t j
dtj�tddtj��YnX|S(Nu-----------------------ufileucannot unpickle packet:(u
pollpacketuNoneupickleuloadsuUnpicklingErroruprintusysu
__stderr__urepru tracebackuprint_stack(uselfuwaitupacketumessage((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyupollmessagesuSocketIO.pollmessagec
Cs�x�ytjd�}Wntjk
r-Yn,X|\}}|d|ff}|j|�y#|j|�}|dkr{dSWn5tk
r�|j�dSYnt k
r�dSYnX|\}}|d}|j
d||f�|d kr^|j
d|�|j||�}|j
d||f�|dkrI|j||f�q|dkrqqq||krn|S|jj|d�} | dk r| j
�||j|<| j�| j�qqqdS(
uRHandle 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.
iuOKupollresponse:%d:myseq:%suCALLuQUEUEupollresponse:%d:localcall:call:u%pollresponse:%d:localcall:response:%sN(uCALLuQUEUE(uresponse_queueugetuqueueuEmptyu
putmessageupollmessageuNoneuEOFErroru
handle_EOFuAttributeErrorudebugu localcallucvarsuacquireu responsesunotifyurelease(
uselfumysequwaituqmsgusequresponseumessageuresquhowucv((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyupollresponse�sN
uSocketIO.pollresponsecCsq|j�|jd�xI|jD]>}|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
remotecalluremotequeueu asynccallu
asyncqueueuasyncreturnudecoderesponseudecode_interrupthookumainloopugetresponseu_proxifyu_getresponseunewsequ
putmessageubuffubufneedubufstateu
pollpacketu_stage0u_stage1upollmessageupollresponseu
handle_EOFuEOFhook(u
__locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuSocketIO}s>.
I
uSocketIOcBs|EeZdZdS(uRemoteObjectN(u__name__u
__module__u__qualname__(u
__locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuRemoteObject�suRemoteObjectcCs t|�}|t|<t|�S(N(uiduobjecttableuRemoteProxy(uobjuoid((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu remoteref�s
u remoterefcBs |EeZdZdd�ZdS(uRemoteProxycCs
||_dS(N(uoid(uselfuoid((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__init__�suRemoteProxy.__init__N(u__name__u
__module__u__qualname__u__init__(u
__locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuRemoteProxy�suRemoteProxycBsD|EeZdZd ZdZdd�Zdd�Zdd�ZdS(
u
RPCHandleru#ScCs6||_tj||�tjj||||�dS(N(ucurrent_handleruSocketIOu__init__usocketserveruBaseRequestHandler(uselfusockuaddrusvr((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__init__�s uRPCHandler.__init__cCs|j�dS(u(handle() method required by socketserverN(umainloop(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuhandlesuRPCHandler.handlecCs
t||�S(N(uRPCProxy(uselfuoid((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuget_remote_proxysuRPCHandler.get_remote_proxyNF( u__name__u
__module__u__qualname__uFalseu debuggingulocationu__init__uhandleuget_remote_proxy(u
__locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu
RPCHandler�s
u
RPCHandlercBsV|EeZdZd
ZdZdZejej dd�Z
dd�Zdd�Zd S(u RPCClientu#CicCs9tj||�|_|jj|�|jjd�dS(Ni(usocketulistening_sockubindulisten(uselfuaddressufamilyutype((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__init__suRPCClient.__init__cCs}|jj�\}}|jr7td|dtj�n|dtkrZtj||�ntd|dtj�t j
�dS(Nu****** Connection request from ufileiu** Invalid host: (ulistening_sockuacceptu debugginguprintusysu
__stderr__u LOCALHOSTuSocketIOu__init__usocketuerror(uselfuworking_sockuaddress((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuaccepts uRPCClient.acceptcCs
t||�S(N(uRPCProxy(uselfuoid((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuget_remote_proxysuRPCClient.get_remote_proxyNF(
u__name__u
__module__u__qualname__uFalseu debuggingulocationunextsequsocketuAF_INETuSOCK_STREAMu__init__uacceptuget_remote_proxy(u
__locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu RPCClients
u RPCClientcBsP|EeZdZd Zd Zdd�Zdd�Zdd�Zdd�Z d S(
uRPCProxycCs||_||_dS(N(usockiouoid(uselfusockiouoid((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__init__&s uRPCProxy.__init__cCs�|jdkr|j�n|jj|�rDt|j|j|�S|jdkr`|j�n||jkr�|jj |jd|fi�}|St
|��dS(Nu__getattribute__(u_RPCProxy__methodsuNoneu_RPCProxy__getmethodsugetuMethodProxyusockiouoidu_RPCProxy__attributesu_RPCProxy__getattributesu
remotecalluAttributeError(uselfunameuvalue((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__getattr__*s
uRPCProxy.__getattr__cCs%|jj|jdfi�|_dS(Nu__attributes__(usockiou
remotecalluoidu_RPCProxy__attributes(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__getattributes8suRPCProxy.__getattributescCs%|jj|jdfi�|_dS(Nu__methods__(usockiou
remotecalluoidu_RPCProxy__methods(uself((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__getmethods<suRPCProxy.__getmethodsN(
u__name__u
__module__u__qualname__uNoneu_RPCProxy__methodsu_RPCProxy__attributesu__init__u__getattr__u_RPCProxy__getattributesu_RPCProxy__getmethods(u
__locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuRPCProxy!suRPCProxycCsvx<t|�D].}t||�}t|�r
d||<q
q
Wt|t�rrx!|jD]}t||�qXWndS(Ni(udirugetattrucallableu
isinstanceutypeu __bases__u_getmethods(uobjumethodsunameuattrusuper((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu_getmethods@su_getmethodscCsCx<t|�D].}t||�}t|�s
d||<q
q
WdS(Ni(udirugetattrucallable(uobju
attributesunameuattr((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu_getattributesKsu_getattributescBs,|EeZdZdd�Zdd�ZdS(uMethodProxycCs||_||_||_dS(N(usockiouoiduname(uselfusockiouoiduname((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__init__Ss uMethodProxy.__init__cOs%|jj|j|j||�}|S(N(usockiou
remotecalluoiduname(uselfuargsukwargsuvalue((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu__call__Xs!uMethodProxy.__call__N(u__name__u
__module__u__qualname__u__init__u__call__(u
__locals__((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyuMethodProxyQsuMethodProxycCs�|dkrdSdt_t|�}ytjj|�WnLtk
r�d}|j|d�}|j |d�}tjj|�YnXtjjd�|t_dS(u9Override standard display hook to use non-locale encodingNuasciiubackslashreplaceustrictu
(
uNoneubuiltinsu_ureprusysustdoutuwriteuUnicodeEncodeErroruencodeudecode(uvalueutextuencodingubytes((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyudisplayhook`s
udisplayhook('u__doc__usysuosusocketuselectusocketserverustructupickleu threadinguqueueu tracebackucopyregutypesumarshalubuiltinsu
unpickle_codeupickle_codeuCodeTypeuBUFSIZEu LOCALHOSTu TCPServeru RPCServeruobjecttableuQueueu
request_queueuresponse_queueuobjectuSocketIOuRemoteObjectu remoterefuRemoteProxyuBaseRequestHandleru
RPCHandleru RPCClientuRPCProxyu_getmethodsu_getattributesuMethodProxyudisplayhook(((u0/opt/alt/python33/lib64/python3.3/idlelib/rpc.pyu<module>sF
2�m
?>