m DMc@sdkZdkZdkZdkZdkZdZeiZdeZdeei i ddfZ dZ dZ dZeidjZeeieigZd Zd ZdZed ed ed eZeiddjZdeifdYZeodZddZndZddZddddddddddd d!d"dgZ dkZdk!Z!dkZydk"Z"e#Z$Wne%j o e&Z$nXd#e'fd$YZ(dk)Z)dkZdkZdk*Z*d%k+l,Z,y dk"Z"d&k"l-Z-e#Z$Wn2e%j o&e&Z$d'ei.fd(YZ-nXd)e,fd*YZ/dkZdk!Z!dkZdkZdk*Z*yd+k0l1Z1Wn e%j od+k1l1Z1nXei2d Z3e3i4ed e'fd,YZ5d e6d-d d d d.Z7dk!Z!dkZdk8Z8d%k+l,Z,d/e,fd0YZ9dkZei2d1Z3e3i4ed2fd3YZ:dk;Z;dkZdkZdkZdk*Z*d%k+l,Z,d4k<l<Z<yd5k=l>Z>Wn e%j od5k?l>Z>nXyd6k@lAZAWnGe%j o;yd6kBlAZAWn e%j od6kAlAZAnXnXyd&k"l-Z-Wn,e%j o d'ei.fd7YZ-nXe;iCd8e;iDZEe;iCd9e;iFZGd:ZHd;ZIeo(ed<d=d>d?d@dAdBdCgZJndk;Z;e;iCdDZKe6ddEZLdFfdGYZMdHfdIYZNdJe,fdKYZOdLePfdMYZQdNePfdOYZRdPePfdQYZSdRe'fdSYZTdTZUdkZdkZeodUkVlWZWndUkXlWZWedVZYdWZZhd"e<dXdY<dZei[<d[ddf<d\e&<d]e&<d^eN~ |_xFtt|id d d D]%} |i| i!p|i| =qqW|ipt"i#dt$i%d ndS(NRRt SOMAXCONNRtserver_softwaretapp_infoRJt monitor_queuet min_threadst max_threadsiiis%No interfaces to listen on...closing.(&thandle_signalsRR t interfacestlistRwtNoneRRxRaR;R+RsRutdictRtQueueRvRJtMonitorRnt_monitort ThreadPoolt get_methodtmethodt _threadpoolt_[1]tiRFt listenerstrangeRMtndxRQtlogtcriticalR>texit(RRzRRuRwRxRaRnRyRRRJRRv((RR9<sB         3   cCstid|idS(NsReceived SIGTERM(RR@Rtstop(Rtsignumtframe((Rt_sigtermus cCstid|idS(NsReceived SIGHUP(RR@Rtrestart(RRR((Rt_sighupys cCstidt|ioTy9dk}|i|i|i|i|i|i Wqoti dqoXn|i i |i it|i i d}d}|dig}|iD]}|d||q~7}ti|x|iD]}|i qW|i }|i}xn|ipcy|titWq#tj oPq#|ip titti q#qq#Xq#W|i!S(Ns Starting %ss'This platform does not support signals.cCs$|i|i|iodpdfS(Nt*t(tlRLR0R.(R((RtssListening on sockets: s, s%s:%i%s("RR@RRRytsignaltSIGTERMRtSIGUSR1RRkRtstartRt setDaemonRbt str_extractR\tjoinRRRttptdynamic_resizet stop_serverR1tsleepR_tKeyboardInterruptR=RRoRpR(RRRRRRR\R((RR}s@     ;      cCstidx5|iD]*}t|_|io|iqqW|i i |i i |i io|i in|ot indS(NsStopping Server(RR@RRRRDRQtisAliveRRRRt stoploggingRRR%(RRR((RRs      cCs|it|idS(N(RRRDR(R((RRs (s 127.0.0.1i@( R R R R|RbR9RRRRR(((RR8s !9   / ic CsN|}|djo d}nt|dhd||i(|i)|i*od pd f}|iid |n|ii#|t}z|i,Wd~XqWqjqjWdS( NsRocket.MonitorsEntering monitor loop.s(In "receive timed-out connections" loop.sReceived a death threat.s Received a timed out connection.s"Adding connection to monitor list.sBlocking on connectionsisRestoring readable connectionRRs"Flushing stale connection: %s:%i%s(-RtgetNametnameRRRSRRURRbRR{t conn_listRDt list_changedRjRkRvtemptyRMRtgettcR|tAssertionErrorRR#taddtselectR_treadabletrR1R,RJRmtremoveRntnowRtstaleR(R*R-RYR<( RRYRRRRRRR((RRqs   "          &cCst|_to|iidnx&|iD]}z|iWd~Xq.Wto|iidnxM|i i p<|i i }|djoqknz|iWd~XqkW|i i ddS(NsFlushing waiting connectionssFlushing queued connections(RDRRRjRRkRRR<RvRRR|Rm(RR((RRYs*    (R R R9RqR(((RRs  csRocket.Errors.ThreadPoolRcBsatZdZededdZdZdZdZedZ dd Z d Z RS( s|The ThreadPool class is a container class for all the worker threads. It manages the number of actively running threads.RRc Cstotidnd|_||_||_||_||_ ||_ t |_ t |dd|_t|tp t}n|id|d|||_t|_x?t|D]1}|i||i|i }|ii|qWdS(NsInitializing ThreadPool.ii iRxRw(RjRRkRtcheck_for_dead_threadsRJRt worker_classRwRxRvRDRtinttgrow_thresholdR RuR}tupdateRtthreadsRtxtworkerR( RRRuRJRvRwRxRR((RR9s,                cCsPt|_totidnx(|iD]}|it |i q+WdS(NsStarting threads.( RDRRRjRRkRtthreadRRbR(RR((RRs   cCstotidnt|_x!|iD]}|ii dq+Wx|iD]}|i qOWx|iD]}|i qmW|i dS(NsStopping threads.(RjRRkRbRRRttRJRmR|tkillRtbring_out_your_dead(RR((RRs    cCsg}|iD]}|ip ||qq~}xN|D]F}totid|i ny|ii |Wq<q<Xq<W|i t |8_ dS(NsRemoving dead thread: %s.( RRRRRt dead_threadsRjRRkRRRRM(RRRR((RRs5cCs|iodSn|p |i}nt||it|ig}toti d|nxYt |D]K}|i |i |i|i}|it|ii||iqqWdS(NsGrowing by %i.(RRtamountRxtminRMRRjRRkRRRRuRJRvRRRbRR(RRRR((Rtgrows  "    icCsVtotid|n|i|7_x$t|D]}|ii dq8WdS(NsShrinking by %i.( RjRRkRRRRRRJRmR|(RRR((Rtshrinks  cCs|i|ijp|idjo|idjo|in|ii}t|i }t ot i d||fn|djo||ijo|iq||ijo|i|qndS(Nis4Examining ThreadPool. %i threads and %i Q'd conxions(RRxRwRRRJtqsizet queueSizeRMRt threadCountRjRRkRRR(RRR((RRs#( R R R RR9RRRR|RRR(((RRs '    (sdatetime(sunquote(sStringIOcBstZRS(N(R R (((RRE'ss%2Fsd^ (?POPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT) # Request Method \ # (single space) ( (?P[^:/]+) # Scheme (://) # (?P[^/]+) # Host )? # (?P(\*|/[^ \?]*)) # Path (\? (?P[^ ]+))? # Query String \ # (single space) (?PHTTPS?/1\.[01]) # Protocol $ s8%(client_ip)s - "%(request_line)s" - %(status)s %(size)ss4HTTP/1.1 %s Content-Length: %i Content-Type: %s %s tOPTIONStGETtHEADtPOSTtPUTtDELETEtTRACEtCONNECTs[ \(\)<>@,;:\\"/\[\]\?=]cCs|dj olt|djoY|pti|o0|iddidd}d||fSq}d||fSn|SdS( s~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. is\s\\t"s\"s%s="%s"s%s=%sN(tvalueR|RMtquotet _tspecialstsearchtreplacetparam(RRR((Rt _formatparamSs tHeaderscBstZdZdZdZdZdZdZeZdZ ddZ d Z d Z d Zd Zd ZdZdZRS(NcCs6t|tgj otdn||_dS(Ns+Headers must be a list of name/value tuples(ttypetheaderst TypeErrorRt_headers(RR((RR9bscCs t|iS(N(RMRR(R((Rt__len__gscCs!||=|ii||fdS(N(RRRtappendR(RRR((Rt __setitem__jscCsS|i}g}|iD](}|di|jo ||qq~|i(dS(Ni(RtlowerRRRtkv(RRRR((Rt __delitem__ns cCs |i|S(N(RRR(RR((Rt __getitem__rscCs|i|dj S(N(RRRR|(RR((Rthas_keyuscCsM|i}g}|iD],}|di|jo||dqq~S(Nii(RRRRRR(RRRR((Rtget_allzs cCsE|i}x2|iD]'\}}|i|jo|SqqW|S(N(RRRRtktvtdefault(RRRRR((RR~s    cCs(g}|iD]\}}||q~S(N(RRRRR(RRRR((RtkeysscCs(g}|iD]\}}||q~S(N(RRRRR(RRRR((RtvaluesscCs|iS(N(RR(R((RtitemsscCs d|iS(Ns Headers(%r)(RR(R((Rt__repr__scCs9dig}|iD]}|d|q~ddgS(Ns s%s: %sR(RRRRR(RRR((Rt__str__scCsB|i|}|djo|ii||f|Sn|SdS(N(RRRtresultR|RRR(RRRR((Rt setdefaults  cKsg}|dj o|i|nxf|iD]X\}}|djo|i|iddq1|it |idd|q1W|i i|di |fdS(Nt_t-s; (tpartst_valueR|Rt_paramsRRRRRRRt_nameR(RRRRRRR((Rt add_headers   &(R R R9RRRRRt __contains__RR|RRRRRRRR(((RRas               t FileWrappercBs5tZdZedZdZdZdZRS(s1Wrapper to convert file-like objects to iterablescCs6||_||_t|do|i|_ndS(NR<(tfilelikeRtblksizeR;R<(RRR((RR9s  cCs.|ii|i}|o|SntdS(N(RRtreadRRYt IndexError(RtkeyRY((RRscCs|S(N(R(R((Rt__iter__scCs.|ii|i}|o|SntdS(N(RRRRRYt StopIteration(RRY((Rtnexts(R R R RR9RRR (((RRs    tWorkercBs_tZdZdZdZdZdZdZdZdZ dZ d Z RS( sThe Worker class is a base class responsible for receiving connections and (a subclass) will run an application to process the the connection cOsti|||||_||_||_d|_d|_ t |_ t i d|_|iitt i d|i|_|iitdS(Nis200 OKsRocket.RequestssRocket.Errors.(RGR9RRHRIRuRJRvtsizetstatusRbtcloseConnectionRRRStreq_logRURRRT(RRuRJRvRHRI((RR9s      cCs|tjo"d|idjo t}q/n|tjo6to|iidn|i i |i t Sn|t jo,t |_to|iidntSn|tjo,t |_to|iidnt Sn|tijot |_|idtjo#to|iidntSqwd|_ti|||}|iidd i|tSnt |_ti|||}|iid i||id tS( Ns timed outisSocket timed outsClient closed socketsClient sent a bad requests5Ignorable socket Error received...closing connection.s999 Utter Server Failures)Unhandled Error when serving connection: s s500 Server Error(ttypRERRHt SocketTimeoutRjRRTRkRvRmtconnRbt SocketClosedRRDt BadRequestR+R=RR Rotformat_exceptionttbttb_fmtRt send_response(RRRRR((Rt _handleErrorsB          c Csto|iidnxcto[|ii}|p#to|iidn|Snt|t ot |}n||_|i |i jo7|ii d|idt|_|iqn%to|iidnt|_xto|to|iidnyt|i|td|idtiid d |iid d d |id|i}|ii t|Wnti }|i"|}|oPq4|ioktd|idtiid d |iid d d |id|id}|ii t|q4nX|io9y|iWn#|ii$t%t&i'nXPqqWqWdS(NsEntering main loop.sReceived a death threat.s'Received HTTP connection on HTTPS port.s400 Bad RequestsReceived a connection.sServing a requestt client_ipR1s%cR RiR t request_lines - not stopping((RjRRTRkRbRJRRR ttupleR"R-R.R@RRR<RDtrun_appR}R(tdatetimeRtstrftimeR tsplitR Rtlog_infoRtLOG_LINER>R?texcRthandledR=RRoRp(RR#R!RR$((RRqsf              cCst|_tddS(NsOverload this method!(RbRRtNotImplementedError(RR((RREs cCs|iddd}t|t|d|f}y|iit |Wn3t i j o$t |_ |ii d|nXdS(NRis text/plains6Tried to send "%s" to client but received socket error(R R tstat_msgtRESPONSERMR\RRR$RR+R=RbRRT(RR R&R\((RRKs cCs|iot|doyy|iitiWqtij oLti }|di dti jo|i idt|qqXndS(NRiisError on shutdown: (RRR;RR%R+t SHUT_RDWRR=R>R?R@RHRBRTRkR(RR@((RRXs c Csd|_y||i}to|id}n|djoEto|ii dn|i}to|id}qnWn"t i j ot dnX|i }|p+to|ii dntdn||_to|i|Snti|}|p|idtn|i}x}|iD]o\}}|pd||Exception for when a client sends an incomprehensible request.(R R R (((RRs RcBstZdZRS(s4Exception for when a socket is closed by the client.(R R R (((RRs t ChunkedReadercBs5tZdZdZdZdZdZRS(NcCs||_d|_dS(Ni(R)Rtstreamt chunk_size(RR)((RR9s cCs_d}y;x'd|jo|iii}q Wt|dSWntj o dSnXdS(NRii(t chunk_lenRRKR*R,RR@(RRM((Rt _read_headers cCstd}|i}x|o|p|i}n||jo%||ii|7}||8}Pq|pPn||ii|7}||8}d}qW||_|S(NRi(RRYRRLR RNRKR(RR RYRL((RRs"       cCsdtd}|id}x8|o0|tdjo||7}|id}qW||7}|S(NRis (RRYRRR(RRYR((RR* s   ccs|iVdS(N(RR*(R((Rt readliness(R R R9RNRR*RO(((RRJs    cCstdt}||iS(NRr(R}t WSGIWorkertmethodsRR(RRQ((RRs(s formatdates sHTTP/1.1 %s %st SCRIPT_NAMERs wsgi.errorss wsgi.versionswsgi.multiprocesss wsgi.run_onceswsgi.file_wrapperRPcBsPtZdZdZdZddZddZddZdZ RS(NcOsti|||t|ito|iiddj}nt }thd|id<d|<|_ |i i t |iid|_t|idptdt|ind S( sMBuilds some instance variables that will last the life of the thread.RxiRRtswsgi.multithreadRt__call__s<The wsgi_app specified (%s) is not a valid WSGI application.N(R R9RRHRIR RuR}Rt multithreadedRDt base_environRtBASE_ENVtappR;RRG(RRHRIRT((RR9<s(cCs{|i|}|ii}x7|i|iD] \}}||t d| !        !cCs |iid|i||S(Ns]WSGI app called write method directly. This is deprecated behavior. Please update your app.(RRTR]twriteRYR{(RRYR{((Rt write_warningscCs|ido'|id|_t|id}n|ip|i||n|idjonyH|i o*|i i tdt ||fn|i i |Wqt ij ot|_qXndS(s& Write the data to the output socket. iiRs%x %s N(RR=R RRYRRR{RmRiRR$RMR+RbR(RRYR{((RRs  *cCs|o#z|ionWdd}Xn|iotdnto't|t  ot |d|_n ||_yt ||_Wn,t j o d|_ |ii dnX|iS(sQ Store the HTTP status and headers to be sent when self.write is called. NsHeaders already set!s ISO-8859-1s500 Internal Server ErrorsHTTP Headers should be bytessWReceived HTTP Headers from client that contain invalid characters for Latin-1 encoding.(s500 Internal Server ErrorsHTTP Headers should be bytes(R?RRR|RwRRR R RRtresponse_headersRFR=RTR(RR RR?((Rtstart_responses$      cCsd|_tg|_t|_d|_t|_d}d}t o|i i dn|idt}z-|i|||_}|idddjo%|dd}|it|n|i||i}t|d  ot|d  o d|_nt|d ot|}nx)|D]!}|o|i||q1q1W|io|iitd n|ip|id|nWdt o|i i dnt|do|in|iXdS(NisGetting sock_filetrbt HTTP_EXPECTRs 100-continueR[s 100 Continue RRs500 Internal Server Errors7WSGI applications must return a list or generator type.s0 s$Finally closing output and sock_fileR<(NN(s500 Internal Server Errors7WSGI applications must return a list or generator type.( RR RRwRDRR|R=RiR{toutputRjRTRkRR&RR)RnRlRtresR$RRWRR;RMRYRRR<(RRRYRlRR)RR{((RRsD    "   ( R R R9RnRR|RRRR(((RRP;s  * 9   cCsadk}hdd<dd<dd<dd<dd <d d <}totid p|ii|itan|iit|d dpd}|i|i ddd}|ii |o\y/t |di }|dd|fgWq@tj o|dgd}q@XqZ|dgd}n|ddgd}|gS(Nthtms text/htmlthtmltgifs image/giftjpgs image/jpegtpngs image/pngtpdfsapplications/pdfR7RZis index.htmlt.ittextRs200 OKs Content-Types 404 NOT FOUNDs500 INTERNAL SERVER ERRORs?

Hello from Rocket Web Server

(s Content-Types text/html(RNttypest static_folderR>RORtgetcwdRlRR RRPtopenRRYRtIOError(RlRRRYRORNR((Rtdemo_app*s( <$   c Csdkl}|}|idddddddd |id d dd dd dd|idddddddd|i\}}|ia d|i |i fGHt |i t |i fdhdt<}|idS(N(s OptionParsers-is--iptdesttipRs 127.0.0.1thelps#ip address of the network interfaces-ps--portR0t8000spost where to run web servers-ss--statictstaticsfolder containing static filessRocket running on %s:%sRrR(toptparset OptionParsertparsert add_optionR|t parse_argstoptionsRHRRRR0RRRRR(RRHRRR((RtdemoCs      -t__main__(aR>RAR+RRtplatformRt gethostnameR!RtversionR RRR8R_tsystemRRt ECONNABORTEDt ECONNRESETRtDEFAULT_LISTEN_QUEUE_SIZEtDEFAULT_MIN_THREADStDEFAULT_MAX_THREADSR}Rt version_infoRtHandlerRRRt__all__R1R-RbR2t ImportErrorRDtobjectR"RNRot threadingRGRER=RFtqueueR~RSRRURR|R RRRtreRturllibR3t urllib.parsetiotStringIOt cStringIOtcompilet IGNORECASER2tXR.R"R'R?RRRRR t ExceptionRRRRJRt email.utilsRyt email.UtilstNEWLINER}tstderrRVRPRRR (AR3RRRRRRRRRVRR?RPRRRR!RRJRARR RR'RFRRRRyRER}R_R2RGRR>RR"RRRRR"R.R RR~RRRRR+RR-R8RRoRRRRR1R2RRRN((RR8s             0      6                          ( G/    N