o
    ›¨ÊhÔ  ã                   @  sd  d Z ddlmZ ddl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lmZmZmZ d	Zd
 ¡ Ze d¡ZdSdd„ZdTdUdd„ZdVdWdd„ZdVdXdd„ZdVdYdd „ZdZd[d"d#„ZeedƒZd\d]d)d*„Zd^d+d,„Zd_d`d/d.„Zdadbd3d4„Zdcddd7d8„Z dedfd>d?„Z!dgdAdB„Z"edCfdhdIdJ„Z#didLdM„Z$djdOdP„Z%ej&Z&e&j'Z(e&j)Z*G dQdR„ dRe&ƒZ+dS )kzText formatting utilities.é    )ÚannotationsN)Úpartial)Úpformat)ÚMatch©Úfill)ÚAnyÚCallableÚPattern)ÚabbrÚabbrtaskÚdedentÚdedent_initialÚensure_newlinesÚ
ensure_sepÚfill_paragraphsÚindentÚjoinÚ	pluralizeÚprettyÚstr_to_listÚsimple_formatÚtruncatez¿
Unknown format %{0} in string {1!r}.
Possible causes: Did you forget to escape the expand sign (use '%%{0!r}'),
or did you escape and the value was expanded twice? (%%N -> %N -> %hostname)?
z%(\w)ÚsÚstrÚreturnú	list[str]c                 C  s   t | tƒr
|  d¡S | S )zConvert string to list.ú,)Ú
isinstancer   Úsplit©r   © r!   úC/var/www/html/env/lib/python3.10/site-packages/celery/utils/text.pyr      s   

r   é   ÚnÚintc                 C  s$   | d|… d| kr| |d… S | S )z+Remove indentation from first line of text.Nú r!   )r   r$   r!   r!   r"   r   #   s   $r   Ú
Úsepc                 C  s   |  dd„ |  ¡ D ƒ¡S )zRemove indentation.c                 s  s   � | ]}t |ƒV  qd S ©N)r   )Ú.0Úlr!   r!   r"   Ú	<genexpr>*   ó   € zdedent.<locals>.<genexpr>)r   Ú
splitlines)r   r(   r!   r!   r"   r   (   s   r   Úwidthc                   ó   |  ‡ fdd„|  |¡D ƒ¡S )z4Fill paragraphs with newlines (or custom separator).c                 3  s   � | ]}t |ˆ ƒV  qd S r)   r   ©r*   Úp©r/   r!   r"   r,   /   s   € z"fill_paragraphs.<locals>.<genexpr>©r   r   )r   r/   r(   r!   r3   r"   r   -   ó   r   r+   c                 C  s   |  dd„ | D ƒ¡S )zConcatenate list of strings.c                 s  s   � | ]}|r|V  qd S r)   r!   )r*   Úvr!   r!   r"   r,   4   r-   zjoin.<locals>.<genexpr>)r   )r+   r(   r!   r!   r"   r   2   s   r   é   c                 C  s   || ||  | ¡   S )z%Ensure text s ends in separator sep'.)Úcount)r(   r   r$   r!   r!   r"   r   7   s   r   ú...ÚSÚmaxÚellipsisú
str | boolc                 C  sJ   | du rdS t | ƒ|kr#t|tƒr| d|t |ƒ … | p"| d|… S | S )zAbbreviate word.Nú???)Úlenr   r   )r:   r;   r<   r!   r!   r"   r   ?   s   
ÿ
ÿr   c                 C  sP   | du rdS t | ƒ|kr&|  d¡\}}}t||t |ƒ d dƒ}|d | S | S )zAbbreviate task name.Nr>   Ú.é   Fz[.])r?   Ú
rpartitionr   )r:   r;   ÚmoduleÚ_Úclsr!   r!   r"   r   I   s   r   Útr   c                   r0   )zIndent text.c                 3  s   � | ]	}d ˆ  | V  qdS )r&   Nr!   r1   ©r   r!   r"   r,   V   s   € zindent.<locals>.<genexpr>r4   )rF   r   r(   r!   rG   r"   r   T   r5   é€   ÚmaxlenÚsuffixc                 C  s0   |rt | ƒ|kr| d|…  dd¡d | S | S )z0Truncate text to a maximum number of characters.Nr&   é   r   )r?   Úrsplit)r   rI   rJ   r!   r!   r"   r   Y   s   r   ÚfloatÚtextc                 C  s   | dkr|| S |S )z*Pluralize term when n is greater than one.rK   r!   )r$   rN   rJ   r!   r!   r"   r   `   s   r   éP   ÚvalueÚnl_widthÚkwr   c                 K  sd   t | tƒr|› dt| d|ƒdd… › �S t | tƒr(d |dt| fd|i|¤Ž¡S t| fd|i|¤ŽS )z%Format value for printing to console.r&   r#   rK   Nz{}{}{}z    r/   )r   Údictr   ÚtupleÚformat)rP   r/   rQ   r(   rR   r!   r!   r"   r   g   s   

ÿr   Úotherc                 C  s   |  ¡ r|  ¡ S |  ¡ S r)   )ÚisupperÚupperÚlower)r   rV   r!   r!   r"   Ú
match_caset   s   rZ   z\1Úkeysúdict[str, str | Callable]ÚpatternúPattern[str]Úexpandc                   s2   ˆrˆ  dd¡ d	‡ ‡‡fdd„}| |ˆ¡S ˆS )
z0Format string, expanding abbreviations in keys'.ú%Úmatchr   r   ú	str | Anyc                   sH   |   ˆ ¡}zˆ| }W n ty   tt |ˆ¡ƒ‚w t|ƒr"|ƒ S |S r)   )r_   ÚKeyErrorÚ
ValueErrorÚUNKNOWN_SIMPLE_FORMAT_KEYrU   Úcallable)ra   ÚkeyÚresolver©r_   r[   r   r!   r"   Úresolve   s   
ÿzsimple_format.<locals>.resolveN)ra   r   r   rb   )Ú
setdefaultÚsub)r   r[   r]   r_   rj   r!   ri   r"   r   x   s
   
r   Ú	task_namec                 C  s    t | ƒ d¡d d }t||ƒS )zðGiven task name, remove repeating module names.

    Example:
        >>> remove_repeating_from_task(
        ...     'tasks.add',
        ...     'tasks.add(2, 2), tasks.mul(3), tasks.div(4)')
        'tasks.add(2, 2), mul(3), div(4)'
    r@   r   )r   rB   Úremove_repeating)rm   r   rC   r!   r!   r"   Úremove_repeating_from_task�   s   
ro   Úsubstrc                 C  sL   |  | ¡}|dkr$d |d|t| ƒ … ||t| ƒ d…  | d¡g¡S |S )a¶  Remove repeating module names from string.

    Arguments:
        task_name (str): Task name (full path including module),
            to use as the basis for removing module names.
        s (str): The string we want to work on.

    Example:

        >>> _shorten_names(
        ...    'x.tasks.add',
        ...    'x.tasks.add(2, 2) | x.tasks.add(4) | x.tasks.mul(8)',
        ... )
        'x.tasks.add(2, 2) | add(4) | mul(8)'
    r   Ú N)Úfindr   r?   Úreplace)rp   r   Úindexr!   r!   r"   rn   œ   s   
ürn   c                   @  s(   e Zd ZdZ	ddd
d„Zddd„ZdS )Ú
WhateverIOz!StringIO that takes bytes or str.Nr6   úbytes | str | NoneÚar   rR   r   ÚNonec                 O  s.   t | t|tƒr| ¡ n|g|¢R i |¤Ž d S r)   )Ú	_SIO_initr   ÚbytesÚdecode)Úselfr6   rw   rR   r!   r!   r"   Ú__init__À   s   .zWhateverIO.__init__Údataúbytes | strr%   c                 C  s   t | t|tƒr| ¡ ƒS |ƒS r)   )Ú
_SIO_writer   rz   r{   )r|   r~   r!   r!   r"   ÚwriteÄ   s
   ÿÿzWhateverIO.writer)   )r6   rv   rw   r   rR   r   r   rx   )r~   r   r   r%   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r}   r�   r!   r!   r!   r"   ru   ½   s
    ÿru   )r   r   r   r   )r#   )r   r   r$   r%   r   r   )r'   )r   r   r(   r   r   r   )r   r   r/   r%   r(   r   r   r   )r+   r   r(   r   r   r   )r7   )r(   r   r   r   r$   r%   r   r   )r9   )r:   r   r;   r%   r<   r=   r   r   )r:   r   r;   r%   r   r   )r   r'   )rF   r   r   r%   r(   r   r   r   )rH   r9   )r   r   rI   r%   rJ   r   r   r   r    )r$   rM   rN   r   rJ   r   r   r   )rO   rO   r'   )rP   r   r/   r%   rQ   r%   r(   r   rR   r   r   r   )r   r   rV   r   r   r   )
r   r   r[   r\   r]   r^   r_   r   r   r   )rm   r   r   r   r   r   )rp   r   r   r   r   r   ),r…   Ú
__future__r   ÚioÚreÚ	functoolsr   Úpprintr   r   Útextwrapr   Útypingr   r	   r
   Ú__all__Ústripre   ÚcompileÚ	RE_FORMATr   r   r   r   r   r   r   r   r   r   r   r   r   rZ   r   ro   rn   ÚStringIOr�   r€   r}   ry   ru   r!   r!   r!   r"   Ú<module>   sH    ü





þ

