
    Hwg@                        d dl Z d dl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 dlmZ d dlmZ d d	lmZmZ ed
        Z edej.                        Z edej.                        Z G d d      Z G d d      ZeZ edej.                        Z edej.                        Z ed      Z ed      Z ed        Z! G d de      Z"ed        Z#e ed      fd       Z$ed        Z%ed        Z&d Z'dddZ( G d  d!e      Z)ddd"Z* ed#ejV                        Z,d$ Z-ed%        Z.ed)d&       Z/d' Z0d( Z1 ee1e2      Z3y)*    N)GzipFile)compress)BytesIO)SuspiciousFileOperation)SimpleLazyObjectkeep_lazy_textlazy)_lazy_re_compile)gettext)gettext_lazypgettextc                 r    | s| S t        | t              st        |       } | d   j                         | dd z   S )z(Capitalize the first letter of a string.r      N)
isinstancestrupper)xs    H/var/www/horilla/myenv/lib/python3.12/site-packages/django/utils/text.pycapfirstr      s:     aFQ4::<!AB%    z
([^<>\s]+)z<|([^<>\s]+)c                       e Zd Zed        Zy)
WordsRegexc                    t         j                  | |      }||d   |S | j                  d|j                  d            }|dk  rt        j                  | |dz         S |dz  }t        | |j                  d      | |      S )Nr   >r   )re_prtsearchfindendre_notag	FakeMatchstart)textpospartialr   s       r   r   zWordsRegex.search*   s     --c*?gaj4N iiW[[^,7??4q11 1HCT'--"2S93??r   N)__name__
__module____qualname__staticmethodr    r   r   r   r   )   s    @ @r   r   c                   (    e Zd ZddgZddZd Zd Zy)r    _text_endc                 2    |dk(  sJ d       | j                   S )Nr   z'This specific object takes only group=0)r,   selfgroups     r   r   zFakeMatch.end?   s    zDDDzyyr   c                 >    |dk(  ry |dk(  sJ d       | j                   S )Nr   r   z.This specific object takes only group in {0,1})r+   r.   s     r   __getitem__zFakeMatch.__getitem__C   s(    A:zKKKzzzr   c                 "    ||c| _         | _        y N)r+   r,   )r/   r"   r   s      r   __init__zFakeMatch.__init__I   s     $c
DIr   N)r   )r%   r&   r'   	__slots__r   r2   r5   r)   r   r   r    r    <   s    &!I*r   r    z<[^>]+?>|(.)z<(/)?(\S+?)(?:(\s*/)|\s.*?)?>z\r\n|\rz&(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))c                 >      fd}dj                   |             S )aC  
    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``.
    c               3     K   j                  d      D ]  } t        | j                  d      xr dz   xs       }t        |       |kD  r| d |dz    j	                  d      dz   }|dk(  r | j                  d      dz   }|dk(  r|  d} nGd| d |dz
   z   | |d  } t        | j                  d      xr dz   xs       }t        |       |kD  r| s|   y w)NT
r    r    z%s
)
splitlinesminendswithlenrfindr   )line	max_widthspacer"   widths      r   
_generatorzwrap.<locals>._generatord   s     OOD) 	DT]]40>UQYG%%PId)i'_y1}-33C81<A: IIcNQ.Ez"
!tKeai000EF|t!4!B!KeeT	 d)i' 
	s   CCCCr;   )join)r"   rD   rE   s   `` r   wraprG   W   s    " 77:<  r   c                   P     e Zd ZdZdZ fdZd
dZddZd ZddZ	d Z
d	 Z xZS )	Truncatorz
    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         |   fd       y )Nc                      t               S r4   r   r"   s   r   <lambda>z$Truncator.__init__.<locals>.<lambda>   s    T r   )superr5   )r/   r"   	__class__s    `r   r5   zTruncator.__init__   s    *+r   c                 f    |t        dd      }d|v r|d|iz  S |j                  |      r|S ||S )Nz%String to return when truncating textu   %(truncated_text)s…z%(truncated_text)struncated_text)r   r>   )r/   r"   truncates      r   add_truncation_textzTruncator.add_truncation_text   sS    79PH  8+/666 ==" Kx((r   c                 D   | j                          t        |      }t        j                  d| j                        }|}| j                  d|      D ]$  }t        j                  |      r|dz  }|dk(  s$ n |r| j                  ||||d      S | j                  ||||      S )a  
        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.
        NFCr;   r   r   F)	_setupintunicodedata	normalize_wrappedrT   	combining_truncate_html_text_chars)r/   numrS   htmllengthr"   truncate_lenchars           r   charszTruncator.chars   s     	S$$UDMM: ,,R: 	D((.!1$		
 &&vx|USS$EEr   c                     d}d}t        |      D ]I  \  }}t        j                  |      r|dz  }|||kD  r|}||kD  s0| j                  |d|xs d |      c S  |S )z2Truncate a string after a certain number of chars.r   Nr   )	enumeraterY   r\   rT   )	r/   ra   rS   r"   rb   s_len	end_indexirc   s	            r   r^   zTruncator._text_chars   s    	  
	RGAt$$T* QJE U\%9	v~//5Ey~A0FQQ
	R r   c                     | j                          t        |      }|r| j                  ||| j                  |d      S | j	                  ||      S )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.
        T)rW   rX   r]   r[   _text_words)r/   r_   rS   r`   ra   s        r   wordszTruncator.words   sJ     	S&&vxPTUU11r   c                     | j                   j                         }t        |      |kD  r&|d| }| j                  dj	                  |      |      S dj	                  |      S )zk
        Truncate a string after a certain number of words.

        Strip newlines in the string.
        Nr:   )r[   splitr?   rT   rF   )r/   ra   rS   rl   s       r   rk   zTruncator._text_words   sV     ##%u:'6NE++CHHUOXFFxxr   c                    |r|dk  ryd}t        |      | j                  kD  r|d| j                   }d}d}d}d}	d}
g }|rt        nt        }|
|k  r|j	                  ||      }|sn|j                  d      }|d   r|
dz  }
|
|k(  r|}	=t        j                  |d         }|r|
|k\  r]|j                         \  }}}|j                         }|s||v rn/|r	 |j                  |      }||dz   d }n|j                  d|       |
|k  r| j                  d|      }|
|k  r|r|r||z  }|S |d|	 }|r||z  }|D ]
  }|d|z  z  } |S # t        $ r Y Pw xY w)	a  
        Truncate HTML to a certain number of chars (not counting tags and
        comments), or, if words is True, then to a certain number of words.
        Close opened tags if they were correctly closed in the given HTML.

        Preserve newlines in the HTML.
        r   r;   FNT)	brcollinkbaseimgparamareahrinputr   z</%s>)r?   MAX_LENGTH_HTMLre_wordsre_charsr   r   re_tagmatchgroupslowerindex
ValueErrorinsertrT   )r/   ra   rS   r"   rb   rl   size_limitedhtml4_singletsr#   end_text_poscurrent_len	open_tagsregexmtagclosing_tagtagnameself_closingri   truncate_textouts                        r   r]   zTruncator._truncate_html   s    Vq[t9t+++.$../DL

 	!xV#T3'A%%(Ctq ,.#&L,,qt$C+514.K,mmoGw.83!0A !*!a%' 2I   G,E V#H 00X>& %K=L!= C 	!C7S= C	! 
1 " s   E 	EEr4   )NF)r%   r&   r'   __doc__ry   r5   rT   rd   r^   rl   rk   r]   __classcell__)rP   s   @r   rI   rI   x   s4      O,)F.&
2
Vr   rI   c                     t        |       j                         j                  dd      }t        j                  dd|      }|dv rt        d| z        |S )aY  
    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.]r;   >   ..r;   .z$Could not derive file name from '%s')r   stripreplaceresubr   )namess     r   get_valid_filenamer   0  sQ     	D	!!#s+A
~r1%AO%&Lt&STTHr   orc                     | syt        |       dk(  rt        | d         S t        d      j                  d | dd D              dt        |      dt        | d         S )	a   
    >>> 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([])
    ''
    r;   r   r   z, c              3   2   K   | ]  }t        |        y wr4   rL   ).0ri   s     r   	<genexpr>z get_text_list.<locals>.<genexpr>U  s     0SV0s   Nr:   )r?   r   r   rF   )list_	last_words     r   get_text_listr   A  s]     
5zQ58} 	
$0U3BZ00IE"I	 r   c                 @    t         j                  dt        |             S )z*Normalize CRLF and CR newlines to just LF.r9   )re_newlinesr   r   rM   s    r   normalize_newlinesr   [  s     ??4T++r   c                     i ddddddddddddd	d
dd
dd
dddddddddddddddddddddddddd	dj                  fd| j                         D              S )z@Convert a phone number with letters into its numeric equivalent.a2bcd3efg4hri   j5klr   6nop7q89)	rr   tuvwr   yzr;   c              3   B   K   | ]  }j                  ||        y wr4   )get)r   r   char2numbers     r   r   z phone2numeric.<locals>.<genexpr>  s     @Q;??1a(@s   )rF   r   )phoner   s    @r   phone2numericr   a  s   SS 	S 	S	
 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S  	S!" 	S#$ 5K8 77@%++-@@@r   c                 2    dt        j                  |       z  S )N   a)secrets	randbelowmax_random_bytess    r   _get_random_filenamer     s    '##$4555r   r   c                    t        | dd      }|s|S t        |      }t        |d d       }t        j                  |d<   t        |      dz   }t        |      |z   |dd  z   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                       e Zd Zd Zy)StreamingBufferc                 h    | j                         }| j                  d       | j                          |S )Nr   )getvalueseekrS   )r/   rets     r   readzStreamingBuffer.read  s&    mmo		!
r   N)r%   r&   r'   r   r)   r   r   r   r     s    r   r   c             #   0  K   t               }|rt        |      nd }t        |dd|d      5 }|j                          | D ]*  }|j	                  |       |j                         }|s'| , 	 d d d        |j                          y # 1 sw Y   xY ww)Nwbr   r   )r   moder   fileobjr   )r   r   r   r   write)sequencer   bufr   zfileitemdatas          r   compress_sequencer     s     

C9I#$45tH	As!
 		hhj 	DKK88:D
			 ((*	 	s"   *B;B
(B
/B
BBz
    ((?:
        [^\s'"]*
        (?:
            (?:"(?:[^"\\]|\\.)*" | '(?:[^'\\]|\\.)*')
            [^\s'"]*
        )+
    ) | \S+)
c              #   `   K   t         j                  t        |             D ]	  }|d     yw)a  
    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s   ,.c                     | r| d   dvs| d   | d   k7  rt        d| z        | d   }| dd j                  d|z  |      j                  dd      S )	al  
    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\\\)r   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                 J   t        |       } |rt        j                  d|       } n5t        j                  d|       j                  dd      j	                  d      } t        j                  dd| j                               } t        j                  dd|       j                  d	      S )
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-]r;   z[-\s]+-z-_)	r   rY   rZ   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    t         j                  d|       j                         j                         S )zQ
    Split CamelCase and convert to lowercase. Strip surrounding whitespace.
    z \1)re_camel_caser   r   r   )r	  s    r   camel_case_to_spacesr    s)     VU+11399;;r   c                 &     | j                   |i |S )zk
    Apply str.format() on 'format_string' where format_string, args,
    and/or kwargs might be lazy.
    )format)format_stringargskwargss      r   _format_lazyr    s    
  =000r   )F)4r   r   r   rY   r   r   r   ior   django.core.exceptionsr   django.utils.functionalr   r   r	   django.utils.regex_helperr
   django.utils.translationr   r   r   r   r   Sr   r   r   r    rz   r{   r|   r   r  rG   rI   r   r   r   r   r   r   r   r   VERBOSEr   r   r   r  r  r  r   format_lazyr)   r   r   <module>r     s    	    *  : J J 6 1 ;    ( M2440	/244	0@ @&* *( ORTT2	:BDD	Az* !JK ! !@u  up    #/#5  2 , ,
 A AB6 ,0 ;g  59 $ " JJ& G G( 5 5(<1 <%r   