a
    ŠxdÕ  ã                   @   s"  d dl Z d dlZd dlZd dlZzd dlmZ eZejZ	W n* e
yd   d dlmZ eZeZ	eZY n0 zd dlZW n e
yŒ   d dlZY n0 ddgZe  dd e¡ ¡Ze  d¡Ze  d¡Ze  d	¡Ze  d
¡Ze  d¡Ze  d¡Ze  d¡ZdZddd„Zdddd dedddddfdd„ZdS )é    N)Úname2codepointÚslugifyÚsmart_truncatez&(%s);ú|z&#(\d+);z&#x([\da-fA-F]+);z[\']+z[^-a-z0-9]+z[^-a-zA-Z0-9]+z-{2,}z(?<=\d),(?=\d)ú-Fú c                 C   sÌ   |   |¡} |s| S t| ƒ|k r"| S |s8| d|…   |¡S || vrL| d|… S d}|  |¡D ]V}|rZt|ƒt|ƒ }||k rŒ|d ||¡7 }qZ||kr¨|d |¡7 } q²qZ|rZ q²qZ|sÂ| d|… }|  |¡S )a=  
    Truncate a string.
    :param string (str): string for modification
    :param max_length (int): output string length
    :param word_boundary (bool):
    :param save_order (bool): if True then word order of output string is like input string
    :param separator (str): separator between words
    :return:
    NÚ z{}{}z{})ÚstripÚlenÚsplitÚformat)ÚstringÚ
max_lengthÚword_boundaryÚ	separatorÚ
save_orderZ	truncatedÚwordZnext_len© r   úG/var/www/html/Ranjet/env/lib/python3.9/site-packages/slugify/slugify.pyr   #   s.    
Tr   c                    sú  |r|D ]\}}|   ||¡} qt| tƒs4t| ddƒ} t t| ¡} t | ¡} t| tƒs`t| ddƒ} |rtt dd„ | ¡} |r zt	 dd„ | ¡} W n t
yž   Y n0 |rÌzt dd„ | ¡} W n t
yÊ   Y n0 t d| ¡} tjdk rî|  d	d¡} |
rú|  ¡ } t d
| ¡} t d
| ¡} |
r$|	p t}n
|	p,t}t |t| ¡} t t| ¡ t¡} ˆ r¤|
r‚dd„ ˆ D ƒ‰‡fdd„|  t¡D ƒ}n‡ fdd„|  t¡D ƒ}t |¡} |rÆ|D ]\}}|   ||¡} q®|dkràt| ||t|ƒ} |tkrö|   t|¡} | S )a‡  
    Make a slug from the given text.
    :param text (str): initial text
    :param entities (bool): converts html entities to unicode
    :param decimal (bool): converts html decimal to unicode
    :param hexadecimal (bool): converts html hexadecimal to unicode
    :param max_length (int): output string length
    :param word_boundary (bool): truncates to complete word even if length ends up shorter than max_length
    :param save_order (bool): if parameter is True and max_length > 0 return whole words in the initial order
    :param separator (str): separator between words
    :param stopwords (iterable): words to discount
    :param regex_pattern (str): regex pattern for allowed characters
    :param lowercase (bool): activate case sensitivity by setting it to False
    :param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
    :return (str):
    zutf-8Úignorec                 S   s   t t|  d¡ ƒS ©Né   )Úunichrr   Úgroup©Úmr   r   r   Ú<lambda>v   ó    zslugify.<locals>.<lambda>c                 S   s   t t|  d¡ƒƒS r   ©r   Úintr   r   r   r   r   r   {   r   c                 S   s   t t|  d¡dƒƒS )Nr   é   r   r   r   r   r   r   ‚   r   ZNFKD)é   Úasciir   c                 S   s   g | ]}|  ¡ ‘qS r   )Úlower)Ú.0Úsr   r   r   Ú
<listcomp>¢   r   zslugify.<locals>.<listcomp>c                    s   g | ]}|ˆ vr|‘qS r   r   ©r$   Úw)Ústopwords_lowerr   r   r&   £   r   c                    s   g | ]}|ˆ vr|‘qS r   r   r'   )Ú	stopwordsr   r   r&   ¥   r   r   )ÚreplaceÚ
isinstanceÚ_unicode_typeÚ_unicodeÚQUOTE_PATTERNÚsubÚDEFAULT_SEPARATORÚ	unidecodeÚCHAR_ENTITY_PATTERNÚDECIMAL_PATTERNÚ	ExceptionÚHEX_PATTERNÚunicodedataÚ	normalizeÚsysÚversion_infoÚencoder#   ÚNUMBERS_PATTERNÚALLOWED_CHARS_PATTERNÚ$ALLOWED_CHARS_PATTERN_WITH_UPPERCASEÚreÚDUPLICATE_DASH_PATTERNr	   r   Újoinr   )ÚtextÚentitiesÚdecimalZhexadecimalr   r   r   r   r*   Zregex_patternZ	lowercaseÚreplacementsÚoldÚnewÚpatternÚwordsr   )r*   r)   r   r   M   s^    







)r   Fr   F)r?   r7   Útypesr9   Úhtmlentitydefsr   Úunicoder.   ZUnicodeTyper-   ÚImportErrorÚhtml.entitiesÚstrÚchrr   Ztext_unidecoder2   Ú__all__ÚcompilerA   r3   r4   r6   r/   r=   r>   r@   r<   r1   r   r   r   r   r   r   Ú<module>   s>   









*

þ