a �DOg�j�@s�dZddlZddlZddlZddlZddlZddlmZddlm Zgd�Z e ed�rde � gd��e ed�r|e � gd ��e ed �r�ej ZnejZGd d �d �ZGd d�de�ZGdd�de�Ze ed�r�Gdd�d�ZGdd�de�ZGdd�d�ZGdd�d�Ze ed��r6Gdd�dee�ZGdd�dee�ZGdd�dee�ZGdd �d ee�Ze ed��r�Gd!d"�d"e�ZGd#d$�d$e�ZGd%d&�d&ee�ZGd'd(�d(ee�ZGd)d*�d*�Z Gd+d,�d,e �Z!Gd-d.�d.e�Z"Gd/d0�d0e �Z#dS)1z0.4�N)�BufferedIOBase)� monotonic) � BaseServer� TCPServer� UDPServer�ThreadingUDPServer�ThreadingTCPServer�BaseRequestHandler�StreamRequestHandler�DatagramRequestHandler�ThreadingMixIn�fork)�ForkingUDPServer�ForkingTCPServer� ForkingMixIn�AF_UNIX)�UnixStreamServer�UnixDatagramServer�ThreadingUnixStreamServer�ThreadingUnixDatagramServer� PollSelectorc@s�eZdZdZdd�Zdd�Zd%dd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdS)&rNcCs ||_||_t��|_d|_dS�NF)�server_address�RequestHandlerClass� threading�Event�_BaseServer__is_shut_down�_BaseServer__shutdown_request)�selfrr�r�$/usr/lib64/python3.9/socketserver.py�__init__�s zBaseServer.__init__cCsdS�Nr�rrrr �server_activate�szBaseServer.server_activate��?cCs�|j��zvt��L}|�|tj�|jsP|�|�}|jr:qP|rF|��|� �q"Wd�n1sd0YWd|_|j� �nd|_|j� �0dSr) r�clear�_ServerSelector�register� selectors� EVENT_READr�select�_handle_request_noblock�service_actions�set)rZ poll_interval�selector�readyrrr � serve_forever�s  * �zBaseServer.serve_forevercCsd|_|j��dS�NT)rr�waitr#rrr �shutdown�szBaseServer.shutdowncCsdSr"rr#rrr r-�szBaseServer.service_actionscCs�|j��}|dur|j}n|jdur0t||j�}|durBt�|}t��t}|�|tj�|� |�}|r||� �Wd�S|durX|t�}|dkrX|� �Wd�SqXWd�n1s�0YdS)Nr) �socket� gettimeout�timeout�min�timer'r(r)r*r+r,�handle_timeout)rr7�deadliner/r0rrr �handle_requests       zBaseServer.handle_requestcCs�z|��\}}Wnty$YdS0|�||�r�z|�||�Wq�tyj|�||�|�|�Yq�|�|��Yq�0n |�|�dSr")� get_request�OSError�verify_request�process_request� Exception� handle_error�shutdown_request�r�request�client_addressrrr r,/s      z"BaseServer._handle_request_noblockcCsdSr"rr#rrr r:FszBaseServer.handle_timeoutcCsdSr2rrDrrr r?MszBaseServer.verify_requestcCs|�||�|�|�dSr")�finish_requestrCrDrrr r@Us zBaseServer.process_requestcCsdSr"rr#rrr � server_close^szBaseServer.server_closecCs|�|||�dSr")rrDrrr rGfszBaseServer.finish_requestcCs|�|�dSr"�� close_request�rrErrr rCjszBaseServer.shutdown_requestcCsdSr"rrKrrr rJnszBaseServer.close_requestcCs@tdtjd�td|tjd�ddl}|��tdtjd�dS)Nz(----------------------------------------)�filez4Exception occurred during processing of request fromr)�print�sys�stderr� traceback� print_exc)rrErFrPrrr rBrs�zBaseServer.handle_errorcCs|Sr"rr#rrr � __enter__szBaseServer.__enter__cGs |��dSr")rH)r�argsrrr �__exit__�szBaseServer.__exit__)r%)�__name__� __module__� __qualname__r7r!r$r1r4r-r<r,r:r?r@rHrGrCrJrBrRrTrrrr r�s$-    rc@sbeZdZejZejZdZdZ ddd�Z dd�Z dd �Z d d �Z d d �Zdd�Zdd�Zdd�ZdS)r�FTcCsTt�|||�t�|j|j�|_|rPz|��|��Wn|���Yn0dSr")rr!r5�address_family� socket_type� server_bindr$rH)rrrZbind_and_activaterrr r!�s� zTCPServer.__init__cCs8|jr|j�tjtjd�|j�|j�|j��|_dS)N�)�allow_reuse_addressr5� setsockopt� SOL_SOCKET� SO_REUSEADDR�bindr� getsocknamer#rrr r[�szTCPServer.server_bindcCs|j�|j�dSr")r5�listen�request_queue_sizer#rrr r$�szTCPServer.server_activatecCs|j��dSr")r5�closer#rrr rH�szTCPServer.server_closecCs |j��Sr")r5�filenor#rrr rf�szTCPServer.filenocCs |j��Sr")r5�acceptr#rrr r=�szTCPServer.get_requestcCs2z|�tj�Wnty"Yn0|�|�dSr")r4r5�SHUT_WRr>rJrKrrr rC�s  zTCPServer.shutdown_requestcCs |��dSr")rerKrrr rJ�szTCPServer.close_requestN)T)rUrVrWr5�AF_INETrY� SOCK_STREAMrZrdr]r!r[r$rHrfr=rCrJrrrr r�s/   rc@s:eZdZdZejZdZdd�Zdd�Z dd�Z d d �Z d S) rFi cCs |j�|j�\}}||jf|fSr")r5�recvfrom�max_packet_size)r�dataZ client_addrrrr r=szUDPServer.get_requestcCsdSr"rr#rrr r$szUDPServer.server_activatecCs|�|�dSr"rIrKrrr rCszUDPServer.shutdown_requestcCsdSr"rrKrrr rJszUDPServer.close_requestN) rUrVrWr]r5� SOCK_DGRAMrZrlr=r$rCrJrrrr rsrcsReZdZdZdZdZdZdd�dd�Zd d �Zd d �Z d d�Z �fdd�Z �Z S)ri,N�(TF��blockingc Cs�|jdurdSt|j�|jkrrz t�dd�\}}|j�|�WqtyZ|j��YqtynYqrYq0q|j� �D]b}z.|r�dntj }t�||�\}}|j�|�Wq|ty�|j�|�Yq|ty�Yq|0q|dS)N�����r) �active_children�len� max_children�os�waitpid�discard�ChildProcessErrorr&r>�copy�WNOHANG)rrq�pid�_�flagsrrr �collect_children(s&      zForkingMixIn.collect_childrencCs |��dSr"�rr#rrr r:KszForkingMixIn.handle_timeoutcCs |��dSr"r�r#rrr r-RszForkingMixIn.service_actionscCs�t��}|r8|jdurt�|_|j�|�|�|�dSd}z^z|�||�d}Wntyp|�||�Yn0Wz|� |�Wt� |�q�t� |�0n(z|� |�Wt� |�n t� |�00dS)Nr\r) rvr rsr.�addrJrGrArBrC�_exit)rrErFr|�statusrrr r@Ys&      � zForkingMixIn.process_requestcst���|j|jd�dS)Nrp)�superrHr�block_on_closer#�� __class__rr rHrs zForkingMixIn.server_close) rUrVrWr7rsrur�rr:r-r@rH� __classcell__rrr�r rs#rcs4eZdZ�fdd�Zdd�Zdd�Zdd�Z�ZS) �_Threadscs"|��|jrdSt��|�dSr")�reap�daemonr��append�r�threadr�rr r�{sz_Threads.appendcCsg|dd�|dd�<}|Sr"r)r�resultrrr �pop_all�sz_Threads.pop_allcCs|��D] }|��qdSr")r��joinr�rrr r��s z _Threads.joincCsdd�|D�|dd�<dS)Ncss|]}|��r|VqdSr")�is_alive)�.0r�rrr � ��z _Threads.reap..rr#rrr r��sz _Threads.reap)rUrVrWr�r�r�r�r�rrr�r r�ws r�c@seZdZdd�Zdd�ZdS)� _NoThreadscCsdSr"rr�rrr r��sz_NoThreads.appendcCsdSr"rr#rrr r��sz_NoThreads.joinN)rUrVrWr�r�rrrr r��sr�cs:eZdZdZdZe�Zdd�Zdd�Z�fdd�Z �Z S) r FTc CsPz>z|�||�Wnty0|�||�Yn0W|�|�n |�|�0dSr")rGrArBrCrDrrr �process_request_thread�s  z%ThreadingMixIn.process_request_threadcCsL|jrt|��dt��tj|j||fd�}|j|_|j � |�|� �dS)N�_threads)�targetrS) r��vars� setdefaultr�r�Threadr��daemon_threadsr�r�r��start)rrErF�trrr r@�s� zThreadingMixIn.process_requestcst���|j��dSr")r�rHr�r�r#r�rr rH�s zThreadingMixIn.server_close) rUrVrWr�r�r�r�r�r@rHr�rrr�r r �s   r c@s eZdZdS)rN�rUrVrWrrrr r�r�rc@s eZdZdS)rNr�rrrr r�r�rc@s eZdZdS)rNr�rrrr r�r�rc@s eZdZdS)rNr�rrrr r�r�rc@seZdZejZdS)rN�rUrVrWr5rrYrrrr r�src@seZdZejZdS)rNr�rrrr r�src@s eZdZdS)rNr�rrrr r�r�rc@s eZdZdS)rNr�rrrr r�r�rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) r cCs>||_||_||_|��z|��W|��n |��0dSr")rErF�server�setup�handle�finish)rrErFr�rrr r!�s zBaseRequestHandler.__init__cCsdSr"rr#rrr r��szBaseRequestHandler.setupcCsdSr"rr#rrr r��szBaseRequestHandler.handlecCsdSr"rr#rrr r��szBaseRequestHandler.finishN)rUrVrWr!r�r�r�rrrr r �s r c@s,eZdZdZdZdZdZdd�Zdd�ZdS) r rrrNFcCsz|j|_|jdur |j�|j�|jr:|j�tjtjd�|j� d|j �|_ |j dkrdt |j�|_n|j� d|j �|_dS)NT�rbr�wb)rE� connectionr7� settimeout�disable_nagle_algorithmr^r5� IPPROTO_TCP� TCP_NODELAY�makefile�rbufsize�rfile�wbufsize� _SocketWriter�wfiler#rrr r�s  � zStreamRequestHandler.setupcCsD|jjs,z|j��Wntjy*Yn0|j��|j��dSr")r��closed�flushr5�errorrer�r#rrr r�#s zStreamRequestHandler.finish) rUrVrWr�r�r7r�r�r�rrrr r s   r c@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) r�cCs ||_dSr")�_sock)r�sockrrr r!3sz_SocketWriter.__init__cCsdSr2rr#rrr �writable6sz_SocketWriter.writablecCs>|j�|�t|��}|jWd�S1s00YdSr")r��sendall� memoryview�nbytes)r�b�viewrrr �write9s  z_SocketWriter.writecCs |j��Sr")r�rfr#rrr rf>sz_SocketWriter.filenoN)rUrVrWr!r�r�rfrrrr r�.sr�c@seZdZdd�Zdd�ZdS)r cCs2ddlm}|j\|_|_||j�|_|�|_dS)Nr)�BytesIO)�ior�rEZpacketr5r�r�)rr�rrr r�Es  zDatagramRequestHandler.setupcCs|j�|j��|j�dSr")r5�sendtor��getvaluerFr#rrr r�KszDatagramRequestHandler.finishN)rUrVrWr�r�rrrr r Asr )$� __version__r5r)rvrNrr�rr9r�__all__�hasattr�extendrr'�SelectSelectorrrrr�listr�r�r rrrrrrrrr r r�r rrrr �{sL     n~ X (  .-