o
    Ê·6i$  ã                   @  sþ   d dl mZ d dlZd dlZd dlmZ d dlmZ zd dlZW n e	y-   d dl
ZY nw 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d„Zdddd deddddddfd.d+d„ZdS )/é    )ÚannotationsN)ÚIterable)Úname2codepointÚslugifyÚsmart_truncatez&(%s);ú|z&#(\d+);z&#x([\da-fA-F]+);z[\']+z[^-a-zA-Z0-9]+z[\W_]+z-{2,}z(?<=\d),(?=\d)ú-Fú ÚstringÚstrÚ
max_lengthÚintÚword_boundaryÚboolÚ	separatorÚ
save_orderÚreturnc                 C  sÊ   |   |¡} |s	| S t| ƒ|k r| S |s| d|…   |¡S || vr&| d|… S d}|  |¡D ]*}|rWt|ƒt|ƒ }||k rF|d ||¡7 }q-||krS|d |¡7 } n|rW nq-|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)r
   r   r   r   r   Ú	truncatedÚwordÚnext_len© r   úT/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/slugify/slugify.pyr      s0   
€
Tr   ÚtextÚentitiesÚdecimalÚhexadecimalÚ	stopwordsúIterable[str]Úregex_patternúre.Pattern[str] | str | NoneÚ	lowercaseÚreplacementsúIterable[Iterable[str]]Úallow_unicodec                   s  |r|D ]
\}}|   ||¡} qt| tƒst| ddƒ} t t| ¡} |r)t d| ¡} nt d| ¡} t | ¡} t| tƒs?t| ddƒ} |rIt	 dd„ | ¡} |r_z
t
 dd„ | ¡} W n	 ty^   Y nw |ruz
t dd„ | ¡} W n	 tyt   Y nw |r~t d| ¡} nt 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 disallowed characters
    :param lowercase (bool): activate case sensitivity by setting it to False
    :param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
    :param allow_unicode (bool): allow unicode characters
    :return (str):
    zutf-8ÚignoreÚNFKCÚNFKDc                 S  s   t t|  d¡ ƒS ©Né   )Úchrr   Úgroup©Úmr   r   r   Ú<lambda>…   ó    zslugify.<locals>.<lambda>c                 S  s   t t|  d¡ƒƒS r,   ©r.   r   r/   r0   r   r   r   r2   Š   r3   c                 S  s   t t|  d¡dƒƒS )Nr-   é   r4   r0   r   r   r   r2   ‘   ó    r   c                 S  s   g | ]}|  ¡ ‘qS r   )Úlower)Ú.0Úsr   r   r   Ú
<listcomp>³   r6   zslugify.<locals>.<listcomp>c                   ó   g | ]}|ˆ vr|‘qS r   r   ©r8   Úw)Ústopwords_lowerr   r   r:   ´   ó    c                   r;   r   r   r<   )r!   r   r   r:   ¶   r?   r   )ÚreplaceÚ
isinstancer   ÚQUOTE_PATTERNÚsubÚDEFAULT_SEPARATORÚunicodedataÚ	normalizeÚ	unidecodeÚCHAR_ENTITY_PATTERNÚDECIMAL_PATTERNÚ	ExceptionÚHEX_PATTERNr7   ÚNUMBERS_PATTERNÚ DISALLOWED_UNICODE_CHARS_PATTERNÚDISALLOWED_CHARS_PATTERNÚreÚDUPLICATE_DASH_PATTERNr   r   Újoinr   )r   r   r   r    r   r   r   r   r!   r#   r%   r&   r(   ÚoldÚnewÚpatternÚwordsr   )r!   r>   r   r   K   sh   "


ÿÿ

)r   Fr	   F)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$   r%   r   r&   r'   r(   r   r   r   )Ú
__future__r   rO   rE   Úcollections.abcr   Úhtml.entitiesr   rG   ÚImportErrorÚtext_unidecodeÚ__all__ÚcompilerQ   rH   rI   rK   rB   rN   rM   rP   rL   rD   r   r   r   r   r   r   Ú<module>   sL    ÿ






û2ó