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.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�|�}t|tj�st�|S)z*Return code object from marshal string ms.)�marshal�loads�
isinstance�types�CodeType�AssertionError)�ms�co�r
�0/opt/alt/python37/lib64/python3.7/idlelib/rpc.py�
unpickle_code-s
rcCs$t|tj�st�t�|�}t|ffS)zBReturn unpickle function and tuple with marshalled co code object.)rrrrr�dumpsr)r	rr
r
r�pickle_code3s
rcCs$t��}t||�}|�|�|��S)z.Return pickled (or marshalled) string for obj.)�io�BytesIO�CodePickler�dump�getvalue)�objZprotocol�f�pr
r
rr
9s

r
c@s"eZdZejeiZe�ej�dS)rN)	�__name__�
__module__�__qualname__rrr�dispatch_table�update�copyregr
r
r
rrBs
ri 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handlerclassr
r
rr!LszRPCServer.__init__cCsdS)z@Override TCPServer method, no bind() phase for connecting entityNr
)r"r
r
r�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"r
r
r�server_activateUszRPCServer.server_activatecCs|j|jfS)z:Override TCPServer method, return already connected socket)r%r&)r"r
r
r�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_addressZerfr
r
r�handle_errorbszRPCServer.handle_error)N)rrrr!r$r'r(r7r
r
r
rrJs

	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"r;r=r:r
r
rr!�s
zSocketIO.__init__cCs |j}d|_|dk	r|��dS)N)r;�close)r"r;r
r
rr@�szSocketIO.closecCst�d�dS)z!override for specific exit actionrN)r4r5)r"r
r
r�exithook�szSocketIO.exithookcGsR|js
dS|jdtt��j�}x|D]}|dt|�}q(Wt|tjd�dS)N� )r))	r:�location�strr.r/r0r-r+r,)r"�args�s�ar
r
r�debug�s
zSocketIO.debugcCs||j|<dS)N)r=)r"�oid�objectr
r
r�register�szSocketIO.registercCs&y|j|=Wntk
r YnXdS)N)r=�KeyError)r"rIr
r
r�
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 formatrNzUnknown 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)rH�	TypeErrorr=�_getmethods�_getattributes�hasattr�getattrr�RemoteObject�	remoteref�
request_queueZputr*�KeyboardInterrupt�OSError�	Exceptionr-r+r,r2r3)r"�seqr6�howrI�
methodnamerE�kwargsr�methods�
attributes�methodZretZex�msgr
r
r�	localcall�sT








zSocketIO.localcallcCs(|�d||�|�||||�}|�|�S)Nzremotecall:asynccall: )rH�	asynccall�asyncreturn)r"rIrdrErerbr
r
r�
remotecall�szSocketIO.remotecallcCs(|�d||�|�||||�}|�|�S)Nzremotequeue:asyncqueue: )rH�
asyncqueuerl)r"rIrdrErerbr
r
r�remotequeue�szSocketIO.remotequeuecCs`d||||ff}|��}t��|jkr8t��}||j|<|�d|||||�|�||f�|S)NrRz
asynccall:%d:)�newseqr.r/r9�	Conditionr?rH�
putmessage)r"rIrdrErer6rb�cvarr
r
rrk�s
zSocketIO.asynccallcCs`d||||ff}|��}t��|jkr8t��}||j|<|�d|||||�|�||f�|S)NrSzasyncqueue:%d:)rpr.r/r9rqr?rHrr)r"rIrdrErer6rbrsr
r
rrn�s
zSocketIO.asyncqueuecCs6|�d|�|j|dd�}|�d||�|�|�S)Nz#asyncreturn:%d:call getresponse(): g�������?)�waitzasyncreturn:%d:response: )rH�getresponse�decoderesponse)r"rb�responser
r
rrl�szSocketIO.asyncreturncCs�|\}}|dkr|S|dkr dS|dkr6|�d�dS|dkrT|�d�|��dS|dkrp|�d|�t|��|d	kr�|�d
|�|�t||��dS)NrPrTrVzdecoderesponse: EXCEPTION�EOFzdecoderesponse: EOFrNzdecoderesponse: Internal ERROR:rUzdecoderesponse: Call Exception:)rH�decode_interrupthook�RuntimeError�SystemError)r"rwrc�whatr
r
rrv�s&

zSocketIO.decoderesponsecCst�dS)�N)�EOFError)r"r
r
rryszSocketIO.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�������?)�myseqrtzmainloop:return)rur~rH)r"r
r
r�mainloops

zSocketIO.mainloopcCs6|�||�}|dk	r2|\}}|dkr2||�|�f}|S)NrP)�_getresponse�_proxify)r"rrtrwrcr|r
r
rru#szSocketIO.getresponsecCs4t|t�rt||j�St|t�r0tt|j|��S|S)N)r�RemoteProxy�RPCProxyrI�list�mapr�)r"rr
r
rr�+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)
rHr.r/r9�pollresponser?�acquirer>rt�release)r"rrtrwrsr
r
rr�3s"


zSocketIO._getresponsecCs|jd|_}|S)N�)�nextseq)r"rbr
r
rrpIszSocketIO.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)rHr
�pickleZ
PicklingErrorr-r1r+r,�structZpack�len�selectr;�send�BUFSIZE�AttributeErrorrWr`)r"�messagerF�r�w�x�nr
r
rrrMs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�r;�filenoZrecvr�r`r~�_stage1)r"rtr�r�r�rFr
r
r�
pollpacketas
zSocketIO.pollpacketcCsR|jdkrNt|j�dkrN|jdd�}|jdd�|_t�d|�d|_d|_dS)Nrr�z<i�)�bufstater�r�r�Zunpackr�)r"rFr
r
rr�qs
zSocketIO._stage0cCsP|jdkrLt|j�|jkrL|jd|j�}|j|jd�|_d|_d|_|SdS)Nr�r�r)r�r�r�r�)r"�packetr
r
rr�xszSocketIO._stage1cCs�|�|�}|dkrdSyt�|�}WnVtjk
rztdtjd�tdt|�tjd�tj	tjd�tdtjd��YnX|S)Nz-----------------------)r)zcannot unpickle packet:)
r�r�rZUnpicklingErrorr-r+r,r1r2�print_stack)r"rtr�r�r
r
r�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.

        rrPNzpollresponse:%d:myseq:%s)rRrSzpollresponse:%d:localcall:call:z%pollresponse:%d:localcall:response:%srRrS)�response_queue�get�queueZEmptyrrr�r~�
handle_EOFr�rHrjr?r�r>�notifyr�)
r"rrtZqmsgrbrwr�Zresqrc�cvr
r
rr��sL





zSocketIO.pollresponsecCsZ|��|�d�x:|jD]0}|j|}|��d|j|<|��|��qW|��dS)z+action taken upon link being closed by peerr�)rxNN)�EOFhookrHr?r�r>r�r�rA)r"�keyr�r
r
rr��s


zSocketIO.handle_EOFcCsdS)zBClasses using rpc client/server can override to augment EOF actionNr
)r"r
r
rr��szSocketIO.EOFhook)NN)"rrrr�r!r@rArHrKrMrjrmrorkrnrlrvryr�rur�r�rprrr�r�r�r�r�r�r�r�r�r�r
r
r
rr8�s>
.


I
r8c@seZdZdS)r\N)rrrr
r
r
rr\�sr\cCst|�}|t|<t|�S)N)�idr<r�)rrIr
r
rr]�sr]c@seZdZdd�ZdS)r�cCs
||_dS)N)rI)r"rIr
r
rr!�szRemoteProxy.__init__N)rrrr!r
r
r
rr��sr�c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
rFz#ScCs(||_t�||�tj�||||�dS)N)Zcurrent_handlerr8r!r�BaseRequestHandler)r"r;r#Zsvrr
r
rr!szRPCHandler.__init__cCs|��dS)z(handle() method required by socketserverN)r�)r"r
r
r�handleszRPCHandler.handlecCs
t||�S)N)r�)r"rIr
r
r�get_remote_proxy	szRPCHandler.get_remote_proxyN)rrrr:rCr!r�r�r
r
r
rr�s
rc@s:eZdZdZdZdZejejfdd�Z	dd�Z
dd	�Zd
S)�	RPCClientFz#Cr�cCs*t�||�|_|j�|�|j�d�dS)Nr�)r%�listening_sockZbindZlisten)r"�addressZfamily�typer
r
rr!szRPCClient.__init__cCsV|j��\}}|jr$td|tjd�|dtkr>t�||�ntd|tjd�t	�dS)Nz****** Connection request from )r)rz** Invalid host: )
r��acceptr:r-r+r,�	LOCALHOSTr8r!r`)r"Zworking_sockr�r
r
rr�szRPCClient.acceptcCs
t||�S)N)r�)r"rIr
r
rr�#szRPCClient.get_remote_proxyN)rrrr:rCr�r%ZAF_INETZSOCK_STREAMr!r�r�r
r
r
rr�
s
r�c@s4eZdZdZdZdd�Zdd�Zdd�Zdd	�ZdS)
r�NcCs||_||_dS)N)�sockiorI)r"r�rIr
r
rr!,szRPCProxy.__init__cCsp|jdkr|��|j�|�r.t|j|j|�S|jdkr@|��||jkrd|j�|jd|fi�}|St	|��dS)N�__getattribute__)
�_RPCProxy__methods�_RPCProxy__getmethodsr��MethodProxyr�rI�_RPCProxy__attributes�_RPCProxy__getattributesrmr�)r"r0�valuer
r
r�__getattr__0s



zRPCProxy.__getattr__cCs|j�|jddi�|_dS)NrQr
)r�rmrIr�)r"r
r
rZ__getattributes>s
zRPCProxy.__getattributescCs|j�|jddi�|_dS)NrOr
)r�rmrIr�)r"r
r
rZ__getmethodsBs
zRPCProxy.__getmethods)	rrrr�r�r!r�r�r�r
r
r
rr�'sr�cCsTx*t|�D]}t||�}t|�r
d||<q
Wt|t�rPx|jD]}t||�q>WdS)Nr�)�dirr[�callablerr��	__bases__rX)rrfr0�attr�superr
r
rrXFs

rXcCs0x*t|�D]}t||�}t|�s
d||<q
WdS)Nr�)r�r[r�)rrgr0r�r
r
rrYQs
rYc@seZdZdd�Zdd�ZdS)r�cCs||_||_||_dS)N)r�rIr0)r"r�rIr0r
r
rr!ZszMethodProxy.__init__cOs|j�|j|j||�}|S)N)r�rmrIr0)r"rErer�r
r
r�__call___szMethodProxy.__call__N)rrrr!r�r
r
r
rr�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�_r1r+�stdout�write�UnicodeEncodeError�encode�decode)r��text�encoding�bytesr
r
r�displayhookgsr��__main__)�mainzidlelib.idle_test.test_rpcr�)�	verbosity)N)-�__doc__r�rrrr4r�r�r�r%rr�r+r.r2rrrr
ZPicklerrr�r�r rr<ZQueuer^r�rJr8r\r]r�r�rr�r�rXrYr�r�rZunittestr�r
r
r
r�<module>sR
	2

k


Hacked By AnonymousFox1.0, Coded By AnonymousFox