
    Nwg                     l    d 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 G d d      Zy)zP
Utility functions to return a formatted name and description for a given view.
    N)	force_str)escape)	mark_safe)apply_markdownc                 P    | j                  |      r| |k7  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)contenttrailings     V/var/www/horilla/myenv/lib/python3.12/site-packages/rest_framework/utils/formatting.pyremove_trailing_stringr      s1    
 !g&9X''N    c                    t        |       } | j                         dd D cg c]  }|j                         s| }}|rt        |D cg c](  }t	        |      t	        |j                  d            z
  * c}      }t        |D cg c](  }t	        |      t	        |j                  d            z
  * c}      }|rQdd|z  z   }t        j                  t        j                  |t
        j                        d|       } | j                         S |rAdd|z  z   }t        j                  t        j                  |t
        j                        d|       } | j                         S c c}w c c}w c c}w )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.
       N 	^ )
r   
splitlineslstripminr	   resubcompile	MULTILINEstrip)r
   linelineswhitespace_counts
tab_countswhitespace_patterns         r   dedentr"      s-     G%002126Hd$++-THEH u UtTSS1A-B!B UVO#d)c$++d*;&<<OP
!$.?(?!@ffRZZ(:BLLI2wWG ==? !$z(9!:ffRZZ(:BLLI2wWG==? I !VOs   E E 	-E%-E*c                     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
   camelcase_boundarys     r   camelcase_to_spacesr)   0   sH    
 Bff'9??AG88GMM#&'--//r   c                     t         rt        |       } t        |       S t        |       j                  dd      } d| z   dz   } t        |       S )z5
    Apply HTML markup to the given description.
    
z<br />z<p>z</p>)r   r   replacer   )descriptions    r   markup_descriptionr.   :   sQ     $[1 [!! [)11$Ak)F2[!!r   c                   &    e Zd ZdZdZd Zd Zd Zy)lazy_formatz
    Delay formatting until it's actually needed.

    Useful when the format string or one of the arguments is lazy.

    Not using Django's lazy because it is too slow.
    )format_stringargskwargsresultc                 <    d | _         || _        || _        || _        y N)r4   r1   r2   r3   )selfr1   r2   r3   s       r   __init__zlazy_format.__init__P   s    *	r   c                     | j                   J | j                  j                  | j                  i | j                  | _         d\  | _        | _        | _        | j                   S )N)NNN)r4   r1   formatr2   r3   )r7   s    r   __str__zlazy_format.__str__V   sP    ;;3$,,33TYYN$++NDK9I6D	4;{{r   c                     t        |       |z  S r6   )str)r7   values     r   __mod__zlazy_format.__mod__\   s    4y5  r   N)__name__
__module____qualname____doc__	__slots__r8   r;   r?    r   r   r0   r0   F   s     >I!r   r0   )rC   r   django.utils.encodingr   django.utils.htmlr   django.utils.safestringr   rest_framework.compatr   r   r"   r)   r.   r0   rE   r   r   <module>rJ      s9    
 + $ - 020	"! !r   