U e5d jã @sdZddlZddlZddlZddlZddlZddlmZddlm Zddddd d d d d g Z e edƒrte   dddg¡e edƒre   ddddg¡e edƒr¢ej ZnejZGdd„dƒZGdd„deƒZGdd„deƒZe edƒrîGdd„dƒZGdd„deƒZGdd„dƒZGd d „d ƒZe edƒrJGd!d„deeƒZGd"d„deeƒZGd#d„deeƒZGd$d „d eeƒZe edƒr¾Gd%d„deƒZGd&d„deƒZGd'd„deeƒZGd(d„deeƒZGd)d „d ƒZ Gd*d „d e ƒZ!Gd+d,„d,eƒZ"Gd-d „d e ƒZ#dS).z0.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Ú threadingZEventÚ_BaseServer__is_shut_downÚ_BaseServer__shutdown_request)Úselfrr©rú$/usr/lib64/python3.8/socketserver.pyÚ__init__Ès zBaseServer.__init__cCsdS©Nr©rrrrÚserver_activateÏszBaseServer.server_activateçà?c Cst|j ¡zRtƒB}| |tj¡|jsP| |¡}|jr:qP|rF|  ¡|  ¡q"W5QRXW5d|_|j ¡XdSr) rÚclearrÚsetÚ_ServerSelectorÚregisterÚ selectorsÚ EVENT_READÚselectÚ_handle_request_noblockÚservice_actions)rZ poll_intervalÚselectorÚreadyrrrÚ serve_forever×s  zBaseServer.serve_forevercCsd|_|j ¡dS©NT)rrÚwaitr"rrrÚshutdownôszBaseServer.shutdowncCsdSr!rr"rrrr-þszBaseServer.service_actionsc Cs¸|j ¡}|dkr|j}n|jdk r0t||jƒ}|dk rBtƒ|}tƒf}| |tj¡|  |¡}|rz|  ¡W5QR£S|dk rX|tƒ}|dkrX|  ¡W5QR£SqXW5QRXdS)Nr) ÚsocketZ gettimeoutÚtimeoutÚminÚtimer'r(r)r*r+r,Úhandle_timeout)rr5Zdeadliner.r/rrrÚhandle_requests       zBaseServer.handle_requestcCs–z| ¡\}}Wntk r&YdSX| ||¡rˆz| ||¡Wq’tk rn| ||¡| |¡Yq’| |¡‚Yq’Xn | |¡dSr!)Ú get_requestÚOSErrorÚverify_requestÚprocess_requestÚ ExceptionÚ handle_errorÚshutdown_request©rÚrequestÚclient_addressrrrr,/s    z"BaseServer._handle_request_noblockcCsdSr!rr"rrrr8FszBaseServer.handle_timeoutcCsdSr1rrArrrr<MszBaseServer.verify_requestcCs| ||¡| |¡dSr!)Úfinish_requestr@rArrrr=Us zBaseServer.process_requestcCsdSr!rr"rrrÚ server_close^szBaseServer.server_closecCs| |||¡dSr!)rrArrrrDfszBaseServer.finish_requestcCs| |¡dSr!©Ú close_request©rrBrrrr@jszBaseServer.shutdown_requestcCsdSr!rrHrrrrGnszBaseServer.close_requestcCs@tdtjdtd|tjdddl}| ¡tdtjddS)Nz(----------------------------------------)Úfilez4Exception happened during processing of request fromr)ÚprintÚsysÚstderrÚ tracebackÚ print_exc)rrBrCrMrrrr?rsÿzBaseServer.handle_errorcCs|Sr!rr"rrrÚ __enter__szBaseServer.__enter__cGs | ¡dSr!)rE)rÚargsrrrÚ__exit__‚szBaseServer.__exit__)r$)Ú__name__Ú __module__Ú __qualname__r5r r#r0r3r-r9r,r8r<r=rErDr@rGr?rOrQrrrrr™s$-    c@sbeZdZejZejZdZdZ ddd„Z dd„Z dd „Z d d „Z d d „Zdd„Zdd„Zdd„ZdS)réFTcCsTt |||¡t |j|j¡|_|rPz| ¡| ¡Wn| ¡‚YnXdSr!)rr r4Úaddress_familyÚ socket_typeÚ server_bindr#rE)rrrZbind_and_activaterrrr ½sÿ zTCPServer.__init__cCs8|jr|j tjtjd¡|j |j¡|j ¡|_dS)Né)Úallow_reuse_addressr4Ú setsockoptZ SOL_SOCKETZ SO_REUSEADDRZbindrZ getsocknamer"rrrrXÊszTCPServer.server_bindcCs|j |j¡dSr!)r4ZlistenÚrequest_queue_sizer"rrrr#ÕszTCPServer.server_activatecCs|j ¡dSr!)r4Úcloser"rrrrEÝszTCPServer.server_closecCs |j ¡Sr!)r4Úfilenor"rrrr^åszTCPServer.filenocCs |j ¡Sr!)r4Zacceptr"rrrr:íszTCPServer.get_requestcCs4z| tj¡Wntk r$YnX| |¡dSr!)r3r4ZSHUT_WRr;rGrHrrrr@õs zTCPServer.shutdown_requestcCs | ¡dSr!)r]rHrrrrGÿszTCPServer.close_requestN)T)rRrSrTr4ZAF_INETrVZ SOCK_STREAMrWr\rZr rXr#rEr^r:r@rGrrrrr†s/   c@s:eZdZdZejZdZdd„Zdd„Z dd„Z d d „Z d S) rFi cCs |j |j¡\}}||jf|fSr!)r4ZrecvfromÚmax_packet_size)rÚdataZ client_addrrrrr:szUDPServer.get_requestcCsdSr!rr"rrrr#szUDPServer.server_activatecCs| |¡dSr!rFrHrrrr@szUDPServer.shutdown_requestcCsdSr!rrHrrrrGszUDPServer.close_requestN) rRrSrTrZr4Z SOCK_DGRAMrWr_r:r#r@rGrrrrrscsReZdZdZdZdZdZddœdd„Zd d „Zd d „Z d d„Z ‡fdd„Z ‡Z S)ri,Né(TF©Úblockingc Csì|jdkrdSt|jƒ|jkrvz t dd¡\}}|j |¡Wqtk r\|j ¡Yqtk rrYqvYqXq|j  ¡D]f}z.|rŽdntj }t ||¡\}}|j |¡Wq€tk rÒ|j |¡Yq€tk räYq€Xq€dS)Néÿÿÿÿr) Úactive_childrenÚlenÚ max_childrenÚosÚwaitpidÚdiscardÚChildProcessErrorr%r;ÚcopyÚWNOHANG)rrcÚpidÚ_ÚflagsrrrÚcollect_children(s&  zForkingMixIn.collect_childrencCs | ¡dSr!©rqr"rrrr8KszForkingMixIn.handle_timeoutcCs | ¡dSr!rrr"rrrr-RszForkingMixIn.service_actionscCsšt ¡}|r8|jdkrtƒ|_|j |¡| |¡dSd}z:z| ||¡d}Wn t k rr|  ||¡YnXW5z| |¡W5t |¡XXdS)NrYr) rhr rer&ÚaddrGÚ_exitr@rDr>r?)rrBrCrnZstatusrrrr=Ys     zForkingMixIn.process_requestcstƒ ¡|j|jddS)Nrb)ÚsuperrErqÚblock_on_closer"©Ú __class__rrrErs zForkingMixIn.server_close) rRrSrTr5rergrvrqr8r-r=rEÚ __classcell__rrrwrrs#cs4eZdZ‡fdd„Zdd„Zdd„Zdd„Z‡ZS) Ú_Threadscs"| ¡|jrdStƒ |¡dSr!)ÚreapÚdaemonruÚappend©rÚthreadrwrrr}{sz_Threads.appendcCsg|dd…|dd…<}|Sr!r)rÚresultrrrÚpop_allsz_Threads.pop_allcCs| ¡D] }| ¡qdSr!)rÚjoinr~rrrr‚…s z _Threads.joincCsdd„|Dƒ|dd…<dS)Ncss|]}| ¡r|VqdSr!)Zis_alive)Ú.0rrrrÚ Šsz _Threads.reap..rr"rrrr{‰sz _Threads.reap)rRrSrTr}rr‚r{ryrrrwrrzws rzc@seZdZdd„Zdd„ZdS)Ú _NoThreadscCsdSr!rr~rrrr}‘sz_NoThreads.appendcCsdSr!rr"rrrr‚”sz_NoThreads.joinN)rRrSrTr}r‚rrrrr…sr…cs:eZdZdZdZeƒZdd„Zdd„Z‡fdd„Z ‡Z S) r FTc CsHz6z| ||¡Wn tk r2| ||¡YnXW5| |¡XdSr!)r@rDr>r?rArrrÚprocess_request_thread¤s z%ThreadingMixIn.process_request_threadcCsL|jrt|ƒ dtƒ¡tj|j||fd}|j|_|j   |¡|  ¡dS)NÚ_threads)ÚtargetrP) rvÚvarsÚ setdefaultrzrZThreadr†Údaemon_threadsr|r‡r}Ústart)rrBrCÚtrrrr=±sÿ zThreadingMixIn.process_requestcstƒ ¡|j ¡dSr!)rurEr‡r‚r"rwrrrE»s zThreadingMixIn.server_close) rRrSrTr‹rvr…r‡r†r=rEryrrrwrr ˜s   c@s eZdZdS)rN©rRrSrTrrrrrÁsc@s eZdZdS)rNrŽrrrrrÂsc@s eZdZdS)rNrŽrrrrrÄsc@s eZdZdS)rNrŽrrrrrÅsc@seZdZejZdS)rN©rRrSrTr4rrVrrrrrÉsc@seZdZejZdS)rNrrrrrrÌsc@s eZdZdS)rNrŽrrrrrÏsc@s eZdZdS)rNrŽrrrrrÑsc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) r cCs6||_||_||_| ¡z | ¡W5| ¡XdSr!)rBrCÚserverÚsetupÚfinishÚhandle)rrBrCrrrrr ås zBaseRequestHandler.__init__cCsdSr!rr"rrrr‘ïszBaseRequestHandler.setupcCsdSr!rr"rrrr“òszBaseRequestHandler.handlecCsdSr!rr"rrrr’õszBaseRequestHandler.finishN)rRrSrTr r‘r“r’rrrrr Ós c@s,eZdZdZdZdZdZdd„Zdd„ZdS) r rdrNFcCsz|j|_|jdk r |j |j¡|jr:|j tjtjd¡|j  d|j ¡|_ |j dkrdt |jƒ|_n|j  d|j ¡|_dS)NTÚrbrÚwb)rBZ connectionr5Z settimeoutÚdisable_nagle_algorithmr[r4Z IPPROTO_TCPZ TCP_NODELAYZmakefileÚrbufsizeÚrfileÚwbufsizeÚ _SocketWriterÚwfiler"rrrr‘s  ÿ zStreamRequestHandler.setupcCsF|jjs.z|j ¡Wntjk r,YnX|j ¡|j ¡dSr!)r›ÚclosedÚflushr4Úerrorr]r˜r"rrrr’#s zStreamRequestHandler.finish) rRrSrTr—r™r5r–r‘r’rrrrr s   c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ršcCs ||_dSr!)Ú_sock)rZsockrrrr 3sz_SocketWriter.__init__cCsdSr1rr"rrrÚwritable6sz_SocketWriter.writablec Cs2|j |¡t|ƒ}|jW5QR£SQRXdSr!)rŸZsendallÚ memoryviewÚnbytes)rÚbZviewrrrÚwrite9s  z_SocketWriter.writecCs |j ¡Sr!)rŸr^r"rrrr^>sz_SocketWriter.filenoN)rRrSrTr r r¤r^rrrrrš.sršc@seZdZdd„Zdd„ZdS)r cCs2ddlm}|j\|_|_||jƒ|_|ƒ|_dS)Nr)ÚBytesIO)Úior¥rBZpacketr4r˜r›)rr¥rrrr‘Es  zDatagramRequestHandler.setupcCs|j |j ¡|j¡dSr!)r4Zsendtor›ÚgetvaluerCr"rrrr’KszDatagramRequestHandler.finishN)rRrSrTr‘r’rrrrr As)$Ú __version__r4r)rhrKrr¦rr7rÚ__all__ÚhasattrÚextendrr'ZSelectSelectorrrrrÚlistrzr…r rrrrrrrrr r ršr rrrrÚ{s`  ý  þ n~ X (  .-