ó »ÏâIc@sdZddlZdefd„ƒYZdefd„ƒYZdefd„ƒYZd „Zd d „Zd „Zd „Z dS(sAdapt an HTTP server.iÿÿÿÿNt ServerAdaptercBsneZdZd d d„Zd„Zd„Zd„Zde_d„Z d„Z d„Z d e _d „Z RS( s»Adapter for an HTTP server. If you need to start more than one HTTP server (to serve on multiple ports, or protocols, etc.), you can manually register each one and then start them all with bus.start: s1 = ServerAdapter(bus, MyWSGIServer(host='0.0.0.0', port=80)) s2 = ServerAdapter(bus, another.HTTPServer(host='127.0.0.1', SSL=True)) s1.subscribe() s2.subscribe() bus.start() cCs1||_||_||_d|_t|_dS(N(tbust httpservert bind_addrtNonet interrupttFalsetrunning(tselfRRR((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyt__init__s     cCs0|jjd|jƒ|jjd|jƒdS(Ntstarttstop(Rt subscribeR R (R((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR scCs0|jjd|jƒ|jjd|jƒdS(NR R (Rt unsubscribeR R (R((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR scCst|jtƒr4|j\}}d||f}n d|j}|jrb|jjd|ƒdSd|_|jsƒt dƒ‚nt|jtƒr¥t |jŒnddl }|j d|j ƒ}|jd|jƒƒ|jƒ|jƒt|_|jjd |ƒdS( sStart the HTTP server.s%s:%sssocket file: %ssAlready serving on %sNs No HTTP server has been created.iÿÿÿÿttargets HTTPServer s Serving on %s(t isinstanceRttupleRRtlogRRRt ValueErrortwait_for_free_portt threadingtThreadt_start_http_threadtsetNametgetNameR twaittTrue(Rthosttportton_whatRtt((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR #s&        iKcCsÝy|jjƒWnÅtk rL}|jjdƒ||_|jjƒntk r‡}|jjdƒ||_|jjƒ‚nRddl}|j ƒd|_|jjddt dd ƒ|jjƒ‚nXdS( sHTTP servers MUST be running in new threads, so that the main thread persists to receive KeyboardInterrupt's. If an exception is raised in the httpserver's thread then it's trapped here, and the bus (and therefore our httpserver) are shut down. s' hit: shutting down HTTP servers,SystemExit raised: shutting down HTTP serveriÿÿÿÿNis#Error in HTTP server: shutting downt tracebacktleveli(( RR tKeyboardInterruptRRRtexitt SystemExittsystexc_infoR(RtexcR$((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyRAs$      cCssx;t|jdtƒs=|jr-|j‚ntjdƒqWt|jtƒro|j\}}t ||ƒndS(s8Wait until the HTTP server is ready to receive requests.treadygš™™™™™¹?N( tgetattrRRRttimetsleepRRRtwait_for_occupied_port(RRR((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR[s  cCsv|jr[|jjƒt|jtƒr8t|jŒnt|_|jj d|jƒn|jj d|jƒdS(sStop the HTTP server.sHTTP Server %s shut downs HTTP Server %s already shut downN( RRR RRRRRRR(R((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR gs   icCs|jƒ|jƒdS(sRestart the HTTP server.N(R R (R((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pytrestartus N( t__name__t __module__t__doc__RR R R R tpriorityRRR R,(((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyRs       tFlupFCGIServercBs)eZdZd„Zd„Zd„ZRS(s*Adapter for a flup.server.fcgi.WSGIServer.cOs||_||_t|_dS(N(targstkwargsRR'(RR2R3((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR ~s  cCs]ddlm}||j|jŽ|_d„|j_g|j_t|_|jj ƒdS(sStart the FCGI server.iÿÿÿÿ(t WSGIServercSsdS(N(R(((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyt’sN( tflup.server.fcgiR4R2R3t fcgiservert_installSignalHandlerst_oldSIGsRR'trun(RR4((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR ƒs    cCs1t|j_|jjj|jj_t|_dS(sStop the HTTP server.N(RR7t _keepGoingt _threadPoolt _idleCounttmaxSpareR'(R((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR —s (R-R.R/R R R (((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR1{s  tFlupSCGIServercBs)eZdZd„Zd„Zd„ZRS(s*Adapter for a flup.server.scgi.WSGIServer.cOs||_||_t|_dS(N(R2R3RR'(RR2R3((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR £s  cCs]ddlm}||j|jŽ|_d„|j_g|j_t|_|jj ƒdS(sStart the SCGI server.iÿÿÿÿ(R4cSsdS(N(R(((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR5·sN( tflup.server.scgiR4R2R3t scgiserverR8R9RR'R:(RR4((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR ¨s    cCs(t|_t|j_d|jj_dS(sStop the HTTP server.iN(RR'RAR;R<R>(R((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR ¼s  (R-R.R/R R R (((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR? s  cCs$|dkrdS|dkr dS|S(sDReturn the host on which a client can connect to the given listener.s0.0.0.0s 127.0.0.1s::s::1((t server_host((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyt client_hostÅs   gð?c Cs|stdƒ‚nt|ƒ}t|ƒ}ddl}xÐ|j|||j|jƒD]°}|\}}}}} d} ye|j|||ƒ} | j|ƒ| j ||fƒ| j ƒt dt |ƒt |ƒfƒ‚WqX|j k r| r| j ƒqqXXqXWdS(s?Raise an error if the given port is not free on the given host.s*Host values of '' or None are not allowed.iÿÿÿÿNsTPort %s is in use on %s; perhaps the previous httpserver did not shut down properly.(RRCtinttsockett getaddrinfot AF_UNSPECt SOCK_STREAMRt settimeouttconnecttclosetIOErrortreprterror( RRttimeoutREtrestaftsocktypetprotot canonnametsats((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyt check_portÏs&      cCs‚|stdƒ‚nxPtdƒD]B}yt||ddƒWntk r_tjdƒq"XdSq"Wtd||fƒ‚dS(s;Wait for the specified port to become free (drop requests).s*Host values of '' or None are not allowed.i2ROgš™™™™™¹?NsPort %r not free on %r(RtxrangeRWRLR)R*(RRttrial((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyRìs cCsy|stdƒ‚nxGtdƒD]9}yt||ƒWntk rMdSXtjdƒq"Wtd||fƒ‚dS(s@Wait for the specified port to become active (receive requests).s*Host values of '' or None are not allowed.i2Ngš™™™™™¹?sPort %r not bound on %r(RRXRWRLR)R*(RRRY((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyR+ýs ( R/R)tobjectRR1R?RCRWRR+(((s>/usr/lib/python2.7/vendor-packages/cherrypy/process/servers.pyts u%%