mò "á¸Ec@s5dZdkZdkZdkZdkZdklZdkZdkl Z dk l Z dk l Z dklZdklZdklZdkZd klZlZlZlZlZlZd klZdkZd e fd „ƒYZd fd„ƒYZ ei!dƒi"Z#ei!dei$ƒZ%d„Z&dS(sr ZServer HTTPResponse The HTTPResponse class takes care of server headers, response munging and logging duties. N(sStringIO(s HTTPResponse(sIStreamIterator(sbuild_http_date(sWakeup(shooked_producer(s http_server(sShutdownProducersLoggingProducersCallbackProducersfile_part_producersfile_close_producersiterator_producer(sLongTypetZServerHTTPResponsecBs§tZdZdZdZdZdZdZdZdZ e Z e i de iƒid„Ze Ze ZdZd „Ze Zd „Zd „Zd „Zd dd„ZRS(s0Used to push data into a channel's producer fifoiis1.0tclosesZope/2.0 ZServer/2.0isc Cs„|io|iodSq$dSn|i}|i}|idƒ o=|idƒ o,|i o!|idjo|idƒn|idƒ o%|i o|i dt |ƒƒn|i ddƒ}|djo|i d|ƒng}|i} |i dd ƒ}| d |ipd |fƒ|idƒo |d=n| d |iƒ| d ttiƒƒƒ|id joK|idjo'|iidƒo|i ddƒqÍ|i ddƒn|idjo€|idjo|i ddƒq]|iidƒpE|io'|io|i ddƒd|_qY|i ddƒq]nxà|iƒD]Ò\} }| iƒ| joŸd| d iƒ| df} d} | id| ƒ}xf|| joTd| | | |d|d!iƒ| |df} |d} | id| ƒ}qÂWn| d| |fƒqjW|io||iƒ}n|i |g|t |ƒ)di!|ƒS(Ns0 ts content-typescontent-lengthiÈt nocontentitstatuss200 OKs HTTP/%s %ss1.0s Server: %ssDate: %ss keep-alivet Connections Keep-AliveRs1.1sTransfer-Encodingtchunkedis%s%st-s%s-%s%sis%s: %ss ("tselft_wrotet _chunkingtheaderstbodythas_keyt _streamingRt setStatust setHeadertlentgettNonetcontent_lengththeadersltappendt _http_versiont_server_versiontbuild_http_datettimet_http_connectiont http_chunktitemstkeytvaltlowertuppertstarttfindtltcookiest _cookie_listtaccumulated_headerstjoin( Rt html_searchR RRRR R$RRR"R((t3/data/zmath/zope/lib/python/ZServer/HTTPResponse.pyt__str__7sb    =   #   4  cCsât|ƒtdƒjotdƒ‚n|i}|ipµ|iiddƒ}|dj ojy\t|ƒtdƒjot |ƒ}n|djo"t i ƒ|_ tiƒ|_nWqÈqÈXnd|_|it|ƒƒd|_n|pdSn|iodt|ƒ|f}nt|ƒ}|i }|djp |djo|i|ƒn{|i}||}|iiƒz|i|ƒ|i|ƒWd|iiƒX||_|it||i||ƒ|ƒdS( s½ Return data as a stream HTML data may be returned using a stream-oriented interface. This allows the browser to display partial results while computation of a response to proceed. The published object should first set any output headers or cookies on the response object. Note that published objects must not generate any errors after beginning stream-oriented output. RsValue must be a stringscontent-lengthiôiNs%x %s iÈ(ttypetdatat TypeErrorRtstdoutR R RRR$tintttempfilet TemporaryFilet _tempfiletthreadt allocate_lockt _templockRtwritetstrR Rttt _tempstarttbtetacquiretseektreleasetfile_part_producer(RR-R<R/R$R;R9((R*R7ŠsH              cCsŸ|io&z|iiƒWdd|_XdSn|i}|i}|dj o#|it|ƒdƒd|_n|i |ƒ|i ƒd|_d|_ dS(Ni( Rt_retried_responset_finishRR/R3R9R7tfile_close_producertfinishRt_request(RR9R/((R*RBÅs         cCs[|id|id|iƒ}|i|_|i|_|i|_|i|_||_ |S(s>Return a request object to be used in a retry attempt R/tstderrN( Rt __class__R/RFtresponseR RRRRA(RRH((R*tretryÙs     cCsG|iit|ƒƒ|io|ii|idƒnd|_dS(sOutput the response bodyiN(RR/R7R8t _bodyproducerR(R((R*t outputBodyès  RcKswti|ƒoJ|iidƒpt‚t|ƒ|_t i |d||||Snt i |||||dS(s9 Accept either a stream iterator or a string as the body scontent-lengthRN(tIStreamIteratortisImplementedByR RR R tAssertionErrortiterator_producerRJt HTTPResponsetsetBodyttitletis_errortkw(RR RRRSRT((R*RQôs(t__name__t __module__t__doc__Rthttp_chunk_sizeRRRRR RRJtretcompiletItsearchR+R3R6R:R7RARBRIRKRQ(((R*R$s& O 9   t ChannelPipecBsJtZdZd„Zed„Zd„Zd„Zd„Zed„Z RS(síExperimental pipe from ZPublisher to a ZServer Channel. Should only be used by one thread at a time. Note also that the channel will be being handled by another thread, thus restrict access to channel to the push method only.cCs4|i|_||_d|_d|_d|_dS(Ni(trequesttchannelRt_channelREt _shutdownt_closet_bytes(RR^((R*t__init__s     cCs`|iiodSn|djot|ƒ}n|i||_|ii|dƒt ƒdS(Ni( RR`tclosedR$RRttextRctpushtWakeup(RRfR$((R*R7 s  cCsftidt|iƒd|ii|ifƒ|iipÆ|ii t |i|iƒdƒ|ii t |ii ƒdƒ|ii t dt|iƒfd„ƒdƒ|i o!|ii tƒdƒtƒn"|io|ii ddƒntƒnO|ii|iƒtidt|iƒƒ|i otd„ƒntƒd|_d|_dS(NtAs%s %sitEcCstti|ƒS(N(tapplyt DebugLoggertlogR9(R9((R*tscCs tiƒS(N(tasyncoret close_all(((R*Rn)s(RlRmtidRREt reply_codeRcR`ReRgtLoggingProducertCallbackProducertdoneRatShutdownProducerRhRbR(R((R*Rs( "'      cCsdS(N((R((R*tflush0scCsr|iƒo d|_n|iiddƒdjp|iiddƒdjo d|_n|i|i_ dS(Nit connectionRRR( RHt_shutdownRequestedRRaR RRbRRERr(RRH((R*RD2s   8 cCs–t|idƒdƒ|i_d|ii|f}|i|ƒdig}|D]}|di|ƒqS~ƒ}|i|ƒ|idƒ|iS(Nt is HTTP/%s %s s s: s ( R0RtsplitRRERrtversionR7R(t_[1]R tx(RRR texc_infoR}R~((R*tstart_response:s 3  ( RURVRWRdRR7RRwRDR€(((R*R]ÿs      s[^ ]* [^ \\]*:sProxy-Connection: (.*)cCs‘tdt|ƒdtƒƒ}|i|_|idjot|iƒo t}n t i }t i ||i ƒiƒ|_|iii|_|S(sSimple http response factoryR/RFs1.0N(RR]R^tStringIORHR|Rtis_proxying_matchtproxying_connection_ret connection_ret http_servert CONNECTIONt get_headertheaderR RR_tservert SERVER_IDENTR(R^R R„RH((R*t make_responseHs     ('RWRRYtsysR1t cStringIORR4tZPublisher.HTTPResponseRPtZPublisher.IteratorsRLtmedusa.http_dateRtPubCore.ZEventRhtmedusa.producersthooked_producertmedusaR…Rot ProducersRvRsRtR@RCROttypestLongTypeRlRR]RZtmatchR‚t IGNORECASERƒR‹(RoRRƒRhR“R@RlRtR1RLRYROR‹R‚RPRsRCRŒR—RvR]R4RRR…R((R*t?s$$         +  ÛF