3 \i@sdZddlZddlZddlZddlZddlZy ddlZWnek rTddlZYnXddl m Z ddl m Z ddddd d d d d g Z eedre jdddgeedre jddddgeedrejZnejZGdddZGdddeZGdddeZeedrGdddZGdd d ZeedrXGdddeeZGdddeeZGdddeeZGd d d eeZeedrGd!ddeZGd"ddeZGd#ddeeZGd$ddeeZGd%d d Z Gd&d d e Z!Gd'd(d(e Z"Gd)d d e Z#dS)*z0.4N)BufferedIOBase) monotonic BaseServer TCPServer UDPServerThreadingUDPServerThreadingTCPServerBaseRequestHandlerStreamRequestHandlerDatagramRequestHandlerThreadingMixInforkForkingUDPServerForkingTCPServer ForkingMixInAF_UNIXUnixStreamServerUnixDatagramServerThreadingUnixStreamServerThreadingUnixDatagramServer PollSelectorc@seZdZdZddZddZd%ddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$ZdS)&rNcCs ||_||_tj|_d|_dS)NF)server_addressRequestHandlerClass threadingZEvent_BaseServer__is_shut_down_BaseServer__shutdown_request)selfrrr$/usr/lib64/python3.6/socketserver.py__init__s zBaseServer.__init__cCsdS)Nr)rrrrserver_activateszBaseServer.server_activate?cCsx|jjzVtF}|j|tjx0|jsR|j|}|jrrrrr8QszBaseServer.verify_requestcCs|j|||j|dS)N)finish_requestr<)rr=r>rrrr9Ys zBaseServer.process_requestcCsdS)Nr)rrrr server_closebszBaseServer.server_closecCs|j|||dS)N)r)rr=r>rrrr?jszBaseServer.finish_requestcCs|j|dS)N) close_request)rr=rrrr<nszBaseServer.shutdown_requestcCsdS)Nr)rr=rrrrArszBaseServer.close_requestcCsHtddtjdtd|tjdddl}|jtddtjddS)N-()filez4Exception happened during processing of request fromr)printsysstderr traceback print_exc)rr=r>rHrrrr;vs  zBaseServer.handle_errorcCs|S)Nr)rrrr __enter__szBaseServer.__enter__cGs |jdS)N)r@)rargsrrr__exit__szBaseServer.__exit__)r!)__name__ __module__ __qualname__r1rr r-r/r)r5r(r4r8r9r@r?r<rAr;rJrLrrrrrs$-    c@sbeZdZejZejZdZdZ dddZ ddZ dd Z d d Z d d ZddZddZddZdS)rFTc CsTtj|||tj|j|j|_|rPy|j|jWn|jYnXdS)N)rrr0address_family socket_type server_bindr r@)rrrZbind_and_activaterrrrs  zTCPServer.__init__cCs8|jr|jjtjtjd|jj|j|jj|_dS)N)allow_reuse_addressr0 setsockoptZ SOL_SOCKETZ SO_REUSEADDRZbindrZ getsockname)rrrrrSszTCPServer.server_bindcCs|jj|jdS)N)r0Zlistenrequest_queue_size)rrrrr szTCPServer.server_activatecCs|jjdS)N)r0close)rrrrr@szTCPServer.server_closecCs |jjS)N)r0fileno)rrrrrYszTCPServer.filenocCs |jjS)N)r0Zaccept)rrrrr6szTCPServer.get_requestc Cs4y|jtjWntk r$YnX|j|dS)N)r/r0ZSHUT_WRr7rA)rr=rrrr<s zTCPServer.shutdown_requestcCs |jdS)N)rX)rr=rrrrAszTCPServer.close_requestN)T)rMrNrOr0ZAF_INETrQZ SOCK_STREAMrRrWrUrrSr r@rYr6r<rArrrrrs/   c@s:eZdZdZejZdZddZddZ ddZ d d Z d S) rFi cCs |jj|j\}}||jf|fS)N)r0Zrecvfrommax_packet_size)rdataZ client_addrrrrr6szUDPServer.get_requestcCsdS)Nr)rrrrr szUDPServer.server_activatecCs|j|dS)N)rA)rr=rrrr<szUDPServer.shutdown_requestcCsdS)Nr)rr=rrrrAszUDPServer.close_requestN) rMrNrOrUr0Z SOCK_DGRAMrRrZr6r r<rArrrrrscsReZdZdZdZdZdZddddZdd Zd d Z d d Z fddZ Z S)ri,NrCF)blockingc Cs|jdkrdSxht|j|jkrvy tjdd\}}|jj|Wqtk r^|jjYqtk rrPYqXqWxt|jj D]f}y.|rdntj }tj||\}}|jj|Wqtk r|jj|Yqtk rYqXqWdS)NrTr) active_childrenlen max_childrenoswaitpiddiscardChildProcessErrorr"r7copyWNOHANG)rr\pid_flagsrrrcollect_children,s&  zForkingMixIn.collect_childrencCs |jdS)N)rj)rrrrr4OszForkingMixIn.handle_timeoutcCs |jdS)N)rj)rrrrr)VszForkingMixIn.service_actionscCstj}|r8|jdkrt|_|jj||j|dSd}z:y|j||d}Wn tk rr|j||YnXWdz|j |Wdtj |XXdS)NrTr) rar r^r*addrAr?r:r;r<_exit)rr=r>rgZstatusrrrr9]s     zForkingMixIn.process_requestcstj|j|jddS)N)r\)superr@rj_block_on_close)r) __class__rrr@vs zForkingMixIn.server_close) rMrNrOr1r^r`rnrjr4r)r9r@ __classcell__rr)rorr#s#cs8eZdZdZdZdZddZddZfddZZ S) r FNcCsHz6y|j||Wn tk r2|j||YnXWd|j|XdS)N)r?r:r;r<)rr=r>rrrprocess_request_threads z%ThreadingMixIn.process_request_threadcCsRtj|j||fd}|j|_|j rF|jrF|jdkr:g|_|jj||jdS)N)targetrK) rZThreadrqdaemon_threadsZdaemonrn_threadsappendstart)rr=r>trrrr9s   zThreadingMixIn.process_requestcs:tj|jr6|j}d|_|r6x|D] }|jq&WdS)N)rmr@rnrtjoin)rZthreadsZthread)rorrr@s  zThreadingMixIn.server_close) rMrNrOrsrnrtrqr9r@rprr)rorr {s   c@s eZdZdS)rN)rMrNrOrrrrrsc@s eZdZdS)rN)rMrNrOrrrrrsc@s eZdZdS)rN)rMrNrOrrrrrsc@s eZdZdS)rN)rMrNrOrrrrrsc@seZdZejZdS)rN)rMrNrOr0rrQrrrrrsc@seZdZejZdS)rN)rMrNrOr0rrQrrrrrsc@s eZdZdS)rN)rMrNrOrrrrrsc@s eZdZdS)rN)rMrNrOrrrrrsc@s,eZdZddZddZddZddZd S) r c Cs6||_||_||_|jz |jWd|jXdS)N)r=r>serversetuphandlefinish)rr=r>ryrrrrs zBaseRequestHandler.__init__cCsdS)Nr)rrrrrzszBaseRequestHandler.setupcCsdS)Nr)rrrrr{szBaseRequestHandler.handlecCsdS)Nr)rrrrr|szBaseRequestHandler.finishN)rMrNrOrrzr{r|rrrrr s c@s,eZdZd ZdZdZdZddZddZdS) r rTrNFcCsz|j|_|jdk r |jj|j|jr:|jjtjtjd|jj d|j |_ |j dkrdt |j|_n|jj d|j |_dS)NTrbrwb)r=Z connectionr1Z settimeoutdisable_nagle_algorithmrVr0Z IPPROTO_TCPZ TCP_NODELAYmakefilerbufsizerfilewbufsize _SocketWriterwfile)rrrrrzs    zStreamRequestHandler.setupc CsF|jjs.y|jjWntjk r,YnX|jj|jjdS)N)rclosedflushr0errorrXr)rrrrr| s zStreamRequestHandler.finishr]) rMrNrOrrr1rrzr|rrrrr s   c@s,eZdZddZddZddZddZd S) rcCs ||_dS)N)_sock)rZsockrrrrsz_SocketWriter.__init__cCsdS)NTr)rrrrwritablesz_SocketWriter.writablec Cs&|jj|t|}|jSQRXdS)N)rZsendall memoryviewnbytes)rbZviewrrrwrite"s  z_SocketWriter.writecCs |jjS)N)rrY)rrrrrY'sz_SocketWriter.filenoN)rMrNrOrrrrYrrrrrsrc@seZdZddZddZdS)r cCs2ddlm}|j\|_|_||j|_||_dS)Nr)BytesIO)iorr=Zpacketr0rr)rrrrrrz.s  zDatagramRequestHandler.setupcCs|jj|jj|jdS)N)r0Zsendtorgetvaluer>)rrrrr|4szDatagramRequestHandler.finishN)rMrNrOrzr|rrrrr *s)$ __version__r0r%raerrnorFr ImportErrorZdummy_threadingrrr3r__all__hasattrextendrr#ZSelectSelectorrrrrr rrrrrrrrr r rr rrrr{sZ      n~ X.  .-