ž §˙fR:c@sŚdZddlZdZGdd„dƒZGdd„dƒZGdd„dƒZGd d „d eƒZGd d „d eƒZdd d„Z e dkr˘e ƒndS(uGeneric 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. iNcBsţ|EeZdZdZd'dd„Zdd„Zdd„Zdd „Zd'd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#d$„Zd"d%d&„Zd'S((u NullFormatteru=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%|dkrtƒ}n||_dS(N(uNoneu NullWriteruwriter(uselfuwriter((u./opt/alt/python33/lib64/python3.3/formatter.pyu__init__&s  uNullFormatter.__init__cCsdS(N((uselfu blankline((u./opt/alt/python33/lib64/python3.3/formatter.pyu end_paragraph*suNullFormatter.end_paragraphcCsdS(N((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_line_break+suNullFormatter.add_line_breakcOsdS(N((uselfuargsukw((u./opt/alt/python33/lib64/python3.3/formatter.pyu add_hor_rule,suNullFormatter.add_hor_rulecCsdS(N((uselfuformatucounteru blankline((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_label_data-suNullFormatter.add_label_datacCsdS(N((uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_flowing_data.suNullFormatter.add_flowing_datacCsdS(N((uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_literal_data/suNullFormatter.add_literal_datacCsdS(N((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyuflush_softspace0suNullFormatter.flush_softspacecCsdS(N((uselfualign((u./opt/alt/python33/lib64/python3.3/formatter.pyupush_alignment1suNullFormatter.push_alignmentcCsdS(N((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyu pop_alignment2suNullFormatter.pop_alignmentcCsdS(N((uselfux((u./opt/alt/python33/lib64/python3.3/formatter.pyu push_font3suNullFormatter.push_fontcCsdS(N((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyupop_font4suNullFormatter.pop_fontcCsdS(N((uselfumargin((u./opt/alt/python33/lib64/python3.3/formatter.pyu push_margin5suNullFormatter.push_margincCsdS(N((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyu pop_margin6suNullFormatter.pop_margincCsdS(N((uselfuspacing((u./opt/alt/python33/lib64/python3.3/formatter.pyu set_spacing7suNullFormatter.set_spacingcGsdS(N((uselfustyles((u./opt/alt/python33/lib64/python3.3/formatter.pyu push_style8suNullFormatter.push_styleicCsdS(N((uselfun((u./opt/alt/python33/lib64/python3.3/formatter.pyu pop_style9suNullFormatter.pop_stylecCsdS(N((uselfuflag((u./opt/alt/python33/lib64/python3.3/formatter.pyuassert_line_data:suNullFormatter.assert_line_dataN(u__name__u __module__u __qualname__u__doc__uNoneu__init__u end_paragraphuadd_line_breaku add_hor_ruleuadd_label_datauadd_flowing_datauadd_literal_datauflush_softspaceupush_alignmentu pop_alignmentu push_fontupop_fontu push_marginu pop_marginu set_spacingu push_styleu pop_styleuassert_line_data(u __locals__((u./opt/alt/python33/lib64/python3.3/formatter.pyu NullFormatters&               u NullFormattercBs|EeZdZdZdd„Zdd„Zdd„Zdd „Zd-d d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)d*„Zd(d+d,„Zd-S(.uAbstractFormatteruę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(uwriteruNoneualignu align_stacku font_stacku margin_stackuspacingu style_stackunospaceu softspaceupara_enduparskipu hard_breaku have_label(uselfuwriter((u./opt/alt/python33/lib64/python3.3/formatter.pyu__init__Ks            uAbstractFormatter.__init__cCs‹|js"|jjƒd|_n|j|krg|j rg|jj||jƒ||_d|_nd|_|_|_d|_dS(Nii( u hard_breakuwriterusend_line_breaku have_labeluparskipusend_paragraphunospaceupara_endu softspace(uselfu blankline((u./opt/alt/python33/lib64/python3.3/formatter.pyu end_paragraphZs     uAbstractFormatter.end_paragraphcCsO|jp|js2|jjƒd|_|_nd|_|_d|_dS(Nii(u hard_breakupara_enduwriterusend_line_breaku have_labeluparskipunospaceu softspace(uself((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_line_breakes  u AbstractFormatter.add_line_breakcOs^|js|jjƒn|jj||Žd|_|_d|_|_|_|_dS(Nii( u hard_breakuwriterusend_line_breaku send_hor_ruleunospaceu have_labelupara_endu softspaceuparskip(uselfuargsukw((u./opt/alt/python33/lib64/python3.3/formatter.pyu add_hor_rulels  uAbstractFormatter.add_hor_rulecCsť|js|j r#|jjƒn|jsK|jj|rAdpDdƒnt|tƒry|jj|j ||ƒƒn|jj|ƒd|_ |_|_|_d|_ |_ dS(Nii( u have_labelu hard_breakuwriterusend_line_breakupara_endusend_paragraphu isinstanceustrusend_label_datauformat_counterunospaceu softspaceuparskip(uselfuformatucounteru blankline((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_label_datass u AbstractFormatter.add_label_datacCsŞd}x|D]•}|dkr0|d|}q |dkrd|dkr˘||j||ƒ}q˘q |dkr˜|dkr˘||j||ƒ}q˘q ||}q W|S(Nuu1u%duaAiuiI(u format_letteru format_roman(uselfuformatucounterulabeluc((u./opt/alt/python33/lib64/python3.3/formatter.pyuformat_counters      u AbstractFormatter.format_countercCsVd}xI|dkrQt|ddƒ\}}tt|ƒ|ƒ}||}q W|S(Nuiii(udivmoduchruord(uselfucaseucounterulabeluxus((u./opt/alt/python33/lib64/python3.3/formatter.pyu format_letterŽs uAbstractFormatter.format_letterc Cs ddddg}dddg}d\}}xÂ|d krńt|d ƒ\}}|d krz||||d |}nj|d krŸ|||||}nE|dkrÂ||}|d}nd}||||}||}|d }q0W|dkr|jƒS|S(Nuiuxucumuvuluduii i iiiuI(ui(udivmoduupper( uselfucaseucounteruonesufivesulabeluindexuxus((u./opt/alt/python33/lib64/python3.3/formatter.pyu format_roman™s&         uAbstractFormatter.format_romancCsń|s dS|dd…jƒ}|dd…jƒ}dj|jƒƒ}|jr_| r_dS|sn|jrŻ|s–|js’d|_d|_ndS|jsŻd|}qŻnd|_|_|_|_|_||_|j j |ƒdS(Niu ii˙˙˙˙( uisspaceujoinusplitunospaceu softspaceuparskipu hard_breakupara_endu have_labeluwriterusend_flowing_data(uselfudatauprespaceu postspace((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_flowing_dataąs$    % u"AbstractFormatter.add_flowing_datacCsx|s dS|jr&|jjdƒn|dd…dk|_d|_|_|_|_|_|jj|ƒdS(Nu iu ii˙˙˙˙( u softspaceuwriterusend_flowing_datau hard_breakunospaceupara_enduparskipu have_labelusend_literal_data(uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyuadd_literal_dataĹs %u"AbstractFormatter.add_literal_datacCsN|jrJd|_|_|_|_|_d|_|jjdƒndS(Niiu (u softspaceu hard_breakupara_enduparskipu have_labelunospaceuwriterusend_flowing_data(uself((u./opt/alt/python33/lib64/python3.3/formatter.pyuflush_softspaceÎs % u!AbstractFormatter.flush_softspacecCsX|rA||jkrA|jj|ƒ||_|jj|ƒn|jj|jƒdS(N(ualignuwriteru new_alignmentu align_stackuappend(uselfualign((u./opt/alt/python33/lib64/python3.3/formatter.pyupush_alignmentŐs  u AbstractFormatter.push_alignmentcCsc|jr|jd=n|jrF|jd|_}|jj|ƒnd|_|jjdƒdS(Nii˙˙˙˙i˙˙˙˙(u align_stackualignuwriteru new_alignmentuNone(uselfualign((u./opt/alt/python33/lib64/python3.3/formatter.pyu pop_alignmentÝs    uAbstractFormatter.pop_alignmentc Csý|\}}}}|jrNd|_|_|_d|_|jjdƒn|jrÇ|jd\}}}} |tkr…|}n|tkrš|}n|tkrŻ|}n|tkrÇ| }qÇn||||f}|jj|ƒ|jj |ƒdS(Niiu i˙˙˙˙( u softspaceu hard_breakupara_endunospaceuwriterusend_flowing_datau font_stackuAS_ISuappendunew_font( uselfufontusizeuiubuttucsizeuciucbuctt((u./opt/alt/python33/lib64/python3.3/formatter.pyu push_fontçs$       uAbstractFormatter.push_fontcCsI|jr|jd=n|jr/|jd}nd}|jj|ƒdS(Nii˙˙˙˙i˙˙˙˙(u font_stackuNoneuwriterunew_font(uselfufont((u./opt/alt/python33/lib64/python3.3/formatter.pyupop_font÷s    uAbstractFormatter.pop_fontcCs]|jj|ƒdd„|jDƒ}| r@|r@|d}n|jj|t|ƒƒdS(NcSsg|]}|r|‘qS(((u.0um((u./opt/alt/python33/lib64/python3.3/formatter.pyu s u1AbstractFormatter.push_margin..ii˙˙˙˙(u margin_stackuappenduwriteru new_marginulen(uselfumarginufstack((u./opt/alt/python33/lib64/python3.3/formatter.pyu push_margins   uAbstractFormatter.push_margincCsb|jr|jd=ndd„|jDƒ}|r?|d}nd}|jj|t|ƒƒdS(NicSsg|]}|r|‘qS(((u.0um((u./opt/alt/python33/lib64/python3.3/formatter.pyu s u0AbstractFormatter.pop_margin..i˙˙˙˙i˙˙˙˙(u margin_stackuNoneuwriteru new_marginulen(uselfufstackumargin((u./opt/alt/python33/lib64/python3.3/formatter.pyu pop_margins   uAbstractFormatter.pop_margincCs||_|jj|ƒdS(N(uspacinguwriteru new_spacing(uselfuspacing((u./opt/alt/python33/lib64/python3.3/formatter.pyu set_spacings uAbstractFormatter.set_spacingcGsz|jr<d|_|_|_d|_|jjdƒnx|D]}|jj|ƒqCW|jjt |jƒƒdS(Niiu ( u softspaceu hard_breakupara_endunospaceuwriterusend_flowing_datau style_stackuappendu new_stylesutuple(uselfustylesustyle((u./opt/alt/python33/lib64/python3.3/formatter.pyu push_styles   uAbstractFormatter.push_styleicCs.|j| d…=|jjt|jƒƒdS(N(u style_stackuwriteru new_stylesutuple(uselfun((u./opt/alt/python33/lib64/python3.3/formatter.pyu pop_stylesuAbstractFormatter.pop_stylecCs,| |_|_d|_|_|_dS(Ni(unospaceu hard_breakupara_enduparskipu have_label(uselfuflag((u./opt/alt/python33/lib64/python3.3/formatter.pyuassert_line_data"su"AbstractFormatter.assert_line_dataN(u__name__u __module__u __qualname__u__doc__u__init__u end_paragraphuadd_line_breaku add_hor_ruleuNoneuadd_label_datauformat_counteru format_letteru format_romanuadd_flowing_datauadd_literal_datauflush_softspaceupush_alignmentu pop_alignmentu push_fontupop_fontu push_marginu pop_marginu set_spacingu push_styleu pop_styleuassert_line_data(u __locals__((u./opt/alt/python33/lib64/python3.3/formatter.pyuAbstractFormatter=s,            uAbstractFormattercBsś|EeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS(u NullWriteruMinimal 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((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyu__init__/suNullWriter.__init__cCsdS(N((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyuflush0suNullWriter.flushcCsdS(N((uselfualign((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_alignment1suNullWriter.new_alignmentcCsdS(N((uselfufont((u./opt/alt/python33/lib64/python3.3/formatter.pyunew_font2suNullWriter.new_fontcCsdS(N((uselfumarginulevel((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_margin3suNullWriter.new_margincCsdS(N((uselfuspacing((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_spacing4suNullWriter.new_spacingcCsdS(N((uselfustyles((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_styles5suNullWriter.new_stylescCsdS(N((uselfu blankline((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_paragraph6suNullWriter.send_paragraphcCsdS(N((uself((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_line_break7suNullWriter.send_line_breakcOsdS(N((uselfuargsukw((u./opt/alt/python33/lib64/python3.3/formatter.pyu send_hor_rule8suNullWriter.send_hor_rulecCsdS(N((uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_label_data9suNullWriter.send_label_datacCsdS(N((uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_flowing_data:suNullWriter.send_flowing_datacCsdS(N((uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_literal_data;suNullWriter.send_literal_dataN(u__name__u __module__u __qualname__u__doc__u__init__uflushu new_alignmentunew_fontu new_marginu new_spacingu new_stylesusend_paragraphusend_line_breaku send_hor_ruleusend_label_datausend_flowing_datausend_literal_data(u __locals__((u./opt/alt/python33/lib64/python3.3/formatter.pyu NullWriter's            u NullWritercBsž|EeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„ZdS(uAbstractWriteru°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. cCstd|fƒdS(Nunew_alignment(%r)(uprint(uselfualign((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_alignmentFsuAbstractWriter.new_alignmentcCstd|fƒdS(Nu new_font(%r)(uprint(uselfufont((u./opt/alt/python33/lib64/python3.3/formatter.pyunew_fontIsuAbstractWriter.new_fontcCstd||fƒdS(Nunew_margin(%r, %d)(uprint(uselfumarginulevel((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_marginLsuAbstractWriter.new_margincCstd|fƒdS(Nunew_spacing(%r)(uprint(uselfuspacing((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_spacingOsuAbstractWriter.new_spacingcCstd|fƒdS(Nunew_styles(%r)(uprint(uselfustyles((u./opt/alt/python33/lib64/python3.3/formatter.pyu new_stylesRsuAbstractWriter.new_stylescCstd|fƒdS(Nusend_paragraph(%r)(uprint(uselfu blankline((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_paragraphUsuAbstractWriter.send_paragraphcCstdƒdS(Nusend_line_break()(uprint(uself((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_line_breakXsuAbstractWriter.send_line_breakcOstdƒdS(Nusend_hor_rule()(uprint(uselfuargsukw((u./opt/alt/python33/lib64/python3.3/formatter.pyu send_hor_rule[suAbstractWriter.send_hor_rulecCstd|fƒdS(Nusend_label_data(%r)(uprint(uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_label_data^suAbstractWriter.send_label_datacCstd|fƒdS(Nusend_flowing_data(%r)(uprint(uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_flowing_dataasu AbstractWriter.send_flowing_datacCstd|fƒdS(Nusend_literal_data(%r)(uprint(uselfudata((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_literal_datadsu AbstractWriter.send_literal_dataN(u__name__u __module__u __qualname__u__doc__u new_alignmentunew_fontu new_marginu new_spacingu new_stylesusend_paragraphusend_line_breaku send_hor_ruleusend_label_datausend_flowing_datausend_literal_data(u __locals__((u./opt/alt/python33/lib64/python3.3/formatter.pyuAbstractWriter>s          uAbstractWritercBst|EeZdZdZdddd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dS(u DumbWriteru;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. iHcCs6|p tj|_||_tj|ƒ|jƒdS(N(usysustdoutufileumaxcolu NullWriteru__init__ureset(uselfufileumaxcol((u./opt/alt/python33/lib64/python3.3/formatter.pyu__init__qs  uDumbWriter.__init__cCsd|_d|_dS(Ni(ucoluatbreak(uself((u./opt/alt/python33/lib64/python3.3/formatter.pyuresetws uDumbWriter.resetcCs*|jjd|ƒd|_d|_dS(Nu i(ufileuwriteucoluatbreak(uselfu blankline((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_paragraph{s uDumbWriter.send_paragraphcCs&|jjdƒd|_d|_dS(Nu i(ufileuwriteucoluatbreak(uself((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_line_break€s uDumbWriter.send_line_breakcOsM|jjdƒ|jjd|jƒ|jjdƒd|_d|_dS(Nu u-i(ufileuwriteumaxcolucoluatbreak(uselfuargsukw((u./opt/alt/python33/lib64/python3.3/formatter.pyu send_hor_rule…s  uDumbWriter.send_hor_rulecCsz|jj|ƒ|jdƒ}|dkrKd|_||dd…}n|jƒ}|jt|ƒ|_d|_dS(Nu ii(ufileuwriteurfinducolu expandtabsulenuatbreak(uselfudataui((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_literal_dataŒs   uDumbWriter.send_literal_datacCsŢ|s dS|jp |djƒ}|j}|j}|jj}xz|jƒD]l}|rš|t|ƒ|krƒ|dƒd}qš|dƒ|d}n||ƒ|t|ƒ}d}qNW||_|djƒ|_dS(Niu u ii˙˙˙˙(uatbreakuisspaceucolumaxcolufileuwriteusplitulen(uselfudatauatbreakucolumaxcoluwriteuword((u./opt/alt/python33/lib64/python3.3/formatter.pyusend_flowing_data–s$          uDumbWriter.send_flowing_dataN( u__name__u __module__u __qualname__u__doc__uNoneu__init__uresetusend_paragraphusend_line_breaku send_hor_ruleusend_literal_datausend_flowing_data(u __locals__((u./opt/alt/python33/lib64/python3.3/formatter.pyu DumbWriterhs     u DumbWritercCs­tƒ}t|ƒ}|dk r0t|ƒ}n2tjdd…rYttjdƒ}n tj}x7|D]/}|dkr‹|jdƒqi|j|ƒqiW|jdƒdS(Niu i( u DumbWriteruAbstractFormatteruNoneuopenusysuargvustdinu end_paragraphuadd_flowing_data(ufileuwufufpuline((u./opt/alt/python33/lib64/python3.3/formatter.pyutestŤs      utestu__main__( u__doc__usysuNoneuAS_ISu NullFormatteruAbstractFormatteru NullWriteruAbstractWriteru DumbWriterutestu__name__(((u./opt/alt/python33/lib64/python3.3/formatter.pyus "ę*C