Your IP : 3.145.88.155


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/formatter.cpython-34.pyc

�
e fE;�@s�dZddlZddlZejde�dZGdd�d�ZGdd�d�ZGdd	�d	�ZGd
d�de�Z	Gdd
�d
e�Z
ddd�Zedkr�e�ndS)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.
�NzDthe formatter module is deprecated and will be removed in Python 3.6c@s�eZdZdZddd�Zdd�Zdd�Zd	d
�Zddd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �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�}n||_dS)N)�
NullWriter�writer)�selfr�r�./opt/alt/python34/lib64/python3.4/formatter.py�__init__)szNullFormatter.__init__cCsdS)Nr)r�	blanklinerrr�
end_paragraph-szNullFormatter.end_paragraphcCsdS)Nr)rrrr�add_line_break.szNullFormatter.add_line_breakcOsdS)Nr)r�args�kwrrr�add_hor_rule/szNullFormatter.add_hor_rulecCsdS)Nr)r�format�counterr	rrr�add_label_data0szNullFormatter.add_label_datacCsdS)Nr)r�datarrr�add_flowing_data1szNullFormatter.add_flowing_datacCsdS)Nr)rrrrr�add_literal_data2szNullFormatter.add_literal_datacCsdS)Nr)rrrr�flush_softspace3szNullFormatter.flush_softspacecCsdS)Nr)r�alignrrr�push_alignment4szNullFormatter.push_alignmentcCsdS)Nr)rrrr�
pop_alignment5szNullFormatter.pop_alignmentcCsdS)Nr)r�xrrr�	push_font6szNullFormatter.push_fontcCsdS)Nr)rrrr�pop_font7szNullFormatter.pop_fontcCsdS)Nr)r�marginrrr�push_margin8szNullFormatter.push_margincCsdS)Nr)rrrr�
pop_margin9szNullFormatter.pop_margincCsdS)Nr)r�spacingrrr�set_spacing:szNullFormatter.set_spacingcGsdS)Nr)r�stylesrrr�
push_style;szNullFormatter.push_style�cCsdS)Nr)r�nrrr�	pop_style<szNullFormatter.pop_stylecCsdS)Nr)r�flagrrr�assert_line_data=szNullFormatter.assert_line_data)�__name__�
__module__�__qualname__�__doc__rr
rrrrrrrrrrrrr r"r%r'rrrrrs&	rc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
dd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*d+�Zd)d,d-�Zd
S).�AbstractFormatterz�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)Nr#r)
rr�align_stack�
font_stack�margin_stackr�style_stack�nospace�	softspace�para_end�parskip�
hard_break�
have_label)rrrrrrNs												zAbstractFormatter.__init__cCs�|js"|jj�d|_n|j|krg|jrg|jj||j�||_d|_nd|_|_|_d|_dS)Nrr#)	r5r�send_line_breakr6r4�send_paragraphr1r3r2)rr	rrrr
]s	
	zAbstractFormatter.end_paragraphcCsO|jp|js2|jj�d|_|_nd|_|_d|_dS)Nrr#)r5r3rr7r6r4r1r2)rrrrrhs

z AbstractFormatter.add_line_breakcOs^|js|jj�n|jj||�d|_|_d|_|_|_|_dS)Nr#r)	r5rr7�
send_hor_ruler1r6r3r2r4)rrr
rrrros
	zAbstractFormatter.add_hor_ruleNcCs�|js|jr#|jj�n|jsK|jj|rAdpDd�nt|t�ry|jj|j	||��n|jj|�d|_
|_|_|_d|_|_dS)Nr#r)
r6r5rr7r3r8�
isinstance�str�send_label_data�format_counterr1r2r4)rrrr	rrrrvs	z AbstractFormatter.add_label_datacCs�d}x�|D]�}|dkr0|d|}q
|dkrd|dkr�||j||�}q�q
|dkr�|dkr�||j||�}q�q
||}q
W|S)N��1z%dZaArZiI)�
format_letter�format_roman)rrr�label�crrrr=�s
z AbstractFormatter.format_countercCsVd}xI|dkrQt|dd�\}}tt|�|�}||}q	W|S)Nr>rr#�)�divmod�chr�ord)r�caserrBr�srrrr@�szAbstractFormatter.format_letterc	Csddddg}dddg}d\}}x�|d	kr�t|d
�\}}|dkrz||||d|}nj|d
kr�|||||}nE|dkr�||}|d}nd}||||}||}|d}q0W|dkr|j�S|S)N�irrC�m�v�l�dr>r�
�	r#���I)r>r)rE�upper)	rrHrZonesZfivesrB�indexrrIrrrrA�s&



zAbstractFormatter.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)Nr#� r���)�isspace�join�splitr1r2r4r5r3r6r�send_flowing_data)rrZprespaceZ	postspacerrrr�s$			%	z"AbstractFormatter.add_flowing_datacCsx|s
dS|jr&|jjd�n|dd�dk|_d|_|_|_|_|_|jj|�dS)NrVr#�
rrW)	r2rr[r5r1r3r4r6�send_literal_data)rrrrrr�s	%z"AbstractFormatter.add_literal_datacCsN|jrJd|_|_|_|_|_d|_|jjd�ndS)Nrr#rV)r2r5r3r4r6r1rr[)rrrrr�s	%	z!AbstractFormatter.flush_softspacecCsX|rA||jkrA|jj|�||_|jj|�n|jj|j�dS)N)rr�
new_alignmentr-�append)rrrrrr�s
	z AbstractFormatter.push_alignmentcCsc|jr|jd=n|jrF|jd|_}|jj|�nd|_|jjd�dS)Nr#rWrW)r-rrr^)rrrrrr�s	
		zAbstractFormatter.pop_alignmentc
Cs�|\}}}}|jrNd|_|_|_d|_|jjd�n|jr�|jd\}}}}	|tkr�|}n|tkr�|}n|tkr�|}n|tkr�|	}q�n||||f}|jj|�|jj	|�dS)Nrr#rVrW)
r2r5r3r1rr[r.�AS_ISr_�new_font)
r�font�sizerJ�bZttZcsizeZci�cbZcttrrrr�s$						zAbstractFormatter.push_fontcCsI|jr|jd=n|jr/|jd}nd}|jj|�dS)Nr#rWrW)r.rra)rrbrrrr�s	
	zAbstractFormatter.pop_fontcCs]|jj|�dd�|jD�}|r@|r@|d}n|jj|t|��dS)NcSsg|]}|r|�qSrr)�.0rKrrr�
<listcomp>s	z1AbstractFormatter.push_margin.<locals>.<listcomp>r#rW)r/r_r�
new_margin�len)rr�fstackrrrrs


zAbstractFormatter.push_margincCsb|jr|jd=ndd�|jD�}|r?|d}nd}|jj|t|��dS)Nr#cSsg|]}|r|�qSrr)rfrKrrrrg
s	z0AbstractFormatter.pop_margin.<locals>.<listcomp>rWrW)r/rrhri)rrjrrrrr
s	

zAbstractFormatter.pop_margincCs||_|jj|�dS)N)rr�new_spacing)rrrrrr s	zAbstractFormatter.set_spacingcGsz|jr<d|_|_|_d|_|jjd�nx|D]}|jj|�qCW|jjt	|j��dS)Nrr#rV)
r2r5r3r1rr[r0r_�
new_styles�tuple)rr!Zstylerrrr"s		
zAbstractFormatter.push_styler#cCs.|j|d�=|jjt|j��dS)N)r0rrlrm)rr$rrrr%!szAbstractFormatter.pop_stylecCs,||_|_d|_|_|_dS)Nr)r1r5r3r4r6)rr&rrrr'%sz"AbstractFormatter.assert_line_data)r(r)r*r+rr
rrrr=r@rArrrrrrrrrr r"r%r'rrrrr,@s,	
	
	r,c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)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.

    cCsdS)Nr)rrrrr2szNullWriter.__init__cCsdS)Nr)rrrr�flush3szNullWriter.flushcCsdS)Nr)rrrrrr^4szNullWriter.new_alignmentcCsdS)Nr)rrbrrrra5szNullWriter.new_fontcCsdS)Nr)rr�levelrrrrh6szNullWriter.new_margincCsdS)Nr)rrrrrrk7szNullWriter.new_spacingcCsdS)Nr)rr!rrrrl8szNullWriter.new_stylescCsdS)Nr)rr	rrrr89szNullWriter.send_paragraphcCsdS)Nr)rrrrr7:szNullWriter.send_line_breakcOsdS)Nr)rrr
rrrr9;szNullWriter.send_hor_rulecCsdS)Nr)rrrrrr<<szNullWriter.send_label_datacCsdS)Nr)rrrrrr[=szNullWriter.send_flowing_datacCsdS)Nr)rrrrrr]>szNullWriter.send_literal_dataN)r(r)r*r+rrnr^rarhrkrlr8r7r9r<r[r]rrrrr*src@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�AbstractWriterz�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)Nznew_alignment(%r))�print)rrrrrr^IszAbstractWriter.new_alignmentcCstd|f�dS)Nznew_font(%r))rq)rrbrrrraLszAbstractWriter.new_fontcCstd||f�dS)Nznew_margin(%r, %d))rq)rrrorrrrhOszAbstractWriter.new_margincCstd|f�dS)Nznew_spacing(%r))rq)rrrrrrkRszAbstractWriter.new_spacingcCstd|f�dS)Nznew_styles(%r))rq)rr!rrrrlUszAbstractWriter.new_stylescCstd|f�dS)Nzsend_paragraph(%r))rq)rr	rrrr8XszAbstractWriter.send_paragraphcCstd�dS)Nzsend_line_break())rq)rrrrr7[szAbstractWriter.send_line_breakcOstd�dS)Nzsend_hor_rule())rq)rrr
rrrr9^szAbstractWriter.send_hor_rulecCstd|f�dS)Nzsend_label_data(%r))rq)rrrrrr<aszAbstractWriter.send_label_datacCstd|f�dS)Nzsend_flowing_data(%r))rq)rrrrrr[dsz AbstractWriter.send_flowing_datacCstd|f�dS)Nzsend_literal_data(%r))rq)rrrrrr]gsz AbstractWriter.send_literal_dataN)r(r)r*r+r^rarhrkrlr8r7r9r<r[r]rrrrrpAsrpc@speZdZdZdddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
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.

    N�HcCs6|ptj|_||_tj|�|j�dS)N)�sys�stdout�file�maxcolrr�reset)rrvrwrrrrts	
zDumbWriter.__init__cCsd|_d|_dS)Nr)�col�atbreak)rrrrrxzs	zDumbWriter.resetcCs*|jjd|�d|_d|_dS)Nr\r)rv�writeryrz)rr	rrrr8~s	zDumbWriter.send_paragraphcCs&|jjd�d|_d|_dS)Nr\r)rvr{ryrz)rrrrr7�s	zDumbWriter.send_line_breakcOsM|jjd�|jjd|j�|jjd�d|_d|_dS)Nr\�-r)rvr{rwryrz)rrr
rrrr9�s
	zDumbWriter.send_hor_rulecCsz|jj|�|jd�}|dkrKd|_||dd�}n|j�}|jt|�|_d|_dS)Nr\rr#)rvr{�rfindry�
expandtabsrirz)rrrJrrrr]�s	zDumbWriter.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)Nrr\rVr#rW)rzrXryrwrvr{rZri)rrrzryrwr{Zwordrrrr[�s$		
	



	zDumbWriter.send_flowing_data)r(r)r*r+rrxr8r7r9r]r[rrrrrrks
rrcCs�t�}t|�}|dk	r0t|�}n2tjdd�rYttjd�}n	tj}z>x7|D]/}|dkr�|jd�ql|j|�qlWWd|tjk	r�|j�nX|jd�dS)Nr#r\r)	rrr,�openrt�argv�stdinr
r�close)rv�w�f�fp�linerrr�test�s		
r��__main__)
r+rt�warnings�warn�PendingDeprecationWarningr`rr,rrprrr�r(rrrr�<module>s	"�*C

?>