;ò `©ÇDc@s dZdZdZdkZdkZdkZdkZdkZdk Z dk Z dk Z dk Z ydk Z dkZeZWn+ej odkZ dkZeZnXee dƒ o de _ndgZdZdZdZdZd Zd Zd Zd Zd Z dZ!dZ"dZ#dZ$dZ%e%Z&dZ'dZ(dZ)d Z*d Z+dZ,dZ-d Z.d Z/dZ0dZ1dZ2dZ3dZ4dZ5dZ6ei7e5ƒZ8ei7e6ƒZ9e:o"dk;Z;dZ<dZ=d„Z>nde?fd„ƒYZ@de@fd„ƒYZAde?fd „ƒYZBd!e?fd"„ƒYZCd#e?fd$„ƒYZDdd%„ZEd&„ZFd'e?fd(„ƒYZGd)e?fd*„ƒYZHd+eHfd,„ƒYZId-e?fd.„ƒYZJd/eJfd0„ƒYZKd1e?fd2„ƒYZLdeLfd3„ƒYZMeNd4jod5„ZOeMeOƒiPƒndS(6s fcgi - a FastCGI/WSGI gateway. For more information about FastCGI, see . For more information about the Web Server Gateway Interface, see . Example usage: #!/usr/bin/env python from myapplication import app # Assume app is your WSGI application object from fcgi import WSGIServer WSGIServer(app).run() See the documentation for WSGIServer/Server for more information. On most platforms, fcgi will fallback to regular CGI behavior if run in a non-FastCGI context. If you want to force CGI behavior, set the environment variable FCGI_FORCE_CGI to "Y" or "y". sAllan Saddi s $Revision$NsSHUT_WRis WSGIServeriiiiiiiii i i sFCGI_MAX_CONNSs FCGI_MAX_REQSsFCGI_MPXS_CONNSs!BBHHBxs!HB5xs!LB3xs!B7xs /tmp/fcgi.logcCsdt|jodSnyAttdƒ}|idtiƒdd!|fƒ|i ƒWnnXdS(Nsas %sfcgi: %s iiüÿÿÿ( sDEBUGslevelsopensDEBUGLOGsfswritestimesctimesmsgsclose(slevelsmsgsf((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_debugs $s InputStreamcBshtZdZd„Zd„Zd„Zdd„Zed„Zdd„Z d „Z d „Z d „Z RS( s‘ File-like object representing FastCGI input streams (FCGI_STDIN and FCGI_DATA). Supports the minimum methods required by WSGI spec. cCsI||_|ii|_d|_g|_d|_d|_ t |_ dS(Nsi( sconnsselfs_connsserversinputStreamShrinkThresholds_shrinkThresholds_bufs_bufLists_poss_availsFalses_eof(sselfsconn((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__‘s     cCs`|i|ijoI|i|i|_|i|i8_d|_|idjpt‚ndS(s6Gets rid of already read data (since we can't rewind).iN(sselfs_poss_shrinkThresholds_bufs_availsAssertionError(sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _shrinkBufferžs  cCs|iiƒdS(s(Waits for more data to become available.N(sselfs_conns process_input(sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _waitForData§siÿÿÿÿcCsï|i|ijo|iodSnxgto_|djp|i|i|jo)|io|i}PqŠ|iƒq(q(|i|}Pq(W|io(|i di |iƒ7_ g|_n|i |i|!}||_|i ƒ|SdS(Nsi( sselfs_poss_avails_eofsTruesnsnewPoss _waitForDatas_bufLists_bufsjoinsrs _shrinkBuffer(sselfsnsrsnewPos((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysread«s&$        cCs#|i|ijo|iodSnx—to|io(|idi|iƒ7_g|_n|iid|iƒ}|djo)|io|i}Pqº|i ƒq(q(|d}Pq(W|t j o)|i||jo|i|}qõn|i|i|!}||_|iƒ|SdS(Nss ii(sselfs_poss_avails_eofsTrues_bufLists_bufsjoinsfindsisnewPoss _waitForDataslengthsNonesrs _shrinkBuffer(sselfslengthsisrsnewPos((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysreadlineÅs.          icCs{d}g}|iƒ}xX|oP|i|ƒ|t|ƒ7}d|jo |jnoPn|iƒ}qW|SdS(Ni(stotalslinessselfsreadlineslinesappendslenssizehint(sselfssizehintslinesslinestotal((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys readlinesäs  cCs|SdS(N(sself(sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__iter__ðscCs&|iƒ}| o t‚n|SdS(N(sselfsreadlinesrs StopIteration(sselfsr((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysnextós  cCs>| o t|_n&|ii|ƒ|it|ƒ7_dS(N(sdatasTruesselfs_eofs_bufListsappends_availslen(sselfsdata((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysadd_dataùs ( s__name__s __module__s__doc__s__init__s _shrinkBuffers _waitForDatasreadsNonesreadlines readliness__iter__snextsadd_data(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys InputStreamŒs      sMultiplexedInputStreamcBsAtZdZd„Zd„Zdd„Zed„Zd„ZRS(sÊ A version of InputStream meant to be used with MultiplexedConnections. Assumes the MultiplexedConnection (the producer) and the Request (the consumer) are running in different threads. cCs8tt|ƒi|ƒtiƒ}ti|ƒ|_ dS(N( ssupersMultiplexedInputStreamsselfs__init__sconns threadingsRLockslocks Conditions_lock(sselfsconnslock((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__s cCs|iiƒdS(N(sselfs_lockswait(sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _waitForDatasiÿÿÿÿcCs<|iiƒztt|ƒi|ƒSWd|iiƒXdS(N(sselfs_locksacquiressupersMultiplexedInputStreamsreadsnsrelease(sselfsn((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysreads  cCs<|iiƒztt|ƒi|ƒSWd|iiƒXdS(N(sselfs_locksacquiressupersMultiplexedInputStreamsreadlineslengthsrelease(sselfslength((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysreadlines  cCsI|iiƒz'tt|ƒi|ƒ|iiƒWd|iiƒXdS(N( sselfs_locksacquiressupersMultiplexedInputStreamsadd_datasdatasnotifysrelease(sselfsdata((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysadd_data"s  ( s__name__s __module__s__doc__s__init__s _waitForDatasreadsNonesreadlinesadd_data(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysMultiplexedInputStreams    s OutputStreamcBsGtZdZed„Zd„Zd„Zd„Zd„Zd„Z RS(sØ FastCGI output stream (FCGI_STDOUT/FCGI_STDERR). By default, calls to write() or writelines() immediately result in Records being sent back to the server. Buffering should be done in a higher level! cCsC||_||_||_||_g|_ t |_ t |_ dS(N( sconnsselfs_connsreqs_reqstypes_typesbuffereds _buffereds_bufListsFalses dataWrittensclosed(sselfsconnsreqstypesbuffered((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__0s      cCst|ƒ}xz|ort||iiitƒ}t |i |ii ƒ}||_|| |_|ii|ƒ||}||8}qWdS(N(slensdataslengthsminsselfs_reqsserversmaxwritesFCGI_HEADER_LENstoWritesRecords_types requestIdsrecs contentLengths contentDatas_conns writeRecord(sselfsdatastoWriteslengthsrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_write9s    cCsZ|i pt‚| odSnt|_|io|ii|ƒn|i |ƒdS(N( sselfsclosedsAssertionErrorsdatasTrues dataWrittens _buffereds_bufListsappends_write(sselfsdata((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pyswriteFs  cCs4|i pt‚x|D]}|i|ƒqWdS(N(sselfsclosedsAssertionErrorslinesslineswrite(sselfslinessline((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys writelinesSscCs:|io,di|iƒ}g|_|i|ƒndS(Ns(sselfs _bufferedsjoins_bufListsdatas_write(sselfsdata((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysflushYs  cCsX|i o|io?|iƒt|i|iiƒ}|i i |ƒt |_ndS(s/Sends end-of-stream notification, if necessary.N( sselfscloseds dataWrittensflushsRecords_types_reqs requestIdsrecs_conns writeRecordsTrue(sselfsrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pyscloseas  ( s__name__s __module__s__doc__sFalses__init__s_writeswrites writelinessflushsclose(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys OutputStream*s   sTeeOutputStreamcBs2tZdZd„Zd„Zd„Zd„ZRS(sq Simple wrapper around two or more output file-like objects that copies written data to all streams. cCs ||_dS(N(s streamListsselfs _streamList(sselfs streamList((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__nscCs%x|iD]}|i|ƒq WdS(N(sselfs _streamListsfswritesdata(sselfsdatasf((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pyswriteqs cCs"x|D]}|i|ƒqWdS(N(slinesslinesselfswrite(sselfslinessline((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys writelinesuscCs"x|iD]}|iƒq WdS(N(sselfs _streamListsfsflush(sselfsf((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysflushys (s__name__s __module__s__doc__s__init__swrites writelinessflush(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysTeeOutputStreamis    s StdoutWrappercBs2tZdZd„Zd„Zd„Zd„ZRS(sN Wrapper for sys.stdout so we know if data has actually been written. cCs||_t|_dS(N(sstdoutsselfs_filesFalses dataWritten(sselfsstdout((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__s cCs(|o t|_n|ii|ƒdS(N(sdatasTruesselfs dataWrittens_fileswrite(sselfsdata((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pyswrite…s cCs"x|D]}|i|ƒqWdS(N(slinesslinesselfswrite(sselfslinessline((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys writelinesŠscCst|i|ƒSdS(N(sgetattrsselfs_filesname(sselfsname((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys __getattr__Žs(s__name__s __module__s__doc__s__init__swrites writeliness __getattr__(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys StdoutWrapper}s    cCsút||ƒ}|d@o3tid|||d!ƒdd@}|d7}n |d7}t||ƒ}|d@o3tid|||d!ƒdd@}|d7}n |d7}||||!}||7}||||!}||7}|||ffSdS(sv Decodes a name/value pair. The number of bytes decoded as well as the name/value pair are returned. i€s!LiiiÿÿÿiN( sordsssposs nameLengthsstructsunpacks valueLengthsnamesvalue(ssspossvalues nameLengths valueLengthsname((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys decode_pair‘s  %  %   cCs–t|ƒ}|djot|ƒ}ntid|dBƒ}t|ƒ}|djo|t|ƒ7}n|tid|dBƒ7}|||SdS(sI Encodes a name/value pair. The encoded string is returned. i€s!LlN( slensnames nameLengthschrsssstructspacksvalues valueLength(snamesvaluesss nameLengths valueLength((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys encode_pair­s    sRecordcBsYtZdZeed„Zd„ZeeƒZd„Zd„Z ee ƒZ d„Z RS(sD A FastCGI Record. Used for encoding/decoding records. cCs:t|_||_||_d|_d|_d|_dS(Nis(sFCGI_VERSION_1sselfsversionstypes requestIds contentLengths paddingLengths contentData(sselfstypes requestId((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__Çs      cCsÎg}d}x¨|o y|i|ƒ}WnLtij o=}|dt i jot i |gggƒqqx‚nX| oPn|i |ƒt |ƒ}||7}||8}qWdi|ƒ|fSdS(sŠ Attempts to receive length bytes from a socket, blocking if necessary. (Socket may be blocking or non-blocking.) isN(sdataListsrecvLenslengthssocksrecvsdatassocketserrorseserrnosEAGAINsselectsappendslensdataLensjoin(ssockslengthsdataLensesdataListsrecvLensdata((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_recvallÏs&   cCs=y|i|tƒ\}}Wn t‚nX|tjo t‚ntit |ƒ\|_ |_ |_ |_ |_to0tdd|iƒ|i |i |i fƒn|i oPy"|i||i ƒ\|_}Wn t‚nX||i jo t‚qn|io+y|i||iƒWq9t‚q9XndS(s'Read and decode a Record from a socket.i s<read: fd = %d, type = %d, requestId = %d, contentLength = %dN(sselfs_recvallssocksFCGI_HEADER_LENsheaderslengthsEOFErrorsstructsunpacks FCGI_Headersversionstypes requestIds contentLengths paddingLengths __debug__s_debugsfilenos contentData(sselfssocksheaderslength((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysreadès.   00    cCs•t|ƒ}x‚|ozy|i|ƒ}WnLtij o=}|dt i jot i g|ggƒqqx‚nX||}||8}qWdS(sY Writes data to a socket and does not return until all the data is sent. iN( slensdataslengthssockssendssentssocketserrorseserrnosEAGAINsselect(ssocksdataseslengthssent((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_sendall s  cCsÏ|i d@|_to0tdd|iƒ|i|i|ifƒnt i t |i |i|i|i|iƒ}|i||ƒ|io|i||iƒn|io|i|d|iƒndS(s&Encode and write a Record to a socket.ii s=write: fd = %d, type = %d, requestId = %d, contentLength = %dsN(sselfs contentLengths paddingLengths __debug__s_debugssocksfilenostypes requestIdsstructspacks FCGI_Headersversionsheaders_sendalls contentData(sselfssocksheader((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pyswrites0    ( s__name__s __module__s__doc__sFCGI_UNKNOWN_TYPEsFCGI_NULL_REQUEST_IDs__init__s_recvalls staticmethodsreads_sendallswrite(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysRecordÁs    "  sRequestcBs8tZdZd„Zd„Zded„Zd„ZRS(s8 Represents a single FastCGI request. These objects are passed to your handler and is the main interface between your handler and the fcgi module. The methods should not be called by your handler. However, server, params, stdin, stdout, stderr, and data are free for your handler's use. cCsp||_|i|_h|_||ƒ|_t||tƒ|_ t||t dt ƒ|_ ||ƒ|_ dS(Nsbuffered(sconnsselfs_connsserversparamssinputStreamClasssstdins OutputStreams FCGI_STDOUTsstdouts FCGI_STDERRsTruesstderrsdata(sselfsconnsinputStreamClass((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__7s   cCsºy|ii|ƒ\}}Wn[tid|iƒ|iiƒ|i i o|ii |ƒnt df\}}nXt otdd||fƒn|iƒ|i||ƒdS(s<Runs the handler, flushes the streams, and ends the request.sfileiis#protocolStatus = %d, appStatus = %dN(sselfsservershandlersprotocolStatuss appStatuss tracebacks print_excsstderrsflushsstdouts dataWrittenserrorsFCGI_REQUEST_COMPLETEs __debug__s_debugs_flushs_end(sselfsprotocolStatuss appStatus((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysrunAs  lcCs|ii|||ƒdS(N(sselfs_conns end_requests appStatussprotocolStatus(sselfs appStatussprotocolStatus((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_endSscCs|iiƒ|iiƒdS(N(sselfsstdoutsclosesstderr(sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_flushVs (s__name__s __module__s__doc__s__init__srunsFCGI_REQUEST_COMPLETEs_ends_flush(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysRequest.s  s CGIRequestcBs/tZdZd„Zded„Zd„ZRS(s4A normal CGI request disguised as a FastCGI request.cCs|d|_t|_d|_t|_||_tt i ƒ|_ t i |_ tt iƒ|_t i|_tiƒ|_dS(Nii(sselfs requestIdsFCGI_RESPONDERsrolesflagssFalsesabortedsserversdictsossenvironsparamsssyssstdins StdoutWrappersstdoutsstderrsStringIOsdata(sselfsserver((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__\s       lcCsti|ƒdS(N(ssyssexits appStatus(sselfs appStatussprotocolStatus((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_endjscCsdS(N((sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_flushms(s__name__s __module__s__doc__s__init__sFCGI_REQUEST_COMPLETEs_ends_flush(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys CGIRequestZs  s ConnectioncBs¡tZdZeZeZd„Zd„Zd„Z d„Z d„Z de e d„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„ZRS(sæ A Connection with the web server. Each Connection is associated with a single socket (which is connected to the web server) and is responsible for handling all the FastCGI message processing for that socket. cCs(||_||_||_h|_dS(N(ssocksselfs_socksaddrs_addrsservers _requests(sselfssocksaddrsserver((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__|s   cCs˜y|iitiƒWn dSnXyXxQtoIti|igggƒ\}}}| p|ii dƒ oPq+q+WWnnX|ii ƒdS(sClose the Connection's socket.Ni( sselfs_socksshutdownssocketsSHUT_WRsTruesselectsrswsesrecvsclose(sselfsesrsw((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_cleanupSocket„s$cCsŠt|_xp|ioey|iƒWq tj oPq titifj o%}|dt i joPn‚q Xq W|i ƒdS(s&Begin processing data from the socket.iN( sTruesselfs _keepGoings process_inputsEOFErrorsselectserrorssocketseserrnosEBADFs_cleanupSocket(sselfse((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysrun“s   cCs|xb|ioWy+ti|igggdƒ\}}}Wntj o t‚nX|oPqqW|i odSnt ƒ}|i |iƒ|i t jo|i|ƒnÇ|i tjo|i|ƒn¦|i tjo|i|ƒn…|i tjo|i|ƒnd|i tjo|i|ƒnC|i tjo|i|ƒn"|itjo|i|ƒndS(s?Attempt to read a single Record from the socket and process it.f1.0N(sselfs _keepGoingsselects_socksrswses ValueErrorsEOFErrorsRecordsrecsreadstypesFCGI_GET_VALUESs_do_get_valuessFCGI_BEGIN_REQUESTs_do_begin_requestsFCGI_ABORT_REQUESTs_do_abort_requests FCGI_PARAMSs _do_paramss FCGI_STDINs _do_stdins FCGI_DATAs_do_datas requestIdsFCGI_NULL_REQUEST_IDs_do_unknown_type(sselfsesrswsrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys process_input¢s8 +    cCs|i|iƒdS(s/ Write a Record to the socket. N(srecswritesselfs_sock(sselfsrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys writeRecordÇslcCs¬tt|iƒ}tit||ƒ|_ t |_ |i|ƒ|o|i|i=ntotdd|iƒn|it@ o|i o|iƒt|_ndS(s  End a Request. Called by Request objects. An FCGI_END_REQUEST Record is sent to the web server. If the web server no longer requires the connection, the socket is closed, thereby ending this Connection (run() returns). isend_request: flags = %dN(sRecordsFCGI_END_REQUESTsreqs requestIdsrecsstructspacksFCGI_EndRequestBodys appStatussprotocolStatuss contentDatasFCGI_EndRequestBody_LENs contentLengthsselfs writeRecordsremoves _requestss __debug__s_debugsflagssFCGI_KEEP_CONNs_cleanupSocketsFalses _keepGoing(sselfsreqs appStatussprotocolStatussremovesrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys end_requestÍs      cCs¯ttƒ}d}xw||ijoft|i|ƒ\}\}}|i i i |ƒ}|tj o"|it|t|ƒƒ7_qqWt|iƒ|_|i|ƒdS(s6Handle an FCGI_GET_VALUES request from the web server.iN(sRecordsFCGI_GET_VALUES_RESULTsoutrecspossinrecs contentLengths decode_pairs contentDatasnamesvaluesselfsservers capabilitysgetscapsNones encode_pairsstrslens writeRecord(sselfsinrecsoutrecscapspossvaluesname((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_do_get_valuesæs  'cCs¦tit|iƒ\}}|ii ||i ƒ}|i ||f\|_ |_|_t |_|i o|io|i|dtdt ƒn||i|i ttƒ}tit|iƒ|_t |_ |i t ƒdS(s4Handle an unknown request type. Respond accordingly.N(sRecordsFCGI_UNKNOWN_TYPEsoutrecsstructspacksFCGI_UnknownTypeBodysinrecstypes contentDatasFCGI_UnknownTypeBody_LENs contentLengthsselfs writeRecordsrec(sselfsinrecsoutrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_do_unknown_type-s   (s__name__s __module__s__doc__sFalses _multiplexeds InputStreams_inputStreamClasss__init__s_cleanupSocketsruns process_inputs writeRecordsFCGI_REQUEST_COMPLETEsTrues end_requests_do_get_valuess_do_begin_requests_do_abort_requests_start_requests _do_paramss _do_stdins_do_datas_do_unknown_type(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys Connectionqs"     %       sMultiplexedConnectioncBs}tZdZeZeZd„Zd„Zd„Z de ed„Z d„Z d„Z d„Zd „Zd „Zd „ZRS( s[ A version of Connection capable of handling multiple requests simultaneously. cCs>tt|ƒi|||ƒtiƒ}ti |ƒ|_ dS(N( ssupersMultiplexedConnectionsselfs__init__ssocksaddrsservers threadingsRLockslocks Conditions_lock(sselfssocksaddrsserverslock((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__<s cCsP|iiƒx|io|iiƒqW|iiƒtt|ƒiƒdS(N( sselfs_locksacquires _requestsswaitsreleasessupersMultiplexedConnections_cleanupSocket(sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_cleanupSocketFs    cCs6|iiƒz|i|iƒWd|iiƒXdS(N(sselfs_locksacquiresrecswrites_socksrelease(sselfsrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys writeRecordOs  lcCsR|iiƒz0tt|ƒi||||ƒ|ii ƒWd|ii ƒXdS(N( sselfs_locksacquiressupersMultiplexedConnections end_requestsreqs appStatussprotocolStatussremovesnotifysrelease(sselfsreqs appStatussprotocolStatussremove((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys end_requestYs cCs<|iiƒztt|ƒi|ƒWd|iiƒXdS(N(sselfs_locksacquiressupersMultiplexedConnections_do_begin_requestsinrecsrelease(sselfsinrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_do_begin_requestds  cCs<|iiƒztt|ƒi|ƒWd|iiƒXdS(N(sselfs_locksacquiressupersMultiplexedConnections_do_abort_requestsinrecsrelease(sselfsinrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_do_abort_requestks  cCsti|ifƒdS(N(sthreadsstart_new_threadsreqsrun(sselfsreq((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_start_requestrscCs<|iiƒztt|ƒi|ƒWd|iiƒXdS(N(sselfs_locksacquiressupersMultiplexedConnections _do_paramssinrecsrelease(sselfsinrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _do_paramsus  cCs<|iiƒztt|ƒi|ƒWd|iiƒXdS(N(sselfs_locksacquiressupersMultiplexedConnections _do_stdinsinrecsrelease(sselfsinrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _do_stdin|s  cCs<|iiƒztt|ƒi|ƒWd|iiƒXdS(N(sselfs_locksacquiressupersMultiplexedConnections_do_datasinrecsrelease(sselfsinrec((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_do_dataƒs  (s__name__s __module__s__doc__sTrues _multiplexedsMultiplexedInputStreams_inputStreamClasss__init__s_cleanupSockets writeRecordsFCGI_REQUEST_COMPLETEs end_requests_do_begin_requests_do_abort_requests_start_requests _do_paramss _do_stdins_do_data(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysMultiplexedConnection4s       sServercBs¥tZdZeZeZddZedeee d„Z d„Z d„Z d„Z d„Zd„Zd „Zd d „Zd „Ze d „Zd„Zd„ZRS(sß The FastCGI server. Waits for connections from the web server, processing each request. If run in a normal CGI context, it will instead instantiate a CGIRequest and run the handler through there. ii c Cs|tj o ||_n||_to¢y#dk}|i|iƒd}Wnt j o d}nX|}|ot |_ |d9}n t|_ ht|<t|<t|odpd<|_n.t|_ htd<td<td<|_||_||_dS(s^ handler, if present, must reference a function or method that takes one argument: a Request object. If handler is not specified at creation time, Server *must* be subclassed. (The handler method below is abstract.) maxwrite is the maximum number of bytes (per Record) to write to the server. I've noticed mod_fastcgi has a relatively small receive buffer (8K or so). bindAddress, if present, must either be a string or a 2-tuple. If present, run() will open its own listening socket. You would use this if you wanted to run your application as an 'external' FastCGI app. (i.e. the webserver would no longer be responsible for starting your app) If a string, it will be interpreted as a filename and a UNIX socket will be opened. If a tuple, the first element, a string, is the interface name/IP to bind to, and the second element (an int) is the port number. Set multiplexed to True if you want to handle multiple requests per connection. Some FastCGI backends (namely mod_fastcgi) don't multiplex requests at all, so by default this is off (which saves on thread creation/locking overhead). If threads aren't available, this keyword is ignored; it's not possible to multiplex requests at all. Niidii(shandlersNonesselfsmaxwritesthread_availablesresources getrlimits RLIMIT_NOFILEsmaxConnss ImportErrorsmaxReqss multiplexedsMultiplexedConnections_connectionClasss ConnectionsFCGI_MAX_CONNSs FCGI_MAX_REQSsFCGI_MPXS_CONNSs capabilitys bindAddresss _bindAddresssumasks_umask( sselfshandlersmaxwrites bindAddresssumasks multiplexedsresourcesmaxReqssmaxConns((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__œs(       6 $ cCs'|itjoÞt}tittiti ƒ}y|i ƒWnQti j oB}|dtijo t}q“|dtijo‚q“nX| p"tiiddƒiƒidƒo*|i|ƒ}|iƒtidƒqn2t}t|iƒtjoltititi ƒ}yti |iƒWnt!j onX|i"tj oti#|i"ƒ}qánlt|iƒt$jpt%‚t&|iƒdjpt%‚tititi ƒ}|i'ti(ti)dƒ|i*|iƒ|i+ti,ƒ|tj oti#|ƒn|SdS(NisFCGI_FORCE_CGIsNsYii(-sselfs _bindAddresssNonesTruesisFCGIssocketsfromfdsFCGI_LISTENSOCK_FILENOsAF_INETs SOCK_STREAMssocks getpeernameserrorseserrnosENOTSOCKsFalsesENOTCONNsossenvironsgetsuppers startswithscgirequest_classsreqsrunssyssexitsoldUmaskstypesstrsAF_UNIXsunlinksOSErrors_umasksumaskstuplesAssertionErrorslens setsockopts SOL_SOCKETs SO_REUSEADDRsbindslistens SOMAXCONN(sselfsoldUmasksreqsesisFCGIssock((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _setupSocketÙsB   -  cCs|iƒdS(sCloses the main socket.N(ssocksclose(sselfssock((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_cleanupSocket scCs‘gi}tititifD]}||ti|ƒfƒq ~|_ titi|i ƒtiti|i ƒtiti|i ƒdS(N( sappends_[1]ssignalsSIGHUPsSIGINTsSIGTERMsxs getsignalsselfs_oldSIGss _hupHandlers _intHandler(sselfs_[1]sx((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_installSignalHandlerssKcCs.x'|iD]\}}ti||ƒq WdS(N(sselfs_oldSIGsssignumshandlerssignal(sselfshandlerssignum((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_restoreSignalHandlerss cCst|_t|_dS(N(sTruesselfs _hupReceivedsFalses _keepGoing(sselfssignumsframe((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _hupHandlers cCs t|_dS(N(sFalsesselfs _keepGoing(sselfssignumsframe((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys _intHandler sf1.0c CsÌtiidƒ}|tj otd„|idƒƒ}n|iƒ}t |_ t |_ |iƒxA|i o6y(ti|ggg|ƒ\}}}Wn6tij o'}|dtijoqin‚nX|oÀy|iƒ\}} Wn?tij o0}|dtitifjoqin‚nX|o!t| ƒdjp| d|jo|iƒqin|i|| |ƒ}t i!|i"fƒn|i#ƒqiW|i$ƒ|i%|ƒ|i SdS(s€ The main loop. Exits on SIGHUP, SIGINT, SIGTERM. Returns True if SIGHUP was received, False otherwise. sFCGI_WEB_SERVER_ADDRScCs |iƒS(N(sxsstrip(sx((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys*ss,iiN(&sossenvironsgetsweb_server_addrssNonesmapssplitsselfs _setupSocketssocksTrues _keepGoingsFalses _hupReceiveds_installSignalHandlerssselectstimeoutsrswseserrorserrnosEINTRsaccepts clientSocksaddrssocketsEAGAINslenscloses_connectionClasssconnsthreadsstart_new_threadsruns_mainloopPeriodics_restoreSignalHandlerss_cleanupSocket( sselfstimeoutsweb_server_addrssws clientSockssocksrsconnsesaddr((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysrun#sB       (+   cCsdS(si Called with just about each iteration of the main loop. Meant to be overridden. N((sself((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_mainloopPeriodicXscCs$|iot|_||_ndS(s Protected convenience method for subclasses to force an exit. Not really thread-safe, which is why it isn't public. N(sselfs _keepGoingsFalsesreloads _hupReceived(sselfsreload((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys_exit_s  cCst|iid‚dS(s­ Default handler, which just raises an exception. Unless a handler is passed at initialization time, this must be implemented by a subclass. s.handlerN(sNotImplementedErrorsselfs __class__s__name__(sselfsreq((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pyshandlerhscCs0dk}|iid|itiƒƒƒdS(st Called by Request if an exception occurs within the handler. May and should be overridden. NsContent-Type: text/html (scgitbsreqsstdoutswriteshtmlssyssexc_info(sselfsreqscgitb((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pyserrorps (s__name__s __module__s__doc__sRequests request_classs CGIRequestscgirequest_classsinputStreamShrinkThresholdsNonesFalses__init__s _setupSockets_cleanupSockets_installSignalHandlerss_restoreSignalHandlerss _hupHandlers _intHandlersruns_mainloopPeriodics_exitshandlerserror(((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pysServerŠs  = 4      5  cBs2tZdZeeed„Zd„Zd„ZRS(s| FastCGI server that supports the Web Server Gateway Interface. See . cKsv|idƒo |d=ntt|ƒi||tjo h}n||_||_||_ t i ƒ|_ dS(s  environ, if present, must be a dictionary-like object. Its contents will be copied into application's environ. Useful for passing application-specific variables. Set multithreaded to False if your application is not MT-safe. shandlerN( skwshas_keyssupers WSGIServersselfs__init__senvironsNones applications multithreadedsthreads allocate_locks _app_lock(sselfs applicationsenvironsumasks multithreadedskw((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys__init__~s      c sQˆitjotdfSnˆi} | i|iƒddf| d<ˆi| d<|i t jo ˆi } nt t i ˆi fƒ} | | dHello World!

Hello World!

s sfps wsgi.inputsenvironskeep_blank_valuesis's
%s%s
Form data
( scgisstart_responsesenvironskeyssnamesssortsnamesescapes FieldStoragesformslistsfieldsvalue(senvironsstart_responsescgisnamesformsfieldsnames((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pystest_apps"       (Qs__doc__s __author__s __version__ssyssosssignalsstructs cStringIOsStringIOsselectssocketserrnos tracebacksthreads threadingsTruesthread_availables ImportErrors dummy_threadsdummy_threadingsFalseshasattrsSHUT_WRs__all__sFCGI_LISTENSOCK_FILENOsFCGI_HEADER_LENsFCGI_VERSION_1sFCGI_BEGIN_REQUESTsFCGI_ABORT_REQUESTsFCGI_END_REQUESTs FCGI_PARAMSs FCGI_STDINs FCGI_STDOUTs FCGI_STDERRs FCGI_DATAsFCGI_GET_VALUESsFCGI_GET_VALUES_RESULTsFCGI_UNKNOWN_TYPEs FCGI_MAXTYPEsFCGI_NULL_REQUEST_IDsFCGI_KEEP_CONNsFCGI_RESPONDERsFCGI_AUTHORIZERs FCGI_FILTERsFCGI_REQUEST_COMPLETEsFCGI_CANT_MPX_CONNsFCGI_OVERLOADEDsFCGI_UNKNOWN_ROLEsFCGI_MAX_CONNSs FCGI_MAX_REQSsFCGI_MPXS_CONNSs FCGI_HeadersFCGI_BeginRequestBodysFCGI_EndRequestBodysFCGI_UnknownTypeBodyscalcsizesFCGI_EndRequestBody_LENsFCGI_UnknownTypeBody_LENs __debug__stimesDEBUGsDEBUGLOGs_debugsobjects InputStreamsMultiplexedInputStreams OutputStreamsTeeOutputStreams StdoutWrappers decode_pairs encode_pairsRecordsRequests CGIRequests ConnectionsMultiplexedConnectionsServers WSGIServers__name__stest_appsrun(CsFCGI_NULL_REQUEST_IDs FCGI_MAXTYPEsFCGI_MAX_CONNSsFCGI_OVERLOADEDs InputStreamsFCGI_AUTHORIZERs OutputStreams encode_pairsFCGI_GET_VALUESs StdoutWrappers FCGI_HeadersFCGI_CANT_MPX_CONNsselectsFCGI_GET_VALUES_RESULTs CGIRequestsFCGI_BEGIN_REQUESTs FCGI_STDINsstructs__all__s FCGI_DATAsFCGI_HEADER_LENserrnos FCGI_MAX_REQSsFCGI_RESPONDERsTeeOutputStreamstest_appsFCGI_REQUEST_COMPLETEsFCGI_ABORT_REQUESTs __version__sServersthread_availablesFCGI_END_REQUESTsFCGI_BeginRequestBodysFCGI_MPXS_CONNSsRequests __author__ssyssFCGI_KEEP_CONNs ConnectionsDEBUGLOGsMultiplexedConnectionsDEBUGs FCGI_PARAMSsRecords FCGI_STDERRsFCGI_UNKNOWN_TYPEs FCGI_FILTERsFCGI_LISTENSOCK_FILENOs_debugssocketsthreadsStringIOsFCGI_UNKNOWN_ROLEssignals tracebacksFCGI_UnknownTypeBody_LENsMultiplexedInputStreamsFCGI_UnknownTypeBodys threadingsFCGI_EndRequestBodysFCGI_VERSION_1stimesFCGI_EndRequestBody_LENs WSGIServersoss FCGI_STDOUTs decode_pair((s4/home/.underwood/jarrodhroberson/vertigrated/fcgi.pys?/sš                   t*?  m,ÃVïŸ