U
    P|j+  ã                   @   s>   d Z ddlZddgZddd„Zddd„Zdd	„ Zddd„ZdS )zž Pretty-Print an Interface object as structured text (Yum)

This module provides a function, asStructuredText, for rendering an
interface as structured text.
é    NÚasReStructuredTextÚasStructuredTextFc                 C   s¨  |rdd„ }ndd„ }||   ¡ ƒg}|j}d}|  ¡ rL|tt|  ¡ ƒ|ƒƒ dd„ | jD ƒ}|r®|td||ƒƒ |d7 }|D ](}d||  ¡ ƒ }	|tt|	ƒ||ƒƒ q||d8 }t|  ¡ ƒ}
|td	||ƒƒ |d7 }|
D ]D\}}t|d
ƒsÖd 	||  ¡ ƒ| ¡ �pd¡}	|tt|	ƒ||ƒƒ qÖ|d8 }|td||ƒƒ |d7 }|
D ]X\}}t|d
ƒ�r@|  ¡ › | 
¡ › �}d 	||ƒ| ¡ �p~d¡}	|tt|	ƒ||ƒƒ �q@d |¡d S )zõ Output structured text format.  Note, this will whack any existing
    'structured' format of the text.

    If `rst=True`, then the output will quote all code as inline literals in
    accordance with 'reStructuredText' markup principles.
    c                 S   s   d| › d�S )Nz``© ©Úsr   r   ú;/tmp/pip-unpacked-wheel-zcalc2_b/zope/interface/document.pyÚinline_literal%   s    z(asStructuredText.<locals>.inline_literalc                 S   s   | S )Nr   r   r   r   r   r   (   s    é   c                 S   s   g | ]}|t jjk	r|‘qS r   )ÚzopeZ	interfaceZ	Interface)Ú.0Úbaser   r   r   Ú
<listcomp>2   s   þz$asStructuredText.<locals>.<listcomp>zThis interface extends:zo %szAttributes:ÚgetSignatureStringz{} -- {}zno documentationzMethods:z

)ÚgetNameÚappendZgetDocÚ_justify_and_indentÚ_trim_doc_stringÚ	__bases__ÚsortedÚnamesAndDescriptionsÚhasattrÚformatr   Újoin)ÚifaceÚmungeÚrstr   ÚrZoutpÚlevelÚbasesÚbÚitemr   ÚnameÚdescZ_callr   r   r   r      sP    
ÿ

þþc                 C   s   t | |dd�S )zi Output reStructuredText format.

    Note, this will whack any existing 'structured' format of the text.T)r   r   )r   )r   r   r   r   r   r   Y   s    c                 C   sZ   |   dd¡ d¡}| d¡g}|rPtdd„ |D ƒƒ}|D ]}| ||d… ¡ q8d |¡S )zJ Trims a doc string to make it format
    correctly with structured text. ú
Ú
r   c                 S   s    g | ]}t |ƒt | ¡ ƒ ‘qS r   )ÚlenÚlstrip)r   Úliner   r   r   r   g   s   ÿz$_trim_doc_string.<locals>.<listcomp>N)ÚreplaceÚsplitÚpopÚminr   r   )ÚtextÚlinesÚnlinesZ
min_indentr'   r   r   r   r   `   s    ÿr   éH   c                 C   s†   d| }|rbg }|}|   ¡ } | D ],}d ||g¡}t|ƒ|kr | |¡ |}q | |¡ d |¡S ||  ¡  dd¡ dd| ¡ S dS )z9 indent and justify text, rejustify (munge) if specified ú r$   r#   N)r)   r   r%   r   Ústripr(   )r,   r   r   ÚwidthÚindentr-   r'   Úwordr   r   r   r   o   s    


ÿr   )r   F)r   )r   r/   )Ú__doc__Zzope.interfacer
   Ú__all__r   r   r   r   r   r   r   r   Ú<module>   s   þ
=
