mς "αΈEc@s dZdkZdfd„ƒYZdfd„ƒYZdfd„ƒYZdfd „ƒYZd fd „ƒYZd fd „ƒYZdfd„ƒYZdfd„ƒYZ dfd„ƒYZ dfd„ƒYZ y dk Z Wne j o dZ nXdfd„ƒYZdfd„ƒYZdS(s7$Id: producers.py 24763 2004-05-17 05:59:28Z philikon $Ntsimple_producercBs#tZdZdd„Zd„ZRS(sproducer for a stringicCs||_||_dS(N(tdatatselft buffer_size(RRR((t7/data/zmath/zope/lib/python/ZServer/medusa/producers.pyt__init__s cCs^t|iƒ|ijo+|i|i }|i|i|_|Sn|i}d|_|SdS(Nt(tlenRRRtresult(RR((Rtmores  (t__name__t __module__t__doc__RR (((RRs  tscanning_producercBs#tZdZdd„Zd„ZRS(s:like simple_producer, but more efficient for large stringsicCs||_||_d|_dS(Ni(RRRtpos(RRR((RR"s  cCsz|it|iƒjoY|i}tt|iƒ|i|iƒ}|i||!}|it|ƒ|_|SndSdS(NR( RRRRtlptminRtrpR(RRRR((RR 's (R R R RR (((RR s  tlines_producercBs)tZdZd„Zd„Zd„ZRS(sproducer for a list of linescCs ||_dS(N(tlinesR(RR((RR7scCs t|iƒS(N(RRR(R((Rtready:scCsG|io5|id }|id|_ti|dƒdSndSdS(Ni2s R(RRtchunktstringtjoin(RR((RR =s   (R R R RRR (((RR4s   tbuffer_list_producercBs tZdZd„Zd„ZRS(sproducer for a list of bufferscCsd|_||_dS(Ni(Rtindextbuffers(RR((RRJs cCsI|it|iƒjodSn%|i|i}|id|_|SdS(NRi(RRRRR(RR((RR Os (R R R RR (((RREs  t file_producercBs*tZdZdd>Zd„Zd„ZRS(s(producer wrapper for file[-like] objectsiicCsd|_||_dS(Ni(Rtdonetfile(RR((RR]s cCsZ|iodSnE|ii|iƒ}|p$|iiƒ|`d|_dSn|SdS(NRi(RRRtreadtout_buffer_sizeRtclose(RR((RR as   (R R R RRR (((RRWs   toutput_producercBsVtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS( s;Acts like an output file; suitable for capturing sys.stdoutcCs d|_dS(NR(RR(R((RRwscCs8ti|dƒ}ti|dƒ}|i||_dS(Ns s (Rt splitfieldsRRRR(RRR((RtwritezscCs|i|d|_dS(Ns (RRtline(RR$((Rt writelinescCs$|iti|dƒd|_dS(Ns (RRRt joinfieldsR(RR((Rt writelines‚scCst|iƒdjS(Ni(RRR(R((RRˆscCsdS(N((R((Rtflush‹scGsdS(N((Rtargs((Rt softspaceŽscCs7|io%|id }|id|_|SndSdS(NiR(RRR(RR((RR ‘s   ( R R R RR#R%R'RR(R*R (((RR!us        tcomposite_producercBs tZdZd„Zd„ZRS(s$combine a fifo of producers into onecCs ||_dS(N(t producersR(RR,((RR›scCsWxPt|iƒo;|iiƒ}|iƒ}|o|Sq|iiƒqWdSdS(NR(RRR,tfirsttpR tdtpop(RR.R/((RR žs (R R R RR (((RR+™s  tglobbing_producercBs'tZdZdd>d„Zd„ZRS(sΜ 'glob' the output from a producer into a particular buffer size. helps reduce the number of calls to send(). [this appears to gain about 30% performance on requests to a single channel] iicCs||_d|_||_dS(NR(tproducerRtbufferR(RR2R((RR±s  cCsbxIt|iƒ|ijo/|iiƒ}|o|i||_qPqW|i}d|_|S(NR(RRR3RR2R Rtr(RR4R((RR Άs  (R R R RR (((RR1ͺs thooked_producercBs tZdZd„Zd„ZRS(s¨ A producer that will call when it empties,. with an argument of the number of bytes produced. Useful for logging/instrumentation purposes. cCs||_||_d|_dS(Ni(R2Rtfunctiontbytes(RR2R6((RRΙs  cCsc|ioQ|iiƒ}|pd|_|i|iƒn|it|ƒ|_|SndSdS(NR(RR2R RtNoneR6R7R(RR((RR Ξs  (R R R RR (((RR5Βs  tchunked_producercBs#tZdZed„Zd„ZRS(s'A producer that implements the 'chunked' transfer coding for HTTP/1.1. Here is a sample usage: request['Transfer-Encoding'] = 'chunked' request.push ( producers.chunked_producer (your_producer) ) request.done() cCs||_||_dS(N(R2Rtfooters(RR2R:((RRμs cCs}|iok|iiƒ}|odt|ƒ|fSqyd|_|io"tidg|idƒdSqydSndSdS(Ns%x %s t0s s s0 R( RR2R RRR8R:RR(RR((RR πs   (R R R R8RR (((RR9βs  tcompressed_producercBs#tZdZdd„Zd„ZRS(s Compress another producer on-the-fly, using ZLIB [Unfortunately, none of the current browsers seem to support this] icCs||_ti|ƒ|_dS(N(R2Rtzlibt compressobjtlevelt compressor(RR2R?((RRs cCsq|io_d}xN|pF|iiƒ}|pd|_|iiƒSq|ii|ƒ}qW|SndSdS(NR( RR2tcdataR RR8R@R(tcompress(RRRA((RR s  (R R R RR (((RR< s  tescaping_producercBs&tZdZddd„Zd„ZRS(s0A producer that escapes a sequence of characterss .s ..cCs>||_||_||_d|_dkl}||_dS(NR(sfind_prefix_at_end(R2Rtesc_fromtesc_toR3tasynchattfind_prefix_at_end(RR2RDRERG((RR1s      cCs‘|i}|i}|i|iiƒ}|oZti|||ƒ}|i||ƒ}|o|| |_|| Sqd|_|Sn|SdS(NR( RRDRER3R2R RtreplaceRGti(RRER3RIRD((RR 9s    (R R R RR (((RRC,s (tRCS_IDRRR RRRR!R+R1R5R9R=t ImportErrorR8R<RC(R5RCR<RRRJR=RR9RR R1R!R+R((Rt?s$ $ $  !