o
    c©ZhÇ  ã                   @   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)ÚcontentZtrailing© r	   úV/var/www/html/lang_env/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   ÚlinesZwhitespace_countsZ
tab_countsZ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   Z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)r/   r,   r-   r.   )Úselfr,   r-   r.   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)r/   r,   Úformatr-   r.   )r1   r	   r	   r
   Ú__str__V   s   
zlazy_format.__str__c                 C   s   t | ƒ| S r0   )Ústr)r1   Úvaluer	   r	   r
   Ú__mod__\   s   zlazy_format.__mod__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r2   r4   r7   r	   r	   r	   r
   r+   F   s    r+   )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	   r
   Ú<module>   s    

