
    1yiQ                    .   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mZmZmZmZ dd
lmZmZ dZej6                  Zej8                  Zej:                  Zej<                  Zej>                  Zej@                  Z ejB                  Z!ejD                  Z"ejF                  Z#ejH                  Z$ejJ                  Z%ejL                  Z&ejN                  Z'ejP                  Z(ejR                  Z)ejT                  Z*ejV                  Z+ejX                  Z,ejZ                  Z-ej\                  Z.ej^                  Z/ej`                  Z0ejb                  Z1ejd                  Z2ejf                  Z3ejh                  Z4ejj                  Z5ejl                  Z6ejn                  Z7ejp                  Z8ejr                  Z9ejt                  Z:ejv                  Z;ejx                  Z<dZ=dZ>dZ?dZ@ eA ej                  dd            ZC e	e@      	 	 	 	 	 	 	 	 	 	 d,d       ZD e	e@      	 	 	 	 	 	 	 	 	 	 d-d       ZEd.d/dZFd0dZGd1dZH	 d2	 	 	 	 	 	 	 d3dZI	 d2	 	 	 	 	 d4dZJd.d5dZK G d dej                  ee         ZM	 	 d6	 	 	 	 	 	 	 	 	 d7dZB	 d2	 	 	 	 	 	 	 d8dZN	 d2	 	 	 	 	 	 	 d9dZOd0dZPd:dZQd:dZR	 d2	 	 	 	 	 	 	 	 	 	 	 d;d ZS	 d2	 	 	 	 	 	 	 	 	 	 	 d;d!ZT	 d2	 	 	 	 	 	 	 	 	 	 	 d;d"ZU	 	 d<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=d#ZV	 	 d<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=d$ZW	 	 d<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d>d%ZX	 	 d<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d>d&ZY	 	 d<	 	 	 	 	 	 	 	 	 	 	 	 	 d?d'ZZ	 	 d<	 	 	 	 	 	 	 	 	 	 	 	 	 d@d(Z[	 d2	 	 	 	 	 	 	 	 	 	 	 dAd)Z\	 d2	 	 	 	 	 	 	 	 	 	 	 dBd*Z]d+ Z^ ej                  eMe^       y)Ca  
Backrefs for the 'regex' module.

Add the ability to use the following backrefs with re:

 - `\Q` and `\Q...\E`                                           - Escape/quote chars (search)
 - `\c` and `\C...\E`                                           - Uppercase char or chars (replace)
 - `\l` and `\L...\E`                                           - Lowercase char or chars (replace)
 - `\N{Black Club Suit}`                                        - Unicode character by name (replace)
 - `\u0000` and `\U00000000`                                    - Unicode characters (replace)
 - `\R`                                                         - Generic line breaks (search)

Licensed under MIT
Copyright (c) 2015 - 2020 Isaac Muse <isaacmuse@gmail.com>
    )annotationsN)	lru_cache   )util)_bregex_parse)ReplaceTemplate)AnyStrCallableAnyGenericMappingIteratorcast)PatternMatch)6expandexpandfmatch	fullmatchsearchsubsubfsubnsubfnsplit	splititerfindallfinditerpurgeescapeDDEBUGAASCIIB	BESTMATCHEENHANCEMATCHFFULLCASEI
IGNORECASELLOCALEM	MULTILINERREVERSESDOTALLUUNICODEXVERBOSEV0VERSION0V1VERSION1WWORDPPOSIXDEFAULT_VERSIONFORMATcompilecompile_searchcompile_replaceBregexr      i   )maxsizec                L    t        j                  | ||      j                         S )zCached search compile.)r   _SearchParserparse)pattern
re_verbose
re_versionpattern_types       Q/var/www/html/content_weaver/venv/lib/python3.12/site-packages/backrefs/bregex.py_cached_search_compilerR   U   s"     &&w
JGMMOO    c                l    t        j                  | |t        |t        z              j	                         S )zCached replace compile.)r   _ReplaceParserboolrB   rL   )rM   replflagsrP   s       rQ   _cached_replace_compilerY   a   s+     ''tEFN7KLRRTTrS   c                    | s t         j                         j                  }|S t        j                         j                  }|S )zGet size of cache.)rR   
cache_infocurrsizerY   )replacesizes     rQ   _get_cache_sizer_   m   s=     %002;; K '113<<KrS   c                 T    t         j                          t        j                          y)zPurge the cache.N)rY   cache_clearrR    rS   rQ   _purge_cacherc   w   s     '')&&(rS   c                "    t        | t              S )z$Check if object is a replace object.)
isinstancer   )objs    rQ   _is_replacerg   ~   s     c?++rS   c                    | t        d      t        |t              r|j                  |       S t	        j
                  | j                  |t        |t        z              j                         j                  |       S )zOExpand with either the `ReplaceTemplate` or compile on the fly, or return None.zMatch is None!)

ValueErrorre   r   r   r   rU   rerV   rB   rL   )mrW   rX   s      rQ   _apply_replace_backrefsrl      sd     	y)**$({{1~''dD4HIOOQXXYZ[[rS   c                   t        | t        t        f      rt        |z  }|t        z  rt        }n|t
        z  rt
        }nd}|t        z  st        | ||t        |             }|S t        j                  t        t        |       ||      j                         }|S t        | t              r|rt        d      | j                   }|S t        | t"              r|rt        d      | }|S t%        d      )z0Apply the search backrefs to the search pattern.r   5Cannot process flags argument with a compiled patternz6Cannot process flags argument with a compiled pattern!z!Not a string or compiled pattern!)re   strbytesr8   r9   r;   r"   rR   typer   rK   r   r	   rL   rF   ri   _pattern_REGEX_TYPE	TypeError)rM   rX   rN   rO   ps        rQ   _apply_search_backrefsrv      s     'C<(u_
2:JRZJJ&ZgA H ++D,A:zZ``bA H 
GV	$TUU H 
G[	)UVV H ;<<rS   c                    t        | t              r(| j                  |k7  r|rt        d      t        d      yt        | t        t
        f      st        d      y)z(Check if replace template is expandable.z(Replace not compiled as a format replacez3Replace should not be compiled as a format replace!z-Expected string, buffer, or compiled replace!N)re   r   
use_formatri   ro   rp   rt   )rW   rx   s     rQ   _assert_expandablery      s[     $(??j( !KLL !VWW	 )
 sEl+GHH ,rS   c                      e Zd ZU dZded<   ded<   ded<   dZd!d" fd	Zed#d
       Zed$d       Z	ed%d       Z
ed&d       Zed'd       Zd$dZd(dZd(dZd)dZ	 d*	 	 	 	 	 d+dZ	 d,	 	 	 	 	 d-dZed.d       Z	 	 	 	 	 	 	 	 d/dZ	 	 	 	 	 	 	 	 d/dZ	 	 	 	 	 	 	 	 d/dZ	 	 	 	 	 	 	 	 d0dZ	 	 	 	 	 	 	 	 d1dZ	 	 	 	 	 	 	 	 d2dZ	 	 	 	 	 	 	 	 d3dZ	 	 	 	 	 	 	 	 	 	 d4dZ	 	 	 	 	 	 	 	 	 	 d4dZ	 	 	 	 	 	 	 	 	 	 d5dZ	 	 	 	 	 	 	 	 	 	 d5d Z xZS )6rF   zBregex object.Pattern[AnyStr]rr   rV   auto_compileint_hashrr   r|   r~   c           
     h    t         |   ||t        t        |       t        |      ||f             y)zInitialization.r   N)super__init__hashrq   )selfrM   r|   	__class__s      rQ   r   zBregex.__init__   s6     	%T
DM7LIJ 	 	
rS   c                J    t        t        | j                  j                        S )zReturn pattern.)r   r	   rr   rM   r   s    rQ   rM   zBregex.pattern   s     FDMM1122rS   c                J    t        t        | j                  j                        S )zReturn flags.)r   r}   rr   rX   r   s    rQ   rX   zBregex.flags   s     C,,--rS   c                d    t        t        t        t        f   | j                  j
                        S )zReturn group index.)r   r   ro   r}   rr   
groupindexr   s    rQ   r   zBregex.groupindex   s$     GCH%t}}'?'?@@rS   c                B    t        d| j                  j                        S )zReturn groups.tuple[AnyStr | None, ...])r   rr   groupsr   s    rQ   r   zBregex.groups   s     /1E1EFFrS   c                .    | j                   j                  S )zReturn scanner.)rr   scannerr   s    rQ   r   zBregex.scanner   s     }}$$$rS   c                    | j                   S )zHash.)r~   r   s    rQ   __hash__zBregex.__hash__   s     zzrS   c                    t        |t              xr4 | j                  |j                  k(  xr | j                  |j                  k(  S zEqual.re   rF   rr   r|   r   others     rQ   __eq__zBregex.__eq__   sA     uf% 4MMU^^+4!3!33	
rS   c                    t        |t               xs4 | j                  |j                  k7  xs | j                  |j                  k7  S r   r   r   s     rQ   __ne__zBregex.__ne__  sD     5&)) 4MMU^^+4!3!33	
rS   c                    dj                  | j                  | j                  j                  | j                  | j
                        S )zRepresentation.z{}.{}({!r}, auto_compile={!r}))format
__module__r   __name__rr   r|   r   s    rQ   __repr__zBregex.__repr__  s8     066OOT^^44dmmTEVEV
 	
rS   c                d   t        |t              r||j                  k7  rt        d      |S t        |t              s"t        |t        t
        f      r:| j                  r.| j                  ||rt        |t              s
t              S d      S t        |t        t
        f      r|rt        d      |S )zCompile replacements.+Compiled replace cannot be a format object!r   zDFormat replaces cannot be called without compiling replace template!)
re   r   rx   ri   ro   rp   r|   rC   rB   AttributeError)r   templaterx   s      rQ   _auto_compilezBregex._auto_compile  s     h0X000 !NOO  /2z(SRWL7Y^b^o^o<<Z
S[]lHm6vvstvv3,/J !!ghhrS   c                0    t        | j                  ||      S )zCompile replace.)rE   rr   )r   rW   rX   s      rQ   rC   zBregex.compile%  s     t}}dE::rS   c                B    t        d| j                  j                        S )zReturned named lists.Mapping[str, set[str | bytes]])r   rr   named_listsr   s    rQ   r   zBregex.named_lists.  s     4dmm6O6OPPrS   c                B     | j                   j                  |g|i |S )zApply `search`.)rr   r   r   stringargskwargss       rQ   r   zBregex.search4  s%     $t}}##F<T<V<<rS   c                V    t        d | j                  j                  |g|i |      S )zApply `match`.Match[AnyStr] | None)r   rr   r   r   s       rQ   r   zBregex.match>  s/     *,?DMM,?,?,X,XQW,XYYrS   c                V    t        d | j                  j                  |g|i |      S )zApply `fullmatch`.r   )r   rr   r   r   s       rQ   r   zBregex.fullmatchH  s/     *,CDMM,C,CF,\T,\U[,\]]rS   c                V    t        d | j                  j                  |g|i |      S )zApply `split`.list[AnyStr])r   rr   r   r   s       rQ   r   zBregex.splitR  s-     N$7DMM$7$7$P$P$PQQrS   c                l    t        t        t            | j                  j                  |g|i |      S )zApply `splititer`.)r   r   r	   rr   r   r   s       rQ   r   zBregex.splititer\  s2     HV$&=dmm&=&=f&Vt&Vv&VWWrS   c                V    t        d | j                  j                  |g|i |      S )zApply `findall`.'list[AnyStr] | list[tuple[AnyStr, ...]])r   rr   r   r   s       rQ   r   zBregex.findallf  s1     =?Tt}}?T?TU[?m^b?mfl?mnnrS   c                z    t        t        t        t               | j                  j
                  |g|i |      S )zApply `finditer`.)r   r   r   r	   rr   r   r   s       rQ   r   zBregex.finditerp  s7     HU6]+-CT]]-C-CF-\T-\U[-\]]rS   c                ~    t        t         | j                  j                  | j	                  |      |g|i |      S )zApply `sub`.)r   r	   rr   r   r   r   rW   r   r   r   s        rQ   r   z
Bregex.subz  s<     F-DMM--d.@.@.F`QU`Y_`aarS   c           	         t        t         | j                  j                  | j	                  |d      |g|i |      S )z&Apply `sub` with format style replace.T)r   r	   rr   r   r   r   s        rQ   r   zBregex.subf  s>     F.DMM..t/A/A$/MvgX\g`fghhrS   c                v    t        d | j                  j                  | j                  |      |g|i |      S )z'Apply `subn` with format style replace.tuple[AnyStr, int])r   rr   r   r   r   s        rQ   r   zBregex.subn  s?     (*<$--*<*<T=O=OPT=UW]*o`d*ohn*opprS   c           	     x    t        d | j                  j                  | j                  |d      |g|i |      S )z%Apply `subn` after applying backrefs.r   T)r   rr   r   r   r   s        rQ   r   zBregex.subfn  sB     (*=$--*=*=d>P>PQUW[>\^d*vgk*vou*vwwrS   )T)rM   r{   r|   rV   returnNone)r   r	   )r   r}   )r   zMapping[str, int])r   r   )r   r   )r   r   r   rV   )r   ro   F)r   AnyStr | Callable[..., AnyStr]rx   rV   r   r   r   )rW   r   rX   r}   r   Callable[..., AnyStr])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   Iterator[AnyStr])r   r	   r   r   r   r   r   r   )r   r	   r   r   r   r   r   Iterator[Match[AnyStr]])
rW   r   r   r	   r   r   r   r   r   r	   )
rW   r   r   r	   r   r   r   r   r   r   ) r   r   __qualname____doc____annotations__	__slots__r   propertyrM   rX   r   r   r   r   r   r   r   r   rC   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @rQ   rF   rF      s6   J5I
 3 3
 . .
 A A
 G G
 % %




 !0  
(	, ;,; ; 
	; Q Q
== = 	=
 
=ZZ Z 	Z
 
Z^^ ^ 	^
 
^RR R 	R
 
RXX X 	X
 
Xoo o 	o
 
1o^^ ^ 	^
 
!^	b,	b 	b 		b
 	b 
	b	i,	i 	i 		i
 	i 
	i	q,	q 	q 		q
 	q 
	q	x,	x 	x 		x
 	x 
	xrS   rF   c                    t        | t              r|t        d      |dk7  rt        d      | S |d}t        t        | |fi ||      S )z>Compile both the search or search and replace into one object.z4Cannot compile Bregex with a different auto_compile!r   rn   T)re   rF   ri   rD   )rM   rX   r|   r   s       rQ   rC   rC     s\     '6"#STTaZTUULnWe>v>MMrS   c           	     n    t        t        t           t        j                  t        | |      |fi |      S )z(Compile with extended search references.)r   r   r	   _regexrC   rv   )rM   rX   r   s      rQ   rD   rD     s0     0FwPU0VX]!hag!hiirS   c                   | t        | t              rt        |t        t        f      rc| j                  t
        z  st        | ||t        |            }|S t        j                  | |t        |t        z              j                         }|S t        |t              r4|rt        d      |j                  t!        |       k7  rt        d      |}|S t#        d      t#        d      )zOConstruct a method that can be used as a replace method for `sub`, `subn`, etc.z5Cannot process flags argument with a ReplaceTemplate!z4Pattern hash doesn't match hash in compiled replace!zNot a valid type!z.Pattern must be a compiled regular expression!)re   rs   ro   rp   rX   r"   rY   rq   r   rU   rV   rB   rL   r   ri   pattern_hashr   rt   )rM   rW   rX   calls       rQ   rE   rE     s     z';?dS%L)MME).weT$ZP K %33GT4PVCWX^^` K o. !XYY  DM1 !WXXD
 K /00HIIrS   c                 @    t                t        j                          y)zPurge caches.N)rc   r   r   rb   rS   rQ   r   r     s     N
LLNrS   c                0    t        |       t        | |      S )z8Expand the string using the replace pattern or function.)ry   rl   rk   rW   s     rQ   r   r     s     t"1d++rS   c                >    t        |d       t        | |t              S )z?Expand the string using the format replace pattern or function.TrX   )ry   rl   rB   r   s     rQ   r   r     s     tT""1d&99rS   c           	     `    t        dt        j                  t        | |      ||g|i |      S )zWrapper for `match`.r   )r   r   r   rv   rM   r   rX   r   r   s        rQ   r   r     s7     +GU;VU\T\U[\ rS   c           	     `    t        dt        j                  t        | |      ||g|i |      S )zWrapper for `fullmatch`.r   )r   r   r   rv   r   s        rQ   r   r     s:     /?`QU`Y_` rS   c           	     `    t        dt        j                  t        | |      ||g|i |      S )zWrapper for `search`.r   )r   r   r   rv   r   s        rQ   r   r     s7     ,We<fe]d]V\] rS   c           
     .   t        |      }t        |t        t        f      }|r,t	        t
        t           |      j                  rt        d      t        | |      } t	        t        t        j                  | |s|rt        | |      n|||dg|i |      S )zWrapper for `sub`.r   r   )rg   re   ro   rp   r   r   r	   rx   ri   rD   r   r   rE   	rM   rW   r   countrX   r   r   
is_replace	is_strings	            rQ   r   r   "  s     T"J4#u.Id?62D9DDFGGWe,G


iogt4UY\b	
 		
 		
 rS   c                F   t        |      }t        |t        t        f      }|r,t	        t
        t           |      j                  st        d      t        | |      } |rt        nd}	t	        t        t        j                  | |s|rt        | ||	      n|||dg|i |      S )zWrapper for `subf`.(Compiled replace is not a format object!r   r   )rg   re   ro   rp   r   r   r	   rx   ri   rD   rB   r   r   rE   
rM   rW   r   r   rX   r   r   r   r   rflagss
             rQ   r   r   >  s     T"J4#u.I$v6=HHCDDWe,G VaF

jT]ogt6Bcgjp	
 		
 		
 rS   c           
     &   t        |      }t        |t        t        f      }|r,t	        t
        t           |      j                  rt        d      t        | |      } t	        dt        j                  | |s|rt        | |      n|||dg|i |      S )zWrapper for `subn`.r   r   r   )rg   re   ro   rp   r   r   r	   rx   ri   rD   r   r   rE   r   s	            rQ   r   r   [  s     T"J4#u.Id?62D9DDFGGWe,G
iogt4UY\b	
 		
 		
 rS   c                >   t        |      }t        |t        t        f      }|r,t	        t
        t           |      j                  st        d      t        | |      } |rt        nd}	t	        dt        j                  | |s|rt        | ||	      n|||dg|i |      S )zWrapper for `subfn`.r   r   r   r   )rg   re   ro   rp   r   r   r	   rx   ri   rD   rB   r   r   rE   r   s
             rQ   r   r   w  s     T"J4#u.I$v6=HHCDDWe,G VaFjT]ogt6Bcgjp	
 		
 		
 rS   c           	     b    t        dt        j                  t        | |      |||g|i |      S )zWrapper for `split`.r   )r   r   r   rv   rM   r   maxsplitrX   r   r   s         rQ   r   r     s:     +GU;VXufW[f_ef rS   c           	     x    t        t        t           t        j                  t        | |      |||g|i |      S )zWrapper for `splititer`.)r   r   r	   r   r   rv   r   s         rQ   r   r     sB     /?SXj[_jcij rS   c           	     `    t        dt        j                  t        | |      ||g|i |      S )zWrapper for `findall`.r   )r   r   r   rv   r   s        rQ   r   r     s7     1-gu=vu^t^W]^ rS   c           	         t        t        t        t              t	        j
                  t        | |      |g|i |      S )zWrapper for `finditer`.)r   r   r   r	   r   r   rv   r   s        rQ   r   r     s>     v.w>XXQWX rS   c                >    t         | j                  | j                  ffS )N)rF   rr   r|   )ru   s    rQ   _pickler     s    AJJ///rS   )
rM   r	   rN   rV   rO   rV   rP   type[AnyStr]r   r	   )
rM   r{   rW   r	   rX   r}   rP   r   r   zReplaceTemplate[AnyStr]r   )r]   rV   r   r}   )r   r   )rf   r   r   rV   r   )rk   r   rW    ReplaceTemplate[AnyStr] | AnyStrrX   r}   r   r	   )rM   )AnyStr | Pattern[AnyStr] | Bregex[AnyStr]rX   r}   r   zAnyStr | Pattern[AnyStr])rW   r   rx   rV   r   r   )r   N)
rM   r   rX   r}   r|   zbool | Noner   r   r   zBregex[AnyStr])rM   r   rX   r}   r   r   r   r{   )rM   r{   rW   r   rX   r}   r   r   )rk   r   rW   r   r   r	   )rM   r   r   r	   rX   r}   r   r   r   r   r   r   )r   r   )rM   r   rW   r   r   r	   r   r}   rX   r}   r   r   r   r   r   r	   )rM   r   rW   r   r   r	   r   r}   rX   r}   r   r   r   r   r   r   )rM   r   r   r	   r   r}   rX   r}   r   r   r   r   r   r   )rM   r   r   r	   r   r}   rX   r}   r   r   r   r   r   r   )rM   r   r   r	   rX   r}   r   r   r   r   r   r   )rM   r   r   r	   rX   r}   r   r   r   r   r   r   )`r   
__future__r   regexr   copyreg_copyreg	functoolsr   
_lru_cacherH   r   _utilr   r   typingr	   r
   r   r   r   r   r   _bregex_typingr   r   __all__r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   r    rB   _UPPER_LOWER	_MAXCACHErq   rC   rs   rR   rY   r_   rc   rg   rl   rv   ry   	ImmutablerF   rD   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   picklerb   rS   rQ   <module>r      s   #   -   * J J J * HH
HH
HH	
HH""
HH??
HH

HH	
HH	
HH
..
HH	
HH
..
HH
..YY??YY??
HH{{
HH((	 
 
	
 	>6>>"a() IPPP P 	P
 P P IUU
U U 	U
 U U), \\
*\ \ 	\" 6 B
I `xU__gfo `xJ  $N6NN N 	N
 N. j6jj j 	j 
(  	4,: 6  	
  $ 6  	
  $ 6  	
  & 6
(  	
    @ 6
(  	
    B 6
(  	
    @ 6
(  	
    @ 	6  	
   & 	6  	
   & 6  	
  -$ 6  	
  0   rS   