ok

Mini Shell

Direktori : /opt/alt/python36/lib64/python3.6/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/idlelib/__pycache__/rpc.cpython-36.opt-2.pyc

3

��2a�R�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZdd�Zdd�Zd*dd�ZGdd	�d	ej�Zd+ZdZGd
d�de	j�ZiZejd�Zejd�ZGdd�de�ZGdd�de�Zdd�ZGdd�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),�NcCstj|�}|S)N)�marshal�loads)�ms�co�r�(/opt/alt/python36/lib64/python3.6/rpc.py�
unpickle_code-s
rcCstj|�}t|ffS)N)r�dumpsr)rrrrr�pickle_code3s
r
cCs$tj�}t||�}|j|�|j�S)N)�io�BytesIO�CodePickler�dump�getvalue)�objZprotocol�f�prrrr	9s

r	c@s"eZdZejeiZejej�dS)r
N)	�__name__�
__module__�__qualname__�types�CodeTyper
�dispatch_table�update�copyregrrrrr
Bs
r
�iz	127.0.0.1c@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�	RPCServerNcCs |dkrt}tjj|||�dS)N)�
RPCHandler�socketserver�	TCPServer�__init__)�self�addrZhandlerclassrrrr LszRPCServer.__init__cCsdS)Nr)r!rrr�server_bindQszRPCServer.server_bindcCs|jj|j�dS)N)�socketZconnect�server_address)r!rrr�server_activateUszRPCServer.server_activatecCs|j|jfS)N)r$r%)r!rrr�get_request^szRPCServer.get_requestcCs�y�Wn�tk
r�Yn�tj}tddd|d�td|d�tdtj�j|d�td||d�tdt|�|d�tj	|d�td	|d�tdd|d�t
jd
�YnXdS)N�
�-�()�filezUnhandled server exception!z
Thread: %szClient Address: z	Request: z#
*** Unrecoverable, server exiting!r)�
SystemExit�sys�
__stderr__�print�	threading�current_thread�name�repr�	traceback�	print_exc�os�_exit)r!�requestZclient_addressZerfrrr�handle_errorbszRPCServer.handle_error)N)rrrr r#r&r'r9rrrrrJs

	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@tj�|_|dk	r||_||_|dkr*t}||_i|_i|_dS)N)	r0r1�
sockthread�	debugging�sock�objecttable�objtable�	responses�cvars)r!r=r?r<rrrr �s
zSocketIO.__init__cCs |j}d|_|dk	r|j�dS)N)r=�close)r!r=rrrrB�szSocketIO.closecCstjd�dS)Nr)r6r7)r!rrr�exithook�szSocketIO.exithookcGsR|js
dS|jdttj�j�}x|D]}|dt|�}q(Wt|tjd�dS)N� )r+)	r<�location�strr0r1r2r/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!rKrrr�
unregister�szSocketIO.unregistercCs�|jd|�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
j||||ff�dSdd|fSWn�tk
�r,�Yn�t
k
�rB�Ynntk
�rX�YnXtk
�r|}
zd
|
fSd}
~
Xn4d}t||||ftjd�tjtjd�dSdS)Nz
localcall:�ERROR�Bad request formatzUnknown object id: %r�__methods__�OK�__attributes__zUnsupported method name: %r�CALL�QUEUE�QUEUEDzUnsupported message type: %s�CALLEXCzU*** Internal Error: rpc.py:SocketIO.localcall()

 Object: %s 
 Method: %s 
 Args: %s
)r+�	EXCEPTION)rPrQ)rWN)rYN)rJ�	TypeErrorr?�_getmethods�_getattributes�hasattr�getattr�
isinstance�RemoteObject�	remoteref�
request_queueZputr,�KeyboardInterrupt�OSError�	Exceptionr/r-r.r4r5)r!�seqr8�howrK�
methodnamerG�kwargsr�methods�
attributes�method�retZex�msgrrr�	localcall�sT








zSocketIO.localcallcCs(|jd||�|j||||�}|j|�S)Nzremotecall:asynccall: )rJ�	asynccall�asyncreturn)r!rKrhrGrirfrrr�
remotecall�szSocketIO.remotecallcCs(|jd||�|j||||�}|j|�S)Nzremotequeue:asyncqueue: )rJ�
asyncqueuerq)r!rKrhrGrirfrrr�remotequeue�szSocketIO.remotequeuecCs`d||||ff}|j�}tj�|jkr8tj�}||j|<|jd|||||�|j||f�|S)NrUz
asynccall:%d:)�newseqr0r1r;�	ConditionrArJ�
putmessage)r!rKrhrGrir8rf�cvarrrrrp�s
zSocketIO.asynccallcCs`d||||ff}|j�}tj�|jkr8tj�}||j|<|jd|||||�|j||f�|S)NrVzasyncqueue:%d:)rur0r1r;rvrArJrw)r!rKrhrGrir8rfrxrrrrs�s
zSocketIO.asyncqueuecCs6|jd|�|j|dd�}|jd||�|j|�S)Nz#asyncreturn:%d:call getresponse(): g�������?)�waitzasyncreturn:%d:response: )rJ�getresponse�decoderesponse)r!rf�responserrrrq�szSocketIO.asyncreturncCs�|\}}|dkr|S|dkr dS|dkr6|jd�dS|dkrT|jd�|j�dS|dkrp|jd|�t|��|d	kr�|jd
|�|�t||��dS)NrSrWrYzdecoderesponse: EXCEPTION�EOFzdecoderesponse: EOFrPzdecoderesponse: Internal ERROR:rXzdecoderesponse: Call Exception:)rJ�decode_interrupthook�RuntimeError�SystemError)r!r|rg�whatrrrr{�s&

zSocketIO.decoderesponsecCst�dS)N)�EOFError)r!rrrr~szSocketIO.decode_interrupthookcCs6y|jddd�Wntk
r0|jd�dSXdS)Ng�������?)�myseqryzmainloop:return)rzr�rJ)r!rrr�mainloops

zSocketIO.mainloopcCs6|j||�}|dk	r2|\}}|dkr2||j|�f}|S)NrS)�_getresponse�_proxify)r!r�ryr|rgr�rrrrz#szSocketIO.getresponsecCs4t|t�rt||j�St|t�r0tt|j|��S|S)N)r_�RemoteProxy�RPCProxyrK�list�mapr�)r!rrrrr�+s


zSocketIO._proxifycCs�|jd|�tj�|jkr:x�|j||�}|dk	r|SqWnb|j|}|j�x||jkrb|j�qNW|j|}|jd||f�|j|=|j|=|j	�|SdS)Nz_getresponse:myseq:z-_getresponse:%s: thread woke up: response: %s)
rJr0r1r;�pollresponserA�acquirer@ry�release)r!r�ryr|rxrrrr�3s"


zSocketIO._getresponsecCs|jd|_}|S)N�)�nextseq)r!rfrrrruIszSocketIO.newseqcCs�|jd|d�yt|�}Wn,tjk
rJtdt|�tjd��YnXtj	dt
|��|}xnt
|�dkr�y0tjg|jgg�\}}}|jj
|dt��}Wn ttfk
r�td��YnX||d�}qbWdS)Nzputmessage:%d:rzCannot pickle:)r+z<izsocket no longer exists)rJr	�pickleZ
PicklingErrorr/r3r-r.�struct�pack�len�selectr=�send�BUFSIZE�AttributeErrorrZrd)r!�messagerH�r�w�x�nrrrrwMszSocketIO.putmessage��cCs�|j�t|j�|jkr�tj|jj�ggg|�\}}}t|�dkrFdSy|jjt�}Wnt	k
rnt
�YnXt|�dkr�t
�|j|7_|j�|j�S)Nr)�_stage0r��buff�bufneedr�r=�filenoZrecvr�rdr��_stage1)r!ryr�r�r�rHrrr�
pollpacketas
zSocketIO.pollpacketcCsR|jdkrNt|j�dkrN|jdd�}|jdd�|_tjd|�d|_d|_dS)Nrr�z<i�)�bufstater�r�r��unpackr�)r!rHrrrr�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�|j|�}|dkrdSytj|�}WnVtjk
rztdtjd�tdt|�tjd�tj	tjd�tdtjd��YnX|S)Nz-----------------------)r+zcannot unpickle packet:)
r�r�rZUnpicklingErrorr/r-r.r3r4�print_stack)r!ryr�r�rrr�pollmessage�s
zSocketIO.pollmessagec
Cs`�xXytjd�}Wntjk
r(Yn X|\}}|d|ff}|j|�y|j|�}|dkr`dSWn.tk
r~|j�dStk
r�dSX|\}}|d}|j	d||f�|dk�r|j	d|�|j
||�}|j	d||f�|dk�r|j||f�q|dkrqq||k�r|S|jj|d�}	|	dk	r|	j�||j
|<|	j�|	j�qqWdS)	NrrSzpollresponse:%d:myseq:%srUrVzpollresponse:%d:localcall:call:z%pollresponse:%d:localcall:response:%s)rUrV)�response_queue�get�queueZEmptyrwr�r��
handle_EOFr�rJrorAr�r@�notifyr�)
r!r�ryZqmsgrfr|r�Zresqrg�cvrrrr��sL





zSocketIO.pollresponsecCsZ|j�|jd�x:|jD]0}|j|}|j�d|j|<|j�|j�qW|j�dS)Nr�r})r}N)�EOFhookrJrAr�r@r�r�rC)r!�keyr�rrrr��s


zSocketIO.handle_EOFcCsdS)Nr)r!rrrr��szSocketIO.EOFhook)NN)"rrrr�r rBrCrJrMrOrorrrtrprsrqr{r~r�rzr�r�rurwr�r�r�r�r�r�r�r�r�r�rrrrr:�s>
.


I
r:c@seZdZdS)r`N)rrrrrrrr`�sr`cCst|�}|t|<t|�S)N)�idr>r�)rrKrrrra�srac@seZdZdd�ZdS)r�cCs
||_dS)N)rK)r!rKrrrr �szRemoteProxy.__init__N)rrrr rrrrr��sr�c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
rFz#ScCs(||_tj||�tjj||||�dS)N)Zcurrent_handlerr:r r�BaseRequestHandler)r!r=r"Zsvrrrrr szRPCHandler.__init__cCs|j�dS)N)r�)r!rrr�handleszRPCHandler.handlecCs
t||�S)N)r�)r!rKrrr�get_remote_proxy	szRPCHandler.get_remote_proxyN)rrrr<rEr r�r�rrrrr�s
rc@s:eZdZdZdZdZejejfdd�Z	dd�Z
dd	�Zd
S)�	RPCClientFz#Cr�cCs*tj||�|_|jj|�|jjd�dS)Nr�)r$�listening_sockZbindZlisten)r!�addressZfamily�typerrrr szRPCClient.__init__cCsV|jj�\}}|jr$td|tjd�|dtkr>tj||�ntd|tjd�t	�dS)Nz****** Connection request from )r+rz** Invalid host: )
r��acceptr<r/r-r.�	LOCALHOSTr:r rd)r!Zworking_sockr�rrrr�szRPCClient.acceptcCs
t||�S)N)r�)r!rKrrrr�#szRPCClient.get_remote_proxyN)rrrr<rEr�r$ZAF_INETZSOCK_STREAMr r�r�rrrrr�
s
r�c@s4eZdZdZdZdd�Zdd�Zdd�Zdd	�ZdS)
r�NcCs||_||_dS)N)�sockiorK)r!r�rKrrrr ,szRPCProxy.__init__cCsp|jdkr|j�|jj|�r.t|j|j|�S|jdkr@|j�||jkrd|jj|jd|fi�}|St	|��dS)N�__getattribute__)
�_RPCProxy__methods�_RPCProxy__getmethodsr��MethodProxyr�rK�_RPCProxy__attributes�_RPCProxy__getattributesrrr�)r!r2�valuerrr�__getattr__0s



zRPCProxy.__getattr__cCs|jj|jdfi�|_dS)NrT)r�rrrKr�)r!rrrZ__getattributes>s
zRPCProxy.__getattributescCs|jj|jdfi�|_dS)NrR)r�rrrKr�)r!rrrZ__getmethodsBs
zRPCProxy.__getmethods)	rrrr�r�r r�r�r�rrrrr�'sr�cCsTx*t|�D]}t||�}t|�r
d||<q
Wt|t�rPx|jD]}t||�q>WdS)Nr�)�dirr^�callabler_r��	__bases__r[)rrjr2�attr�superrrrr[Fs

r[cCs0x*t|�D]}t||�}t|�s
d||<q
WdS)Nr�)r�r^r�)rrkr2r�rrrr\Qs
r\c@seZdZdd�Zdd�ZdS)r�cCs||_||_||_dS)N)r�rKr2)r!r�rKr2rrrr ZszMethodProxy.__init__cOs|jj|j|j||�}|S)N)r�rrrKr2)r!rGrir�rrr�__call___szMethodProxy.__call__N)rrrr r�rrrrr�Xsr�cCs~|dkrdSdt_t|�}ytjj|�Wn<tk
rfd}|j|d�}|j|d�}tjj|�YnXtjjd�|t_dS)N�ascii�backslashreplace�strictr()	�builtins�_r3r-�stdout�write�UnicodeEncodeError�encode�decode)r��text�encoding�bytesrrr�displayhookgsr��__main__)�mainzidlelib.idle_test.test_rpcr�)�	verbosity)Ni ),r�rrrr6r�r�r�r$rr�r-r0r4rrr
r	ZPicklerr
r�r�rrr>ZQueuerbr�rLr:r`rar�r�rr�r�r[r\r�r�rZunittestr�rrrr�<module>sP
	2

k


Zerion Mini Shell 1.0