
|W                 @   sU   d  Z  d d l Z d d d d  Z d d d  Z d d	   Z d 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.
    NFc             C   sP  | r d d   } n d d   } | |  j     g } | j } d } |  j   rp | t t |  j    |   d d   |  j D } | r | t d | |   | d 7} x@ | D]8 } d | | j     }	 | t t |	  | |   q W| d 8} t |  j    }
 | t d	 | |   | d 7} xg |
 D]_ \ } } t | d
  s2d | | j     | j   pnd f }	 | t t |	  | |   q2W| d 8} | t d | |   | d 7} x} |
 D]u \ } } t | d
  rd | j    | j	   f } d | |  | j   pd f }	 | t t |	  | |   qWd j
 |  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 |  f S)Nz``%s`` )sr   r   9/usr/lib/python3/dist-packages/zope/interface/document.py<lambda>   s    z"asStructuredText.<locals>.<lambda>c             S   s   |  S)Nr   )r   r   r   r   r   !   s       c             S   s(   g  |  ] } | t  j j k	 r |  q Sr   )zopeZ	interfaceZ	Interface).0baser   r   r   
<listcomp>*   s   	z$asStructuredText.<locals>.<listcomp>zThis interface extends:zo %szAttributes:getSignatureStringz%s -- %szno documentationzMethods:z%s%sz

)ZgetNameappendZgetDoc_justify_and_indent_trim_doc_string	__bases__sortednamesAndDescriptionshasattrr   join)ImungerstZinline_literalrZoutplevelbasesbitemr   nameZdescZ_callr   r   r   asStructuredText   sF    		
 

 

 r   c             C   s   t  |  d | d d S)zi Output reStructuredText format.  Note, this will whack any existing
    'structured' format of the text.r   r   T)r   )r   r   r   r   r   asReStructuredTextM   s    r   c             C   s   |  j  d d  j d  } | j d  g } | rt t d d   | D  } x% | D] } | j | | d   qS Wd j |  S)zJ Trims a doc string to make it format
    correctly with structured text. z

r   c             S   s,   g  |  ]" } t  |  t  | j     q Sr   )lenlstrip)r   liner   r   r   r
   Z   s   	z$_trim_doc_string.<locals>.<listcomp>N)replacesplitpopminr   r   )textlinesZnlinesZ
min_indentr"   r   r   r   r   S   s    r   H   c             C   s   d | } | r g  } | } |  j    }  xU |  D]@ } d j | | g  } t |  | k r/ | j |  | } q/ W| j |  d j |  S| |  j   j d d  j d d |  Sd S)z9 indent and justify text, rejustify (munge) if specified  r   z
N)r$   r   r    r   stripr#   )r'   r   r   widthindentr(   r"   Zwordr   r   r   r   b   s    

r   )__doc__Zzope.interfacer   r   r   r   r   r   r   r   r   <module>   s
   7