Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib64/python3.7/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/idlelib/__pycache__/rpc.cpython-37.opt-1.pyc

B

� f�R�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZdd�Zdd�Zd*dd�ZGd	d
�d
ej�ZdZdZGd
d�de
j�ZiZe�d�Ze�d�ZGdd�de�ZGdd�de�Zdd�Z Gdd�de�Z!Gdd�de
j"e�Z#Gdd�de�Z$Gdd�de�Z%dd�Z&dd �Z'Gd!d"�d"e�Z(d#d$�Z)e*d%k�r�dd&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.)�marshal�loads)�ms�co�r�0/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.)r�dumpsr)rrrrr�pickle_code3s
r
cCs$t��}t||�}|�|�|��S)z.Return pickled (or marshalled) string for obj.)�io�BytesIO�CodePickler�dump�getvalue)�objZprotocol�f�prrrr	9s

r	c@s"eZdZejeiZe�ej�dS)r
N)	�__name__�
__module__�__qualname__�types�CodeTyper
�dispatch_table�update�copyregrrrrr
Bs
r
i z	127.0.0.1c@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�	RPCServerNcCs |dkrt}tj�|||�dS)N)�
RPCHandler�socketserver�	TCPServer�__init__)�self�addrZhandlerclassrrrrLszRPCServer.__init__cCsdS)z@Override TCPServer method, no bind() phase for connecting entityNr)r rrr�server_bindQszRPCServer.server_bindcCs|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 rrr�server_activateUszRPCServer.server_activatecCs|j|jfS)z:Override TCPServer method, return already connected socket)r#r$)r rrr�get_request^szRPCServer.get_requestcCs�y�Wn�tk
r�Yn�tj}td|d�td|d�tdt��j|d�td||d�tdt|�|d�tj	|d�td|d�td|d�t
�d	�YnXd
S)z�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.

        z)
----------------------------------------)�filezUnhandled server exception!z
Thread: %szClient Address: z	Request: z#
*** Unrecoverable, server exiting!z(----------------------------------------rN)�
SystemExit�sys�
__stderr__�print�	threading�current_thread�name�repr�	traceback�	print_exc�os�_exit)r �requestZclient_addressZerfrrr�handle_errorbszRPCServer.handle_error)N)rrrrr"r%r&r5rrrrrJs

	rc@s�eZdZdZd;dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+Zd,ZdZd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!dS)<�SocketIOrNcCs@t��|_|dk	r||_||_|dkr*t}||_i|_i|_dS)N)	r,r-�
sockthread�	debugging�sock�objecttable�objtable�	responses�cvars)r r9r;r8rrrr�s
zSocketIO.__init__cCs |j}d|_|dk	r|��dS)N)r9�close)r r9rrrr>�szSocketIO.closecCst�d�dS)z!override for specific exit actionrN)r2r3)r rrr�exithook�szSocketIO.exithookcGsR|js
dS|jdtt��j�}x|D]}|dt|�}q(Wt|tjd�dS)N� )r')	r8�location�strr,r-r.r+r)r*)r �args�s�arrr�debug�s
zSocketIO.debugcCs||j|<dS)N)r;)r �oid�objectrrr�register�szSocketIO.registercCs&y|j|=Wntk
r YnXdS)N)r;�KeyError)r rGrrr�
unregister�szSocketIO.unregisterc
Cs�|�d|�y|\}\}}}}Wntk
r4dSX||jkrNdd|ffS|j|}|dkrvi}	t||	�d|	fS|dkr�i}
t||
�d|
fSt||�s�dd|ffSt||�}y^|d	kr�|||�}t|t�r�t	|�}d|fS|d
k�rt
�||||ff�dSdd|fSWn�tk
�r,�Yn�t
k
�rB�Ynptk
�rX�YnZtk
�r~}
zd
|
fSd}
~
XYn4d}t||||ftjd�tjtjd�dSdS)Nz
localcall:)�ERRORzBad request formatrLzUnknown object id: %r�__methods__�OK�__attributes__zUnsupported method name: %r�CALL�QUEUE)�QUEUEDNzUnsupported message type: %s�CALLEXCzU*** Internal Error: rpc.py:SocketIO.localcall()

 Object: %s 
 Method: %s 
 Args: %s
)r')�	EXCEPTIONN)rF�	TypeErrorr;�_getmethods�_getattributes�hasattr�getattr�
isinstance�RemoteObject�	remoteref�
request_queueZputr(�KeyboardInterrupt�OSError�	Exceptionr+r)r*r0r1)r �seqr4�howrG�
methodnamerC�kwargsr�methods�
attributes�methodZretZex�msgrrr�	localcall�sT








zSocketIO.localcallcCs(|�d||�|�||||�}|�|�S)Nzremotecall:asynccall: )rF�	asynccall�asyncreturn)r rGrcrCrdrarrr�
remotecall�szSocketIO.remotecallcCs(|�d||�|�||||�}|�|�S)Nzremotequeue:asyncqueue: )rF�
asyncqueuerk)r rGrcrCrdrarrr�remotequeue�szSocketIO.remotequeuecCs`d||||ff}|��}t��|jkr8t��}||j|<|�d|||||�|�||f�|S)NrPz
asynccall:%d:)�newseqr,r-r7�	Conditionr=rF�
putmessage)r rGrcrCrdr4ra�cvarrrrrj�s
zSocketIO.asynccallcCs`d||||ff}|��}t��|jkr8t��}||j|<|�d|||||�|�||f�|S)NrQzasyncqueue:%d:)ror,r-r7rpr=rFrq)r rGrcrCrdr4rarrrrrrm�s
zSocketIO.asyncqueuecCs6|�d|�|j|dd�}|�d||�|�|�S)Nz#asyncreturn:%d:call getresponse(): g�������?)�waitzasyncreturn:%d:response: )rF�getresponse�decoderesponse)r ra�responserrrrk�szSocketIO.asyncreturncCs�|\}}|dkr|S|dkr dS|dkr6|�d�dS|dkrT|�d�|��dS|dkrp|�d|�t|��|d	kr�|�d
|�|�t||��dS)NrNrRrTzdecoderesponse: EXCEPTION�EOFzdecoderesponse: EOFrLzdecoderesponse: Internal ERROR:rSzdecoderesponse: Call Exception:)rF�decode_interrupthook�RuntimeError�SystemError)r rvrb�whatrrrru�s&

zSocketIO.decoderesponsecCst�dS)�N)�EOFError)r rrrrxszSocketIO.decode_interrupthookcCs6y|jddd�Wntk
r0|�d�dSXdS)z�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.

        Ng�������?)�myseqrszmainloop:return)rtr}rF)r rrr�mainloops

zSocketIO.mainloopcCs6|�||�}|dk	r2|\}}|dkr2||�|�f}|S)NrN)�_getresponse�_proxify)r r~rsrvrbr{rrrrt#szSocketIO.getresponsecCs4t|t�rt||j�St|t�r0tt|j|��S|S)N)rZ�RemoteProxy�RPCProxyrG�list�mapr�)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<rs�release)r r~rsrvrrrrrr�3s"


zSocketIO._getresponsecCs|jd|_}|S)N�)�nextseq)r rarrrroIszSocketIO.newseqc	Cs�|�d|d�yt|�}Wn,tjk
rJtdt|�tjd��YnXt�	dt
|��|}xnt
|�dkr�y0t�g|jgg�\}}}|j�
|dt��}Wn ttfk
r�td��YnX||d�}qbWdS)Nzputmessage:%d:rzCannot pickle:)r'z<izsocket no longer exists)rFr	�pickleZ
PicklingErrorr+r/r)r*�structZpack�len�selectr9�send�BUFSIZE�AttributeErrorrUr_)r �messagerD�r�w�x�nrrrrqMszSocketIO.putmessage��cCs�|��t|j�|jkr�t�|j��ggg|�\}}}t|�dkrFdSy|j�t�}Wnt	k
rnt
�YnXt|�dkr�t
�|j|7_|��|��S)Nr)�_stage0r��buff�bufneedr�r9�filenoZrecvr�r_r}�_stage1)r rsr�r�r�rDrrr�
pollpacketas
zSocketIO.pollpacketcCsR|jdkrNt|j�dkrN|jdd�}|jdd�|_t�d|�d|_d|_dS)Nrr�z<i�)�bufstater�r�r�Zunpackr�)r rDrrrr�qs
zSocketIO._stage0cCsP|jdkrLt|j�|jkrL|jd|j�}|j|jd�|_d|_d|_|SdS)Nr�r�r)r�r�r�r�)r �packetrrrr�xszSocketIO._stage1cCs�|�|�}|dkrdSyt�|�}WnVtjk
rztdtjd�tdt|�tjd�tj	tjd�tdtjd��YnX|S)Nz-----------------------)r'zcannot unpickle packet:)
r�r�rZUnpicklingErrorr+r)r*r/r0�print_stack)r rsr�r�rrr�pollmessage�s
zSocketIO.pollmessagec
Cs`�xXyt�d�}Wntjk
r(Yn X|\}}|d|ff}|�|�y|�|�}|dkr`dSWn.tk
r~|��dStk
r�dSX|\}}|d}|�	d||f�|dk�r|�	d|�|�
||�}|�	d||f�|dk�r|�||f�q|d	krqq||k�r|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_queue�get�queueZEmptyrqr�r}�
handle_EOFr�rFrir=r�r<�notifyr�)
r r~rsZqmsgrarvr�Zresqrb�cvrrrr��sL





zSocketIO.pollresponsecCsZ|��|�d�x:|jD]0}|j|}|��d|j|<|��|��qW|��dS)z+action taken upon link being closed by peerr�)rwNN)�EOFhookrFr=r�r<r�r�r?)r �keyr�rrrr��s


zSocketIO.handle_EOFcCsdS)zBClasses using rpc client/server can override to augment EOF actionNr)r rrrr��szSocketIO.EOFhook)NN)"rrrr�rr>r?rFrIrKrirlrnrjrmrkrurxrrtr�r�rorqr�r�r�r�r�r�r�r�r�r�rrrrr6�s>
.


I
r6c@seZdZdS)r[N)rrrrrrrr[�sr[cCst|�}|t|<t|�S)N)�idr:r�)rrGrrrr\�sr\c@seZdZdd�ZdS)r�cCs
||_dS)N)rG)r rGrrrr�szRemoteProxy.__init__N)rrrrrrrrr��sr�c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
rFz#ScCs(||_t�||�tj�||||�dS)N)Zcurrent_handlerr6rr�BaseRequestHandler)r r9r!ZsvrrrrrszRPCHandler.__init__cCs|��dS)z(handle() method required by socketserverN)r)r rrr�handleszRPCHandler.handlecCs
t||�S)N)r�)r rGrrr�get_remote_proxy	szRPCHandler.get_remote_proxyN)rrrr8rArr�r�rrrrr�s
rc@s:eZdZdZdZdZejejfdd�Z	dd�Z
dd	�Zd
S)�	RPCClientFz#Cr�cCs*t�||�|_|j�|�|j�d�dS)Nr�)r#�listening_sockZbindZlisten)r �addressZfamily�typerrrrszRPCClient.__init__cCsV|j��\}}|jr$td|tjd�|dtkr>t�||�ntd|tjd�t	�dS)Nz****** Connection request from )r'rz** Invalid host: )
r��acceptr8r+r)r*�	LOCALHOSTr6rr_)r Zworking_sockr�rrrr�szRPCClient.acceptcCs
t||�S)N)r�)r rGrrrr�#szRPCClient.get_remote_proxyN)rrrr8rAr�r#ZAF_INETZSOCK_STREAMrr�r�rrrrr�
s
r�c@s4eZdZdZdZdd�Zdd�Zdd�Zdd	�ZdS)
r�NcCs||_||_dS)N)�sockiorG)r r�rGrrrr,szRPCProxy.__init__cCsp|jdkr|��|j�|�r.t|j|j|�S|jdkr@|��||jkrd|j�|jd|fi�}|St	|��dS)N�__getattribute__)
�_RPCProxy__methods�_RPCProxy__getmethodsr��MethodProxyr�rG�_RPCProxy__attributes�_RPCProxy__getattributesrlr�)r r.�valuerrr�__getattr__0s



zRPCProxy.__getattr__cCs|j�|jddi�|_dS)NrOr)r�rlrGr�)r rrrZ__getattributes>s
zRPCProxy.__getattributescCs|j�|jddi�|_dS)NrMr)r�rlrGr�)r rrrZ__getmethodsBs
zRPCProxy.__getmethods)	rrrr�r�rr�r�r�rrrrr�'sr�cCsTx*t|�D]}t||�}t|�r
d||<q
Wt|t�rPx|jD]}t||�q>WdS)Nr�)�dirrY�callablerZr��	__bases__rV)rrer.�attr�superrrrrVFs

rVcCs0x*t|�D]}t||�}t|�s
d||<q
WdS)Nr�)r�rYr�)rrfr.r�rrrrWQs
rWc@seZdZdd�Zdd�ZdS)r�cCs||_||_||_dS)N)r�rGr.)r r�rGr.rrrrZszMethodProxy.__init__cOs|j�|j|j||�}|S)N)r�rlrGr.)r rCrdr�rrr�__call___szMethodProxy.__call__N)rrrrr�rrrrr�Xsr�cCs~|dkrdSdt_t|�}ytj�|�Wn<tk
rfd}|�|d�}|�|d�}tj�|�YnXtj�d�|t_dS)z9Override standard display hook to use non-locale encodingN�ascii�backslashreplace�strict�
)	�builtins�_r/r)�stdout�write�UnicodeEncodeError�encode�decode)r��text�encoding�bytesrrr�displayhookgsr��__main__)�mainzidlelib.idle_test.test_rpcr�)�	verbosity)N)-�__doc__r�rrrr2r�r�r�r#rr�r)r,r0rrr
r	ZPicklerr
r�r�rrr:ZQueuer]r�rHr6r[r\r�r�rr�r�rVrWr�r�rZunittestr�rrrr�<module>sR
	2

k


Hacked By AnonymousFox1.0, Coded By AnonymousFox