3
>^	                 @   sl   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	 Zd
d Zdd Zdd ZdS )zP
Utility functions to return a formatted name and description for a given view.
    )unicode_literalsN)
force_text)escape)	mark_safe)apply_markdownc             C   s(   | j |r$| |kr$| dt|  S | S )z|
    Strip trailing component `trailing` from `content` if it exists.
    Used when generating names from view classes.
    N)endswithlen)contentZtrailing r
   N/tmp/pip-build-8app2_gc/djangorestframework/rest_framework/utils/formatting.pyremove_trailing_string   s    r   c             C   s   t | } dd | j dd D }|rtdd |D }tdd |D }|rtdd|  }tjtj|tjd	| } n(|rdd
|  }tjtj|tjd	| } | j S )a  
    Remove leading indent from a block of text.
    Used when generating descriptions from docstrings.

    Note that python's `textwrap.dedent` doesn't quite cut it,
    as it fails to dedent multiline docstrings that include
    unindented text on the initial line.
    c             S   s   g | ]}|j  r|qS r
   )lstrip).0liner
   r
   r   
<listcomp>#   s    zdedent.<locals>.<listcomp>   Nc             S   s"   g | ]}t |t |jd  qS ) )r   r   )r   r   r
   r
   r   r   '   s    c             S   s"   g | ]}t |t |jd  qS )	)r   r   )r   r   r
   r
   r   r   (   s    ^r    r   )r   
splitlinesminresubcompile	MULTILINEstrip)r	   linesZwhitespace_countsZ
tab_countsZwhitespace_patternr
   r
   r   dedent   s    	r   c             C   s*   d}t j|d| j } dj| jdj S )zm
    Translate 'CamelCaseNames' to 'Camel Case Names'.
    Used when generating names from view classes.
    z&(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))z \1r   _)r   r   r   joinsplittitle)r	   Zcamelcase_boundaryr
   r
   r   camelcase_to_spaces2   s    r#   c             C   s2   t rt | } nt| jdd} d|  d } t| S )z5
    Apply HTML markup to the given description.
    
z<br />z<p>z</p>)r   r   replacer   )descriptionr
   r
   r   markup_description<   s
    
r'   )__doc__
__future__r   r   Zdjango.utils.encodingr   Zdjango.utils.htmlr   Zdjango.utils.safestringr   Zrest_framework.compatr   r   r   r#   r'   r
   r
   r
   r   <module>   s   

