ó
O'—^c           @  sŠ   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 „  Z d	 „  Z d
 „  Z d „  Z d S(   uP   
Utility functions to return a formatted name and description for a given view.
iÿÿÿÿ(   t   unicode_literalsN(   t
   force_text(   t   escape(   t	   mark_safe(   t   apply_markdownc         C  s.   |  j  | ƒ r* |  | k r* |  t | ƒ  S|  S(   u|   
    Strip trailing component `trailing` from `content` if it exists.
    Used when generating names from view classes.
    (   t   endswitht   len(   t   contentt   trailing(    (    sA   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/formatting.pyt   remove_trailing_string   s    c         C  s(  t  |  ƒ }  g  |  j ƒ  d D]1 } | j ƒ  r t | ƒ t | j d ƒ ƒ ^ q } g  |  j ƒ  d D]1 } | j ƒ  re t | ƒ t | j d ƒ ƒ ^ qe } | rİ d d t | ƒ } t j t j | t j ƒ d |  ƒ }  nA | rd d t | ƒ } t j t j | t j ƒ d |  ƒ }  n  |  j	 ƒ  S(   u  
    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.
    i   u    u   	u   ^u    (
   R   t
   splitlinest   lstripR   t   mint   ret   subt   compilet	   MULTILINEt   strip(   R   t   linet   whitespace_countst
   tab_countst   whitespace_pattern(    (    sA   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/formatting.pyt   dedent   s    	EE''c         C  s=   d } t  j | d |  ƒ j ƒ  }  d j |  j d ƒ ƒ j ƒ  S(   um   
    Translate 'CamelCaseNames' to 'Camel Case Names'.
    Used when generating names from view classes.
    u&   (((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))u    \1u    u   _(   R   R   R   t   joint   splitt   title(   R   t   camelcase_boundry(    (    sA   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/formatting.pyt   camelcase_to_spaces7   s    c         C  sE   t  r t  |  ƒ }  n& t |  ƒ j d d ƒ }  d |  d }  t |  ƒ S(   u5   
    Apply HTML markup to the given description.
    u   
u   <br />u   <p>u   </p>(   R   R   t   replaceR   (   t   description(    (    sA   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/formatting.pyt   markup_descriptionA   s
    (   t   __doc__t
   __future__R    R   t   django.utils.encodingR   t   django.utils.htmlR   t   django.utils.safestringR   t   rest_framework.compatR   R	   R   R   R   (    (    (    sA   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/utils/formatting.pyt   <module>   s   	
		
