zfc@sedZddlmZededd[ddgZdefdYZdd d YZd S( sA 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. i(twarns9the multifile module has been deprecated since Python 2.5t stacklevelit MultiFiletErrorcBseZRS((t__name__t __module__(((s!/usr/lib64/python2.7/multifile.pyR$scBseZdZddZdZddZdZdZdZdZ d Z d Z d Z d Z d ZRS(iicCsU||_g|_d|_d|_|rQd|_|jj|_g|_ndS(Nii(tfptstacktleveltlasttseekablettelltstarttposstack(tselfRR ((s!/usr/lib64/python2.7/multifile.pyt__init__+s     cCs*|jdkr|jS|jj|jS(Ni(RtlastposRR R (R((s!/usr/lib64/python2.7/multifile.pyR 5scCs|j}|re|dkr+||}qe|dkre|jdkrV||j}qbtdqend|ko||kn s|jdkr||jkrtdn|jj||jd|_d|_dS(Niiiscan't use whence=2 yetsbad MultiFile.seek() call(R RRRRtseekR R (Rtpostwhencethere((s!/usr/lib64/python2.7/multifile.pyR:s      cCsX|jdkrdS|jj}|set|j|_|jdk|_|jratdndS|jdkszt|j|r|S|j }xkt t |jD]P\}}||j |krd|_Pq||j |krd|_PqqW|S|jr,|jt||_n|d|_|jdkrTtdndS(Nits"sudden EOF in MultiFile.readline()is)Missing endmarker in MultiFile.readline()(RRtreadlinetlenRR RtAssertionErrortis_datatrstript enumeratetreversedtsection_dividert end_markerR R R(Rtlinetmarkertitsep((s!/usr/lib64/python2.7/multifile.pyRKs6   "     cCs4g}x'|j}|sPn|j|q W|S(N(Rtappend(RtlistR((s!/usr/lib64/python2.7/multifile.pyt readlinesps cCsdj|jS(NR(tjoinR%(R((s!/usr/lib64/python2.7/multifile.pytreadxscCscx|jrqW|jdks+|jr/dSd|_d|_|jr_|jj|_ndS(Nii(RRR R RR R (R((s!/usr/lib64/python2.7/multifile.pytnext{s   cCs`|jdkrtdn|jj||jr\|jj|j|jj|_ndS(Nisbad MultiFile.push() call( RRRR#R R R RR (RR"((s!/usr/lib64/python2.7/multifile.pytpushs   cCs|jgkrtdn|jdkr6d|_n|j|j}td|jd|_|jj|jr|j j|_|jdkr||j|_qndS(Nsbad MultiFile.pop() callii( RRRR RR tmaxtpopR R (Rt abslastpos((s!/usr/lib64/python2.7/multifile.pyR+s    cCs|d dkS(Nis--((RR((s!/usr/lib64/python2.7/multifile.pyRscCsd|S(Ns--((Rtstr((s!/usr/lib64/python2.7/multifile.pyRscCs d|dS(Ns--((RR-((s!/usr/lib64/python2.7/multifile.pyRs(RRR RR RRR%R'R(R)R+RRR(((s!/usr/lib64/python2.7/multifile.pyR's   %      N((t__doc__twarningsRtDeprecationWarningt__all__t ExceptionRR(((s!/usr/lib64/python2.7/multifile.pyts