
    iil                    H   d 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mZ 	 ddlmZmZ n# e$ r ddlmZmZ Y nw xY werddlmZ i de
d	ed
edede	dedeez   de	ez   ded e
j                    dee	z   dz   dee	z   dz   dd                     ee
                              ee	z   dz                       dee	z   dz   dee	z   dz   dee	z   dz   Zed         ed         ed         ed         ed         ed         dZ G d d           Zd!S )"a
  The code in this files is adapted from https://github.com/crdoconnor/xeger/blob/master/xeger/xeger.py.Which in turn
adapted it from https://bitbucket.org/leapfrogdevelopment/rstr/.

Copyright (C) 2015, Colm O'Connor
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the Leapfrog Direct Response, LLC, including
      its subsidiaries and affiliates nor the names of its
      contributors, may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEAPFROG DIRECT
RESPONSE, LLC, INCLUDING ITS SUBSIDIARIES AND AFFILIATES, BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    )annotations)chain)ascii_lettersascii_lowercaseascii_uppercasedigits	printablepunctuation
whitespace)TYPE_CHECKINGAnyPattern)
SubPatternparse)Randomr	   letters	uppercase	lowercaser   r
   	nondigits
nonlettersr   nonwhitespacenormal word_nonword 
postalsafez .-#/urlsafez-._~
domainsafe-)category_digitcategory_not_digitcategory_spacecategory_not_spacecategory_wordcategory_not_wordc                  L    e Zd ZdZddd	ZddZd dZd!dZd"dZd#dZ	d$dZ
dS )%RegexFactoryzFactory for regexes.
   randomr   limitintreturnNonec                     | _         i  _        | _        t           fdd  j         fdd d  fd j         fdd  fd	 fd
 fdd d _        dS )zCreate a RegexFactoryc                x    j                             t          j        t	          |           d                    S Nr   )_randomchoicer	   replacechrxselfs    z/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/polyfactory/value_generators/regex.py<lambda>z'RegexFactory.__init__.<locals>.<lambda>Z   s+    T\%8%89J3q66SU9V9V%W%W     c                    dS r2    r8   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>[   s    B r<   c                ^    j                             t          j        dd                    S )N
r   )r3   r4   r	   r5   r7   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>]   s$    T\001B41L1LMM r<   c                T    d t          | d         | d         dz             D             S )Nc                ,    g | ]}t          |          S r>   )r6   ).0is     r:   
<listcomp>z;RegexFactory.__init__.<locals>.<lambda>.<locals>.<listcomp>^   s    FFF1AFFFr<   r      )ranger?   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>^   s+    FFadAaD1H0E0EFFF r<   c                Z    t           t          |                                                    S N)_categoriesstrlowerr?   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>_   s    +c!ffllnn"= r<   c                    d                     fdj                            | d                   D                       S )Nr   c              3  B   K   | ]}                     |          V  d S rJ   _handle_staterD   rE   r9   s     r:   	<genexpr>z:RegexFactory.__init__.<locals>.<lambda>.<locals>.<genexpr>`   s1      'a'a!(:(:1(=(='a'a'a'a'a'ar<   rG   )joinr3   r4   r7   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>`   s?    'a'a'a'at|GZGZ[\]^[_G`G`'a'a'a a a r<   c                R    d                     fd| d         D                       S )Nr   c              3  B   K   | ]}                     |          V  d S rJ   rP   rR   s     r:   rS   z:RegexFactory.__init__.<locals>.<lambda>.<locals>.<genexpr>b   s1      'L'L!(:(:1(=(='L'L'L'L'L'Lr<   rG   rT   r7   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>b   s,    'L'L'L'Lqt'L'L'L L L r<   c                    dS r2   r>   r?   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>c   s    B r<   c                    j         |          S rJ   )_cacher7   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>d   s    $+a. r<   c                     j         |  S rJ   _handle_repeatr7   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>e       $7D$7$; r<   c                     j         |  S rJ   r\   r7   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>f   r^   r<   c                    dgS )NFr>   r?   s    r:   r;   z'RegexFactory.__init__.<locals>.<lambda>g   s     r<   )literalnot_literalatinanyrH   categorybranch
subpatternassert
assert_notgroupref
min_repeat
max_repeatnegateN)_limitrZ   r3   r6   
_handle_in_handle_group_cases)r9   r+   r,   s   `  r:   __init__zRegexFactory.__init__R   s    &( WWWW,/MMMMFF==aaaa,LLLL&,0000;;;;;;;;''
 
r<   string_or_regexstr | PatternrL   c                    t          |t                    r|j        n|}t          |          }|                     |          }| j                                         |S )zGenerate a string matching a regex.

        :param string_or_regex: A string or pattern.

        :return: The generated string.
        )
isinstancer   patternr   _build_stringrZ   clear)r9   rt   rx   parsedresults        r:   __call__zRegexFactory.__call__j   sX     .8-Q-Qf/))Wfw##F++r<   r{   r   c                F     d                      fd|D                       S )Nr   c                :    g | ]}                     |          S r>   rP   )rD   stater9   s     r:   rF   z.RegexFactory._build_string.<locals>.<listcomp>x   s'    FFFe**511FFFr<   rW   )r9   r{   s   ` r:   ry   zRegexFactory._build_stringw   s*    wwFFFFvFFFGGGr<   r   "tuple[SubPattern, tuple[Any, ...]]r   c                v    |\  }} | j         t          |                                                   |          S rJ   )rr   rL   rM   )r9   r   opcodevalues       r:   rQ   zRegexFactory._handle_statez   s4    /t{3v;;,,../666r<   r   tuple[Any, ...]c                     d                      fd|d         D                       }|d         r| j        |d         <   |S )Nr   c              3  B   K   | ]}                     |          V  d S rJ   rP   rR   s     r:   rS   z-RegexFactory._handle_group.<locals>.<genexpr>   s1      AA1++A..AAAAAAr<      r   )rT   rZ   )r9   r   r|   s   `  r:   rq   zRegexFactory._handle_group~   sN    AAAAaAAAAA8 	+$*DKa!r<   c                @    t          t           fd|D                        }|r`|d         du rVt          t          t                                        |dd                              } j                            |          S  j                            |          S )Nc              3  B   K   | ]}                     |          V  d S rJ   rP   rR   s     r:   rS   z*RegexFactory._handle_in.<locals>.<genexpr>   s1      !G!GA$"4"4Q"7"7!G!G!G!G!G!Gr<   r   FrG   )listr   setr	   
differencer3   r4   )r9   r   
candidatess   `  r:   rp   zRegexFactory._handle_in   s    %!G!G!G!G!G!G!GHII
 	3*Q-500c)nn77
122GGHHJ<&&z222|"":...r<   start_range	end_rangec           
          t          | j                  } fdt           j                            |t          ||                              D             }d                    |          S )Nc                R    g | ]#}d                      fdD                       $S )r   c              3  B   K   | ]}                     |          V  d S rJ   rP   )rD   vr9   s     r:   rS   z9RegexFactory._handle_repeat.<locals>.<listcomp>.<genexpr>   s1      99aD&&q))999999r<   rW   )rD   r   r9   r   s     r:   rF   z/RegexFactory._handle_repeat.<locals>.<listcomp>   sJ     
 
 
 GG9999599999
 
 
r<   r   )minro   rH   r3   randintmaxrT   )r9   r   r   r   r|   s   `  ` r:   r]   zRegexFactory._handle_repeat   sx    	4;//	
 
 
 
 
4<//Si=X=XYYZZ
 
 
 wwvr<   N)r*   )r+   r   r,   r-   r.   r/   )rt   ru   r.   rL   )r{   r   r.   rL   )r   r   r.   r   )r   r   r.   rL   )r   r   r.   r   )r   r-   r   r   r   r   r.   rL   )__name__
__module____qualname____doc__rs   r}   ry   rQ   rq   rp   r]   r>   r<   r:   r)   r)   O   s        
 
 
 
 
0   H H H H7 7 7 7   / / / /     r<   r)   N)r   
__future__r   	itertoolsr   stringr   r   r   r   r	   r
   r   typingr   r   r   
re._parserr   r   ImportError	sre_parser+   r   striprT   r   r   
_alphabetsrK   r)   r>   r<   r:   <module>r      s   @ # " " " " "       n n n n n n n n n n n n n n n n n n . . . . . . . . . .,,,,,,,,,              }  	
 f ; , &;& * _Y_&& mf$s* MF"S( rwwss9~~001G#1MNNOO -&(72 }v%.  -&(3.!
( !*$[1 .$_5'#I. C C C C C C C C C Cs   5 AA