mò %U²Ic@s¢dZdkZdZdfd„ƒYZdfd„ƒYZdfd„ƒYZdefd „ƒYZd efd „ƒYZdd „Z e d jo e ƒndS(sGeneric output formatting. Formatter objects transform an abstract flow of formatting events into specific output events on writer objects. Formatters manage several stack structures to allow various properties of a writer object to be changed and restored; writers need not be able to handle relative changes nor any sort of ``change back'' operation. Specific writer properties which may be controlled via formatter objects are horizontal alignment, font, and left margin indentations. A mechanism is provided which supports providing arbitrary, non-exclusive style settings to a writer as well. Additional interfaces facilitate formatting events which are not reversible, such as paragraph separation. Writer objects encapsulate device interfaces. Abstract devices, such as file formats, are supported as well as physical devices. The provided implementations all work with abstract devices. The interface makes available mechanisms for setting the properties which formatter objects manage and inserting data into the output. Nt NullFormattercBs¼tZdZed„Zd„Zd„Zd„Zed„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„Zd„Zd„Zdd„Zdd„ZRS(s=A formatter which does nothing. If the writer parameter is omitted, a NullWriter instance is created. No methods of the writer are called by NullFormatter instances. Implementations should inherit from this class if implementing a writer interface but don't need to inherit any implementation. cCs'|djo tƒ}n||_dS(N(twritertNonet NullWritertself(RR((t&/data/zmath/lib/python2.4/formatter.pyt__init__&s  cCsdS(N((Rt blankline((Rt end_paragraph*scCsdS(N((R((Rtadd_line_break+scOsdS(N((Rtargstkw((Rt add_hor_rule,scCsdS(N((RtformattcounterR((Rtadd_label_data-scCsdS(N((Rtdata((Rtadd_flowing_data.scCsdS(N((RR((Rtadd_literal_data/scCsdS(N((R((Rtflush_softspace0scCsdS(N((Rtalign((Rtpush_alignment1scCsdS(N((R((Rt pop_alignment2scCsdS(N((Rtx((Rt push_font3scCsdS(N((R((Rtpop_font4scCsdS(N((Rtmargin((Rt push_margin5scCsdS(N((R((Rt pop_margin6scCsdS(N((Rtspacing((Rt set_spacing7scGsdS(N((Rtstyles((Rt push_style8sicCsdS(N((Rtn((Rt pop_style9scCsdS(N((Rtflag((Rtassert_line_data:s(t__name__t __module__t__doc__RRRR R RRRRRRRRRRRR R"R$(((RRs&                  tAbstractFormattercBsÔtZdZd„Zd„Zd„Zd„Zed„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zdd„Zdd„ZRS(sêThe standard formatter. This implementation has demonstrated wide applicability to many writers, and may be used directly in most circumstances. It has been used to implement a full-featured World Wide Web browser. cCsy||_d|_g|_g|_g|_d|_g|_d|_ d|_ d|_ d|_ d|_ d|_dS(Nii(RRRRt align_stackt font_stackt margin_stackRt style_stacktnospacet softspacetpara_endtparskipt hard_breakt have_label(RR((RRKs            cCs|ip|iiƒd|_n|i|jo8|i o-|ii||iƒ||_d|_nd|_|_|_ d|_ dS(Nii( RR1Rtsend_line_breakR2R0Rtsend_paragraphR-R/R.(RR((RRZs     cCsR|ip|ip!|iiƒd|_|_nd|_|_d|_dS(Nii( RR1R/RR3R2R0R-R.(R((RR es  cOs`|ip|iiƒn|ii||Žd|_|_d|_|_ |_ |_ dS(Nii( RR1RR3t send_hor_ruleR R R-R2R/R.R0(RR R ((RR ls  cCsÄ|ip |i o|iiƒn|ip"|ii|odpdƒnt|t ƒo |ii |i ||ƒƒn|ii |ƒd|_|_|_|_d|_|_dS(Nii(RR2R1RR3R/R4Rt isinstanceR tstrtsend_label_datatformat_counterRR-R.R0(RR RR((RRss " cCs´d}x§|D]Ÿ}|djo|d|}q |djo+|djo||i||ƒ}q¬q |djo+|djo||i||ƒ}q¬q ||}q W|S(Ntt1s%dtaAitiI(tlabelR tcRRt format_lettert format_roman(RR RR?R>((RR9s     cCsXd}xK|djo=t|ddƒ\}}tt|ƒ|ƒ}||}q W|S(NR:iii(R>RtdivmodRtchrtordtcasets(RRERR>RFR((RR@Žs c Csddddg}dddg}d\}}xÊ|d jo¼t|d ƒ\}}|d jo||||d |}no|d jo|||||}nH|djo||}|d}nd}||||}||}|d }q0W|djo|i ƒSn|S(NtiRR?tmtvtltdR:ii i iiitI(R:i( tonestfivesR>tindexRRBRRFREtupper( RRERRORNR>RFRMR((RRA™s(        cCsü|pdSn|d iƒ}|diƒ}di|iƒƒ}|io| odSn]|p |ioK|p(|ipd|_d|_ ndSn|ipd|}qºnd|_ |_|_ |_ |_ ||_|i i|ƒdS(Niiÿÿÿÿt i(Rtisspacetprespacet postspacetjointsplitRR-R.R0R1R/R2Rtsend_flowing_data(RRRSRT((RR±s$    % cCsy|pdSn|io|iidƒn|ddj|_d|_|_|_|_|_ |ii |ƒdS(NRQiÿÿÿÿs i( RRR.RRWR1R-R/R0R2tsend_literal_data(RR((RRÇs %cCsP|ioBd|_|_|_|_|_d|_|iidƒndS(NiiRQ( RR.R1R/R0R2R-RRW(R((RRÐs % cCs[|o=||ijo-|ii|ƒ||_|ii|ƒn|ii|iƒdS(N(RRRt new_alignmentR)tappend(RR((RR×s  cCsg|io|id=n|io(|id|_}|ii|ƒnd|_|iidƒdS(Niÿÿÿÿ(RR)RRRYR(RR((RRßs   c Cs |\}}}}|io4d|_|_|_d|_|i i dƒn|i oy|i d\} }}}|tjo | }n|tjo |}n|tjo |}n|tjo |}qÓn||||f} |i i| ƒ|i i| ƒdS(NiiRQiÿÿÿÿ(tsizeRGtbtttRR.R1R/R-RRWR*tcsizetcitcbtctttAS_IStfontRZtnew_font( Rt.2R[RGR\R]RaR_R`R^Rc((RRés"       cCsM|io|id=n|io|id}nd}|ii|ƒdS(Niÿÿÿÿ(RR*RcRRRd(RRc((RRøs   cCs\|ii|ƒtd|iƒ}| o|o|d}n|ii|t |ƒƒdS(Niÿÿÿÿ( RR+RZRtfilterRtfstackRt new_margintlen(RRRg((RRs cCsb|io|id=ntd|iƒ}|o|d}nd}|ii|t|ƒƒdS(Niÿÿÿÿ( RR+RfRRgRRRhRi(RRgR((RRs cCs||_|ii|ƒdS(N(RRRt new_spacing(RR((RRs cGs||io4d|_|_|_d|_|iidƒnx|D]}|i i |ƒqEW|ii t |i ƒƒdS(NiiRQ( RR.R1R/R-RRWRtstyleR,RZt new_stylesttuple(RRRk((RR s  icCs(|i| 3|iit|iƒƒdS(N(RR,R!RRlRm(RR!((RR"s cCs,| |_|_d|_|_|_dS(Ni(R#RR-R1R/R0R2(RR#((RR$#s(R%R&R'RRR R RRR9R@RARRRRRRRRRRR R"R$(((RR(=s,             RcBsƒtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „ZRS(sMinimal writer interface to use in testing & inheritance. A writer which only provides the interface definition; no actions are taken on any methods. This should be the base class for all writers which do not need to inherit any implementation methods. cCsdS(N((R((RR0scCsdS(N((R((Rtflush1scCsdS(N((RR((RRY2scCsdS(N((RRc((RRd3scCsdS(N((RRtlevel((RRh4scCsdS(N((RR((RRj5scCsdS(N((RR((RRl6scCsdS(N((RR((RR47scCsdS(N((R((RR38scOsdS(N((RR R ((RR59scCsdS(N((RR((RR8:scCsdS(N((RR((RRW;scCsdS(N((RR((RRX<s(R%R&R'RRnRYRdRhRjRlR4R3R5R8RWRX(((RR(s             tAbstractWritercBsqtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z RS( s°A writer which can be used in debugging formatters, but not much else. Each method simply announces itself by printing its name and arguments on standard output. cCsd|fGHdS(Nsnew_alignment(%r)(R(RR((RRYGscCsd|fGHdS(Ns new_font(%r)(Rc(RRc((RRdJscCsd||fGHdS(Nsnew_margin(%r, %d)(RRo(RRRo((RRhMscCsd|fGHdS(Nsnew_spacing(%r)(R(RR((RRjPscCsd|fGHdS(Nsnew_styles(%r)(R(RR((RRlSscCsd|fGHdS(Nssend_paragraph(%r)(R(RR((RR4VscCs dGHdS(Nssend_line_break()((R((RR3YscOs dGHdS(Nssend_hor_rule()((RR R ((RR5\scCsd|fGHdS(Nssend_label_data(%r)(R(RR((RR8_scCsd|fGHdS(Nssend_flowing_data(%r)(R(RR((RRWbscCsd|fGHdS(Nssend_literal_data(%r)(R(RR((RRXes(R%R&R'RYRdRhRjRlR4R3R5R8RWRX(((RRp?s           t DumbWritercBsStZdZedd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS( s;Simple writer class which writes output on the file object passed in as the file parameter or, if file is omitted, on standard output. The output is simply word-wrapped to the number of columns specified by the maxcol parameter. This class is suitable for reflowing a sequence of paragraphs. iHcCs7|pti|_||_ti|ƒ|iƒdS(N(tfiletsyststdoutRtmaxcolRRtreset(RRrRu((RRrs  cCsd|_d|_dS(Ni(Rtcoltatbreak(R((RRvxs cCs*|iid|ƒd|_d|_dS(Ns i(RRrtwriteRRwRx(RR((RR4|s cCs&|iidƒd|_d|_dS(Ns i(RRrRyRwRx(R((RR3s cOsM|iidƒ|iid|iƒ|iidƒd|_d|_dS(Ns t-i(RRrRyRuRwRx(RR R ((RR5†s  cCsv|ii|ƒ|idƒ}|djod|_||d}n|iƒ}|it|ƒ|_d|_ dS(Ns ii( RRrRyRtrfindRGRwt expandtabsRiRx(RRRG((RRXs   cCsè|pdSn|ip|diƒ}|i}|i}|ii}x~|iƒD]p}|oC|t |ƒ|jo|dƒd}q¤|dƒ|d}n||ƒ|t |ƒ}d}qTW||_|diƒ|_dS(Nis RQiiÿÿÿÿ( RRRxRRRwRuRrRyRVtwordRi(RRRuR}RyRwRx((RRW—s&          ( R%R&R'RRRvR4R3R5RXRW(((RRqis      cCs¼tƒ}t|ƒ}|dj ot|ƒ}n/ti dotti dƒ}n ti }xH|i ƒ}|pPn|djo|i dƒqc|i|ƒqcW|i dƒdS(Nis i(RqtwR(tfRrRtopentfpRstargvtstdintreadlinetlineRR(RrRRR~R…((Rttest¬s       t__main__( R'RsRRbRR(RRpRqR†R%(RRRpRsR(RqR†Rb((Rt?s "ë*C