o
    ).hÇ  ã                   @   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/supernova/superenvnew/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    

