U e5d';@sdZddlZddlZejdedddZGdddZGdd d ZGd d d ZGd d d eZ GdddeZ dddZ e dkre dS)aGeneric 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. Nz"the formatter module is deprecated) stacklevelc@seZdZdZd(ddZddZddZd d Zd)d d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd*d$d%Zd+d&d'ZdS), NullFormattera=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. NcCs|dkrt}||_dSN) NullWriterwriterselfrr !/usr/lib64/python3.8/formatter.py__init__)szNullFormatter.__init__cCsdSrr r blankliner r r end_paragraph-zNullFormatter.end_paragraphcCsdSrr r r r r add_line_break.rzNullFormatter.add_line_breakcOsdSrr r argskwr r r add_hor_rule/rzNullFormatter.add_hor_rulecCsdSrr r formatcounterrr r r add_label_data0rzNullFormatter.add_label_datacCsdSrr r datar r r add_flowing_data1rzNullFormatter.add_flowing_datacCsdSrr rr r r add_literal_data2rzNullFormatter.add_literal_datacCsdSrr rr r r flush_softspace3rzNullFormatter.flush_softspacecCsdSrr r alignr r r push_alignment4rzNullFormatter.push_alignmentcCsdSrr rr r r pop_alignment5rzNullFormatter.pop_alignmentcCsdSrr )r xr r r push_font6rzNullFormatter.push_fontcCsdSrr rr r r pop_font7rzNullFormatter.pop_fontcCsdSrr )r marginr r r push_margin8rzNullFormatter.push_margincCsdSrr rr r r pop_margin9rzNullFormatter.pop_margincCsdSrr r spacingr r r set_spacing:rzNullFormatter.set_spacingcGsdSrr r stylesr r r push_style;rzNullFormatter.push_stylecCsdSrr r nr r r pop_style<rzNullFormatter.pop_stylecCsdSrr r flagr r r assert_line_data=rzNullFormatter.assert_line_data)N)N)r0)r0)__name__ __module__ __qualname____doc__r rrrrrrrr"r#r%r&r(r)r,r/r3r6r r r r rs&   rc@seZdZdZddZddZddZdd Zd.d d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd/d*d+Zd0d,d-Zd S)1AbstractFormatterzThe 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. cCsR||_d|_g|_g|_g|_d|_g|_d|_d|_d|_ d|_ d|_ d|_ dSNr0r) rr! align_stack font_stack margin_stackr+ style_stacknospace softspacepara_endparskip hard_break have_labelrr r r r NszAbstractFormatter.__init__cCs`|js|jd|_|j|krD|jsD|j||j||_d|_d|_|_|_d|_dSNrr0) rErsend_line_breakrFrDsend_paragraphrArCrBr r r r r]s zAbstractFormatter.end_paragraphcCs8|js"|js"|jd|_|_d|_|_d|_dSrG)rErCrrHrFrDrArBrr r r rhs     z AbstractFormatter.add_line_breakcOsF|js|j|jj||d|_|_d|_|_|_|_dSr<) rErrH send_hor_rulerArFrCrBrDrr r r ros   zAbstractFormatter.add_hor_ruleNcCs|js |js|j|js0|j|r*dp,dt|trP|j| ||n |j|d|_ |_|_|_d|_ |_ dSr<) rFrErrHrCrI isinstancestrsend_label_dataformat_counterrArBrDrr r r rvs    z AbstractFormatter.add_label_datacCstd}|D]f}|dkr"|d|}q|dkrD|dkrn||||}q|dkrf|dkrn||||}q||}q|S)N1z%dZaArZiI) format_letter format_roman)r rrlabelcr r r rNs z AbstractFormatter.format_countercCs<d}|dkr8t|dd\}}tt||}||}q|S)NrOrr0)divmodchrord)r caserrSr$sr r r rQs  zAbstractFormatter.format_letterc Csddddg}dddg}d\}}|d krt|d \}}|d krV||||d |}nT|d krt|||||}n6|dkr||}|d}nd}||||}||}|d }q|dkr|S|S)Nir$rTmvld)rOrr r0rOI)rVupper) r rYrZonesZfivesrSindexr$rZr r r rRs&    zAbstractFormatter.format_romancCs|sdS|dd}|dd}d|}|jrD|sDdS|sN|jrv|sh|jsdd|_d|_dS|jsvd|}d|_|_|_|_|_||_|j |dS)Nr0 r) isspacejoinsplitrArBrDrErCrFrsend_flowing_data)r rZprespaceZ postspacer r r rs*  z"AbstractFormatter.add_flowing_datacCsZ|sdS|jr|jd|dddk|_d|_|_|_|_|_|j|dS)Nrhrg r) rBrrlrErArCrDrFsend_literal_datarr r r rs z"AbstractFormatter.add_literal_datacCs:|jr6d|_|_|_|_|_d|_|jddSNrr0rh)rBrErCrDrFrArrlrr r r rsz!AbstractFormatter.flush_softspacecCs@|r.||jkr.|j|||_|j|n|j|jdSr)r!r new_alignmentr=appendr r r r r"s  z AbstractFormatter.push_alignmentcCsH|jr|jd=|jr2|jd|_}|j|nd|_|jddSNrg)r=r!rrpr r r r r#szAbstractFormatter.pop_alignmentc Cs|\}}}}|jr6d|_|_|_d|_|jd|jr~|jd\}}}} |tkrZ|}|tkrf|}|tkrr|}|tkr~| }||||f}|j||j |dS)Nrr0rhrg) rBrErCrArrlr>AS_ISrqnew_font) r fontsizer[bZttZcsizeZcicbZcttr r r r%s$    zAbstractFormatter.push_fontcCs4|jr|jd=|jr |jd}nd}|j|dSrr)r>rrtr rur r r r&s  zAbstractFormatter.pop_fontcCsB|j|dd|jD}|s,|r,|d}|j|t|dS)NcSsg|] }|r|qSr r .0r\r r r sz1AbstractFormatter.push_margin..rg)r?rqr new_marginlen)r r'fstackr r r r(s  zAbstractFormatter.push_margincCsF|jr|jd=dd|jD}|r,|d}nd}|j|t|dS)NrgcSsg|] }|r|qSr r rzr r r r| sz0AbstractFormatter.pop_margin..)r?rr}r~)r rr'r r r r) s zAbstractFormatter.pop_margincCs||_|j|dSr)r+r new_spacingr*r r r r,szAbstractFormatter.set_spacingcGsV|jr*d|_|_|_d|_|jd|D]}|j|q.|jt |jdSro) rBrErCrArrlr@rq new_stylestuple)r r.Zstyler r r r/s zAbstractFormatter.push_styler0cCs$|j| d=|jt|jdSr)r@rrrr1r r r r3!szAbstractFormatter.pop_stylecCs$| |_|_d|_|_|_dSNr)rArErCrDrFr4r r r r6%sz"AbstractFormatter.assert_line_data)N)r0)r0)r7r8r9r:r rrrrrNrQrRrrrr"r#r%r&r(r)r,r/r3r6r r r r r;@s,         r;c@sxeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZdS)raMinimal 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. cCsdSrr rr r r r 2rzNullWriter.__init__cCsdSrr rr r r flush3rzNullWriter.flushcCsdSrr r r r r rp4rzNullWriter.new_alignmentcCsdSrr ryr r r rt5rzNullWriter.new_fontcCsdSrr r r'levelr r r r}6rzNullWriter.new_margincCsdSrr r*r r r r7rzNullWriter.new_spacingcCsdSrr r-r r r r8rzNullWriter.new_stylescCsdSrr r r r r rI9rzNullWriter.send_paragraphcCsdSrr rr r r rH:rzNullWriter.send_line_breakcOsdSrr rr r r rJ;rzNullWriter.send_hor_rulecCsdSrr rr r r rM<rzNullWriter.send_label_datacCsdSrr rr r r rl=rzNullWriter.send_flowing_datacCsdSrr rr r r rn>rzNullWriter.send_literal_dataN)r7r8r9r:r rrprtr}rrrIrHrJrMrlrnr r r r r*src@sheZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)AbstractWriterzA 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. cCstd|fdS)Nznew_alignment(%r)printr r r r rpIszAbstractWriter.new_alignmentcCstd|fdS)Nz new_font(%r)rryr r r rtLszAbstractWriter.new_fontcCstd||fdS)Nznew_margin(%r, %d)rrr r r r}OszAbstractWriter.new_margincCstd|fdS)Nznew_spacing(%r)rr*r r r rRszAbstractWriter.new_spacingcCstd|fdS)Nznew_styles(%r)rr-r r r rUszAbstractWriter.new_stylescCstd|fdS)Nzsend_paragraph(%r)rr r r r rIXszAbstractWriter.send_paragraphcCs tddS)Nzsend_line_break()rrr r r rH[szAbstractWriter.send_line_breakcOs tddS)Nzsend_hor_rule()rrr r r rJ^szAbstractWriter.send_hor_rulecCstd|fdS)Nzsend_label_data(%r)rrr r r rMaszAbstractWriter.send_label_datacCstd|fdS)Nzsend_flowing_data(%r)rrr r r rldsz AbstractWriter.send_flowing_datacCstd|fdS)Nzsend_literal_data(%r)rrr r r rngsz AbstractWriter.send_literal_dataN)r7r8r9r:rprtr}rrrIrHrJrMrlrnr r r r rAsrc@sJeZdZdZdddZddZdd Zd d Zd d ZddZ ddZ dS) DumbWritera;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. NHcCs(|ptj|_||_t||dSr)sysstdoutfilemaxcolrr reset)r rrr r r r ts  zDumbWriter.__init__cCsd|_d|_dSr)colatbreakrr r r rzszDumbWriter.resetcCs |jd|d|_d|_dSNrmrrwriterrr r r r rI~szDumbWriter.send_paragraphcCs|jdd|_d|_dSrrrr r r rHs zDumbWriter.send_line_breakcOs:|jd|jd|j|jdd|_d|_dS)Nrm-r)rrrrrrr r r rJs   zDumbWriter.send_hor_rulecCsV|j||d}|dkr4d|_||dd}|}|jt||_d|_dS)Nrmrr0)rrrfindr expandtabsr~r)r rr[r r r rns  zDumbWriter.send_literal_datacCs|sdS|jp|d}|j}|j}|jj}|D]N}|rl|t||kr\|dd}n|d|d}|||t|}d}q6||_|d|_dS)Nrrmrhr0rg)rrirrrrrkr~)r rrrrrZwordr r r rls$  zDumbWriter.send_flowing_data)Nr) r7r8r9r:r rrIrHrJrnrlr r r r rks  rcCst}t|}|dk r t|}n$tjddr>ttjd}ntj}z,|D]"}|dkrb|dqJ||qJW5|tjk r|X|ddS)Nr0rmr) rr;openrargvstdincloserr)rwffpliner r r tests    r__main__)N) r:rwarningswarnDeprecationWarningrsrr;rrrrr7r r r r s"k*C