
    h7                     `   S SK r S SKrS SKrS SKrS SKrS SKJr  S SK Jr  S SK Jr	  S SK
Jr  S SKJr  S SKJr  S SKJr  S S	KJrJrJrJr  S S
KJr  S SKJr  S SKJrJr  \S 5       r\" S5      r\" S5      r \S 5       r!S,S jr"S r# " S S\5      r$ " S S\$5      r% " S S\$5      r& " S S\5      r'\S 5       r(\\" S5      4S j5       r)\S 5       r*\S 5       r+S  r,SS!.S" jr- " S# S$\5      r.SS!.S% jr/\" S&\R`                  5      r1S' r2\S( 5       r3\S-S) j5       r4S* r5S+ r6\" \6\75      r8g).    N)deque)GzipFile)compress)escape)
HTMLParser)BytesIO)SuspiciousFileOperation)SimpleLazyObjectcached_propertykeep_lazy_textlazy)_lazy_re_compile)gettext)gettext_lazypgettextc                     U (       d  U $ [        U [        5      (       d  [        U 5      n U S   R                  5       U SS -   $ )z(Capitalize the first letter of a string.r      N)
isinstancestrupper)xs    C/var/www/html/env/lib/python3.13/site-packages/django/utils/text.pycapfirstr      s=     aFQ4::<!AB%    z\r\n|\rz&(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))c                     [         R                  " USSS9n/ nU R                  S5       H#  nUR                  UR	                  U5      5        M%     SR                  U5      $ )a'  
A word-wrap function that preserves existing line breaks. Expects that
existing line breaks are posix newlines.

Preserve all white space except added line breaks consume the space on
which they break the line.

Don't wrap long words, thus the output text may have lines longer than
``width``.
F)widthbreak_long_wordsbreak_on_hyphensT
)textwrapTextWrapper
splitlinesextendwrapjoin)textr   wrapperresultlines        r   r$   r$   (   s[     ""G
 F%gll4() &99Vr   c                 v    Uc  [        SS5      nSU;   a  USU 0-  $ U R                  U5      (       a  U $ U  U 3$ )Nz%String to return when truncating textu   %(truncated_text)s…z%(truncated_text)struncated_text)r   endswith)r&   truncates     r   add_truncation_textr.   @   sZ    35L
 x'+T222 }}X VH:r   c                     U n[        SU5       H.  n[        R                  " U5      (       a  M   US-  nUS:X  d  M-    U$    U$ )N r   r   )r.   unicodedata	combining)lengthreplacementtruncate_lenchars       r   calculate_truncate_chars_lengthr7   P   sL    L#B4$$T**ALq  5
 r   c                   z   ^  \ rS rSr " S S\5      rSS.U 4S jjr\S 5       rS r	S	 r
S
 rS rU 4S jrSrU =r$ )TruncateHTMLParserZ   c                       \ rS rSrSrg)&TruncateHTMLParser.TruncationCompleted[    N)__name__
__module____qualname____firstlineno____static_attributes__r>   r   r   TruncationCompletedr<   [   s    r   rD   Tconvert_charrefsc                d   > [         TU ]  US9  [        5       U l        SU l        Xl        X l        g )NrE   r0   )super__init__r   tagsoutput	remainingr4   selfr3   r4   rF   	__class__s       r   rI   TruncateHTMLParser.__init__^   s/    *:;G	&r   c                     SSK Jn  U$ )Nr   )VOID_ELEMENTS)django.utils.htmlrR   )rN   rR   s     r   void_elements TruncateHTMLParser.void_elementse   s    3r   c                 h    U R                  X5        XR                  ;  a  U R                  U5        g g N)handle_starttagrT   handle_endtagrN   tagattrss      r   handle_startendtag%TruncateHTMLParser.handle_startendtagk   s/    S((((s# )r   c                     U =R                   U R                  5       -  sl         XR                  ;  a  U R                  R	                  U5        g g rW   )rK   get_starttag_textrT   rJ   
appendleftrZ   s      r   rX   "TruncateHTMLParser.handle_starttagp   s<    t--//(((II  % )r   c                     XR                   ;  a6  U =R                  SU S3-  sl         U R                  R                  U5        g g ! [         a     g f = f)N</>)rT   rK   rJ   remove
ValueError)rN   r[   s     r   rY    TruncateHTMLParser.handle_endtagu   sT    (((KKRuA;&K		  % )  s   A 
AAc                 *   U R                  U5      u  p[        U5      nU R                  U:  a;  SU l        U =R                  [	        X R
                  5      -  sl        U R                  eU =R                  U-  sl        U =R                  U-  sl        g Nr   )processlenrL   rK   r.   r4   rD   )rN   datarK   data_lens       r   handle_dataTruncateHTMLParser.handle_data}   sp    ||D)t9>>H$DNKK.v7G7GHHK***("vr   c                 X  >  [         TU ]  U5        U R                  5         g ! U R                   av    U =R                  SR                  U R                   Vs/ s H	  nSU S3PM     Os  snf sn5      -  sl        U R                  R                  5         U R                  5          g f = f)Nr0   rd   re   )rH   feedresetrD   rK   r%   rJ   clear)rN   rm   r[   rO   s      r   rr   TruncateHTMLParser.feed   s    	GL JJL '' 	KK277499#E9CbQK9#EFFKIIOOJJL	s   # 5B)A)(>B)(B))rK   rL   r4   rJ   )r?   r@   rA   rB   	ExceptionrD   rI   r   rT   r]   rX   rY   ro   rr   rC   __classcell__rO   s   @r   r9   r9   Z   sR    i  AE ' '  
$
&
	 	r   r9   c                   6   ^  \ rS rSrSS.U 4S jjrS rSrU =r$ )TruncateCharsHTMLParser   TrE   c                P   > Xl         SU l        [        TU ]  [	        X5      UUS9  g )Nr   )r3   r4   rF   )r3   processed_charsrH   rI   r7   rM   s       r   rI    TruncateCharsHTMLParser.__init__   s0     26G#- 	 	
r   c                 x   U =R                   [        U5      -  sl         U R                   U R                  :X  aY  [        U R                  5      [        U5      -   [        U R                  5      :X  a!  U =R                  U-  sl        U R
                  e[        SR                  US U R                   5      5      nX4$ )Nr0   )	r}   rl   r3   rK   rawdatarD   r   r%   rL   rN   rm   rK   s      r   rk   TruncateCharsHTMLParser.process   s    D	)  DKK/s4y(C,==KK4K***%5t~~ 678|r   )r3   r}   )r?   r@   rA   rB   rI   rk   rC   rw   rx   s   @r   rz   rz      s    @D 
 
 r   rz   c                       \ rS rSrS rSrg)TruncateWordsHTMLParser   c                     [         R                  " SU5      n[        SR                  US U R                   5      5      nX4$ )Nz(?<=\S)\s+(?=\S) )resplitr   r%   rL   r   s      r   rk   TruncateWordsHTMLParser.process   s:    xx+T2&6!789|r   r>   N)r?   r@   rA   rB   rk   rC   r>   r   r   r   r      s    r   r   c                   P   ^  \ rS rSrSrSrU 4S jrS
S jrS rS
S jr	S r
S	rU =r$ )	Truncator   z
An object used to truncate text, either by characters or words.

When truncating HTML text (either chars or words), input will be limited to
at most `MAX_LENGTH_HTML` characters.
i@KL c                 .   >^ [         TU ]  U4S j5        g )Nc                     > [        T 5      $ rW   r   r&   s   r   <lambda>$Truncator.__init__.<locals>.<lambda>   s	    Tr   )rH   rI   )rN   r&   rO   s    `r   rI   Truncator.__init__   s    *+r   c                 &   U R                  5         [        U5      nUS::  a  g[        R                  " SU R                  5      nU(       a6  [        XBS9nUR                  U5        UR                  5         UR                  $ U R                  XBU5      $ )z
Return the text truncated to be no longer than the specified number
of characters.

`truncate` specifies what should be used to notify that the string has
been truncated, defaulting to a translatable string of an ellipsis.
r   r0   NFCr3   r4   )
_setupintr1   	normalize_wrappedrz   rr   closerK   _text_chars)rN   numr-   htmlr3   r&   parsers          r   charsTruncator.chars   su     	SQ;$$UDMM:,FQFKKLLN== $77r   c                     [        X5      nSnSn[        U5       HP  u  px[        R                  " U5      (       a  M"  US-  nUc  XT:  a  UnXQ:  d  M8  [	        USU=(       d    S U5      s  $    U$ )z2Truncate a string after a certain number of chars.r   Nr   )r7   	enumerater1   r2   r.   )	rN   r3   r-   r&   r5   s_len	end_indexir6   s	            r   r   Truncator._text_chars   sz    6vH	 GA$$T** QJE U%9	~*40@).q+A8LL ' r   c                     U R                  5         [        U5      nUS::  a  gU(       a@  [        XBS9nUR                  U R                  5        UR                  5         UR                  $ U R                  XB5      $ )z
Truncate a string after a certain number of words. `truncate` specifies
what should be used to notify that the string has been truncated,
defaulting to ellipsis.
r   r0   r   )r   r   r   rr   r   r   rK   _text_words)rN   r   r-   r   r3   r   s         r   wordsTruncator.words   sa     	SQ;,FQFKK&LLN== 11r   c                     U R                   R                  5       n[        U5      U:  a   USU n[        SR	                  U5      U5      $ SR	                  U5      $ )zS
Truncate a string after a certain number of words.

Strip newlines in the string.
Nr   )r   r   rl   r.   r%   )rN   r3   r-   r   s       r   r   Truncator._text_words   sP     ##%u:'6NE&sxxAAxxr   r>   )NF)r?   r@   rA   rB   __doc__MAX_LENGTH_HTMLrI   r   r   r   r   rC   rw   rx   s   @r   r   r      s-      O,8*(2"
 
r   r   c                     [        U 5      R                  5       R                  SS5      n[        R                  " SSU5      nUS;   a  [        SU -  5      eU$ )a=  
Return the given string converted to a string that can be used for a clean
filename. Remove leading and trailing spaces; convert other spaces to
underscores; and remove anything that is not an alphanumeric, dash,
underscore, or dot.
>>> get_valid_filename("john's portrait in 2004.jpg")
'johns_portrait_in_2004.jpg'
r   _z(?u)[^-\w.]r0   >   r0   ...z$Could not derive file name from '%s')r   stripreplacer   subr	   )namess     r   get_valid_filenamer     sQ     	D	!!#s+A
~r1%AO%&Lt&STTHr   orc                     U (       d  g[        U 5      S:X  a  [        U S   5      $ [        S5      R                  S U SS  5       5      < S[        U5      < S[        U S   5      < 3$ )	z
>>> get_text_list(['a', 'b', 'c', 'd'])
'a, b, c or d'
>>> get_text_list(['a', 'b', 'c'], 'and')
'a, b and c'
>>> get_text_list(['a', 'b'], 'and')
'a and b'
>>> get_text_list(['a'])
'a'
>>> get_text_list([])
''
r0   r   r   z, c              3   8   #    U  H  n[        U5      v   M     g 7frW   r   ).0r   s     r   	<genexpr> get_text_list.<locals>.<genexpr>)  s     0ZSVVZs   Nr   )rl   r   r   r%   )list_	last_words     r   get_text_listr     s]     
5zQ58} 	
$0U3BZ00IE"I	 r   c                 @    [         R                  S[        U 5      5      $ )z*Normalize CRLF and CR newlines to just LF.r   )re_newlinesr   r   r   s    r   normalize_newlinesr   /  s     ??4T++r   c                    ^ 0 SS_SS_SS_SS_SS_SS_S	S
_SS
_SS
_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSS.	EmSR                  U4S jU R                  5        5       5      $ )z@Convert a phone number with letters into its numeric equivalent.a2bcd3efg4hr   j5klm6nop7q89)	rr   tuvwr   yzr0   c              3   F   >#    U  H  nTR                  X5      v   M     g 7frW   )get)r   r   char2numbers     r   r    phone2numeric.<locals>.<genexpr>T  s     @-Q;??1((-s   !)r%   lower)phoner   s    @r   phone2numericr   5  s   SS 	S 	S	
 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S  	S!" 	S#$ 5K8 77@%++-@@@r   c                 4    S[         R                  " U 5      -  $ )N   a)secrets	randbelowmax_random_bytess    r   _get_random_filenamer   W  s    '##$4555r   r   c                    [        U SSS9nU(       d  U$ [        U5      n[        US S 5      n[        R                  US'   [        U5      S-   n[        U5      U-   USS  -   $ )N   r   )compresslevelmtime
          )gzip_compress
memoryview	bytearraygzipFNAMEr   bytes)r   r   compressed_datacompressed_viewheaderfilenames         r   compress_stringr  [  sl    #AQa@O 1Os+,F

F1I#$45?H=8#obc&:::r   c                       \ rS rSrS rSrg)StreamingBufferij  c                 h    U R                  5       nU R                  S5        U R                  5         U$ rj   )getvalueseekr-   )rN   rets     r   readStreamingBuffer.readk  s&    mmo		!
r   r>   N)r?   r@   rA   rB   r  rC   r>   r   r   r	  r	  j  s    r   r	  c             #   L  #    [        5       nU(       a  [        U5      OS n[        USSUSS9 nUR                  5       v   U  H1  nUR	                  U5        UR                  5       nU(       d  M-  Uv   M3     S S S 5        UR                  5       v   g ! , (       d  f       N!= f7f)Nwbr   r   )r  moder   fileobjr   )r	  r   r   r  write)sequencer   bufr  zfileitemrm   s          r   compress_sequencer  s  s     

C9I#$45tH	As!
	hhjDKK88:Dt
	 
 ((*
 
s"   ,B$>B0B8B$
B!B$z
    ((?:
        [^\s'"]*
        (?:
            (?:"(?:[^"\\]|\\.)*" | '(?:[^'\\]|\\.)*')
            [^\s'"]*
        )+
    ) | \S+)
c              #   d   #    [         R                  [        U 5      5       H
  nUS   v   M     g7f)as  
Generator that splits a string by spaces, leaving quoted phrases together.
Supports both single and double quotes, and supports escaping quotes with
backslashes. In the output, strings will keep their initial and trailing
quote marks and escaped quotes will remain escaped (the results can then
be further processed with unescape_string_literal()).

>>> list(smart_split(r'This is "a person\'s" test.'))
['This', 'is', '"a person\\\'s"', 'test.']
>>> list(smart_split(r"Another 'person\'s' test."))
['Another', "'person\\'s'", 'test.']
>>> list(smart_split(r'A "\"funky\" style" test.'))
['A', '"\\"funky\\" style"', 'test.']
r   N)smart_split_refinditerr   )r&   bits     r   smart_splitr    s)      &&s4y1!f 2s   .0c                     U (       a  U S   S;  d  U S   U S   :w  a  [        SU -  5      eU S   nU SS R                  SU-  U5      R                  SS5      $ )	a@  
Convert quoted string literals to unquoted strings with escaped quotes and
backslashes unquoted::

    >>> unescape_string_literal('"abc"')
    'abc'
    >>> unescape_string_literal("'abc'")
    'abc'
    >>> unescape_string_literal('"a \"bc\""')
    'a "bc"'
    >>> unescape_string_literal("'\'ab\' c'")
    "'ab' c"
r   z"'r   zNot a string literal: %rr   z\%sz\\\)rg   r   )r   quotes     r   unescape_string_literalr"    sb     !E!QrUad]3a788aDEQr7??6E>5199%FFr   c                 \   [        U 5      n U(       a  [        R                  " SU 5      n O6[        R                  " SU 5      R                  SS5      R	                  S5      n [
        R                  " SSU R                  5       5      n [
        R                  " SSU 5      R                  S	5      $ )
a  
Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
dashes to single dashes. Remove characters that aren't alphanumerics,
underscores, or hyphens. Convert to lowercase. Also strip leading and
trailing whitespace, dashes, and underscores.
NFKCNFKDasciiignorez[^\w\s-]r0   z[-\s]+-z-_)	r   r1   r   encodedecoder   r   r   r   )valueallow_unicodes     r   slugifyr-    s     JE%%fe4 !!&%0VGX&VG_ 	
 FF;EKKM2E66)S%(..t44r   c                 f    [         R                  SU 5      R                  5       R                  5       $ )zI
Split CamelCase and convert to lowercase. Strip surrounding whitespace.
z \1)re_camel_caser   r   r   )r+  s    r   camel_case_to_spacesr0    s)     VU+11399;;r   c                 &    U R                   " U0 UD6$ )z_
Apply str.format() on 'format_string' where format_string, args,
and/or kwargs might be lazy.
)format)format_stringargskwargss      r   _format_lazyr6    s    
 000r   rW   )F)9r   r   r   r    r1   collectionsr   r   r   r   r   r   html.parserr   ior   django.core.exceptionsr	   django.utils.functionalr
   r   r   r   django.utils.regex_helperr   django.utils.translationr   r   r   r   r   r   r/  r$   r.   r7   r9   rz   r   r   r   r   r   r   r   r  r	  r  VERBOSEr  r  r"  r-  r0  r6  r   format_lazyr>   r   r   <module>r@     s    	      *  "  :  7 1 ;     z* !JK  . 6 6r0 *0 R  Rj    #/#5  2 , ,
 A AB6 ,0 ;g  59 $ " JJ& G G( 5 5(<1 <%r   