mς %U²Ic@s?dZddgZdefd„ƒYZdfd„ƒYZdS(s­A readline()-style interface to the parts of a multipart message. The MultiFile class makes each part of a multipart message "feel" like an ordinary file, as long as you use fp.readline(). Allows recursive use, for nested multipart messages. Probably best used together with module mimetools. Suggested use: real_fp = open(...) fp = MultiFile(real_fp) "read some lines from fp" fp.push(separator) while 1: "read lines from fp until it returns an empty string" (A) if not fp.next(): break fp.pop() "read remaining lines from fp until it returns an empty string" The latter sequence may be used recursively at (A). It is also allowed to use multiple push()...pop() sequences. If seekable is given as 0, the class code will not do the bookkeeping it normally attempts in order to make seeks relative to the beginning of the current file part. This may be useful when using MultiFile with a non- seekable stream object. t MultiFiletErrorcBstZRS(N(t__name__t __module__(((t&/data/zmath/lib/python2.4/multifile.pyR scBs€tZdZdd„Zd„Zdd„Zd„Zd„Zd„Zd „Z d „Z d „Z d „Z d „Z d„ZRS(NiicCsW||_g|_d|_d|_|o(d|_|iiƒ|_g|_ndS(Nii( tfptselftstacktleveltlasttseekablettelltstarttposstack(RRR ((Rt__init__'s     cCs/|idjo |iSn|iiƒ|iS(Ni(RRtlastposRR R (R((RR 1s cCsζ|iƒ}|oZ|djo||}qm|djo.|idjo||i}qitd‚qmnd|jo |jn p |idjo||ijo td‚n|ii ||i ƒd|_d|_ dS(Niiiscan't use whence=2 yetsbad MultiFile.seek() call( RR theretwhencetposRRRRtseekR R (RRRR((RR6s   ?  cCs\|idjodSn|iiƒ}|pCt|iƒ|_|idj|_|io td‚ndSn|i |ƒo|Sn |i ƒ}xot t |iƒƒD]T\}}||i|ƒjod|_Pq«||i|ƒjod|_Pq«q«W|S|io|iƒt|ƒ|_n|d|_|idjo td‚ndS(Nits"sudden EOF in MultiFile.readline()is)Missing endmarker in MultiFile.readline()(RRRtreadlinetlinetlenRR Rtis_datatrstriptmarkert enumeratetreversedtitseptsection_dividert end_markerR R R(RRRRR((RRGs8          cCs7g}x*|iƒ}|pPn|i|ƒq W|S(Ni(tlistRRRtappend(RR!R((Rt readlinesls cCsdi|iƒƒS(NR(tjoinRR#(R((RtreadtscCsmx|iƒoqW|idjp |iodSnd|_d|_|io|iiƒ|_ndS(Nii(RRRR R RR R (R((Rtnextws    cCsd|idjo td‚n|ii|ƒ|io)|ii|iƒ|i i ƒ|_ndS(Nisbad MultiFile.push() call( RRRRR"RR R R RR (RR((Rtpushs   cCsΈ|igjo td‚n|idjo d|_n|i|i}td|idƒ|_|ii ƒ|i o:|i i ƒ|_|idjo||i|_q΄ndS(Nsbad MultiFile.pop() callii( RRRRR RR t abslastpostmaxtpopR R (RR(((RR*‰s    cCs|d djS(Nis--(R(RR((RR—scCsd|S(Ns--(tstr(RR+((RRšscCs d|dS(Ns--(R+(RR+((RR s(RRR RR RRR#R%R&R'R*RRR (((RR#s   %      N(t__doc__t__all__t ExceptionRR(RR-R((Rt?s