o
    g                     @   sn   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d Z
d	d
 Zdd Zdd ZG dd dZdS )zP
Utility functions to return a formatted name and description for a given view.
    N)	force_str)escape)	mark_safe)apply_markdownc                 C   s(   |  |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)contenttrailing r
   \/var/www/rescue_company/venv/lib/python3.10/site-packages/rest_framework/utils/formatting.pyremove_trailing_string   s   r   c                 C   s   t | } dd |  dd D }|rQtdd |D }tdd |D }|r=dd|  }tt|tjd	| } |  S |rQdd
|  }tt|tjd	| } |  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 | ]}|  r|qS r
   )lstrip.0liner
   r
   r   
<listcomp>!   s    zdedent.<locals>.<listcomp>   Nc                 S   "   g | ]}t |t |d  qS ) r   r   r   r
   r
   r   r   %      " c                 S   r   )	r   r   r
   r
   r   r   &   r   ^r    r   )r   
splitlinesminresubcompile	MULTILINEstrip)r   lineswhitespace_counts
tab_countswhitespace_patternr
   r
   r   dedent   s   	r%   c                 C   s*   d}t |d|  } d| d 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_boundaryr
   r
   r   camelcase_to_spaces0   s   r+   c                 C   s8   t r
t | } t| S t| 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/   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
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                 O   s   d | _ || _|| _|| _d S N)r4   r1   r2   r3   )selfr1   r2   r3   r
   r
   r   __init__P   s   
zlazy_format.__init__c                 C   s8   | j d u r| jj| ji | j| _ d\| _| _| _| j S )N)NNN)r4   r1   formatr2   r3   )r6   r
   r
   r   __str__V   s   
zlazy_format.__str__c                 C   s   t | | S r5   )str)r6   valuer
   r
   r   __mod__\   s   zlazy_format.__mod__N)__name__
__module____qualname____doc__	__slots__r7   r9   r<   r
   r
   r
   r   r0   F   s    r0   )r@   r   django.utils.encodingr   django.utils.htmlr   django.utils.safestringr   rest_framework.compatr   r   r%   r+   r/   r0   r
   r
   r
   r   <module>   s    

