
    giO!                        U 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
mZ d dlmZ  ej        e          Z ee
          Z ej        d          Zeed<    ej        d	          Zeed
<    ej        d          Zeed<    ej        d          Zeed<   dZdZdZd Z edg d          Z G d d          ZdS )    N)
namedtuple)Pattern)Faker)AVAILABLE_LOCALESDEFAULT_LOCALE)SampleCodeValidatorz1^faker\.providers\.BaseProvider\.(?P<method>\w+)$_base_provider_method_patternz2^faker\.providers\.\w+\.Provider\.(?P<method>\w+)$!_standard_provider_method_patternzS^faker\.providers\.\w+\.(?P<locale>[a-z]{2,3}_[A-Z]{2})\.Provider\.(?P<method>\w+)$_locale_provider_method_patternzZ^:sample(?: size=(?P<size>[1-9][0-9]*))?(?: seed=(?P<seed>[0-9]+))?:(?: ?(?P<kwargs>.*))?$_sample_line_patternzgenerator.{method}({kwargs})zb>>> Faker.seed({seed})
>>> for _ in range({size}):
...     fake.{method}({kwargs})
...
{results}

   Sample)sizeseedkwargsc                   z    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zed             Zed             ZdS )ProviderMethodDocstringam  
    Class that preprocesses provider method docstrings to generate sample usage and output

    Notes on how samples are generated:
    - If the docstring belongs to a standard provider method, sample usage and output will be
      generated using a `Faker` object in the `DEFAULT_LOCALE`.
    - If the docstring belongs to a localized provider method, the correct locale will be used.
    - If the docstring does not belong to any provider method, docstring preprocessing will be skipped.
    - Docstring lines will be parsed for potential sample sections, and the generation details of each
      sample section will internally be represented as a ``Sample`` namedtuple.
    - Each ``Sample`` will have info on the keyword arguments to pass to the provider method, how many
      times the provider method will be called, and the initial seed value to ``Faker.seed()``.
    c                    t          |          | _        g | _        g | _        d| _        t          j        |           d| d| _        |dk    rd S t          	                    |          }t          	                    |          }t          	                    |          }	|r.|                                }
|
d         | _        t          | _        nc|	r.|	                                }
|
d         | _        t          | _        n3|r/|                                }
|
d         | _        |
d         | _        nd S d| _        |                                  |                                  d S )NTz:docstring of z
: WARNING:methodlocaleF)iter
_line_iter_parsed_lines_samples_skippedinspectgetfile_log_prefixr	   matchr   r
   	groupdict_methodr   _locale_parse_generate_samples)selfappwhatnameobjoptionslinesbase_provider_method_matchlocale_provider_method_matchstandard_provider_method_matchr    s              n/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/faker/sphinx/docstring.py__init__z ProviderMethodDocstring.__init__3   sU   u++%oc22RR$RRR8F%B%H%H%N%N"'F'L'LT'R'R$)J)P)PQU)V)V&% 	2<<>>I$X.DL)DLL+ 		6@@BBI$X.DL)DLL) 	4>>@@I$X.DL$X.DLLF         c                 N    t                               | j         d|            d S )N )loggerwarningr   )r%   r5   s     r/   _log_warningz$ProviderMethodDocstring._log_warningS   s+    $*66W6677777r1   c                 ~    	 	 t          | j                  }|                     |           n# t          $ r Y d S w xY w=N)nextr   _parse_sectionStopIteration)r%   lines     r/   r#   zProviderMethodDocstring._parseV   s]    	**DO,, ##D)))) !   	*s   - 
;;c                    |                     d          s| j                            |           d S 	 t          | j                  }n&# t
          $ r |                     |           Y d S w xY w|                     d          r,|                     |           |                     |           d S |dk    r|                     |           d S ||z   }|                     |           d S )Nz:sample )
startswithr   appendr9   r   r;   _process_sample_sectionr:   )r%   section	next_lines      r/   r:   z&ProviderMethodDocstring._parse_section_   s   !!),, 	%%g...F	T_--II 	 	 	((111FF	 	** 	)((111	***** "__((11111
 	)G(((((s   A A+*A+c                 ,   t                               |          }|sd| d}|                     |           d S |                                }|                    d          }|                    d          }|                    d          }|r"t          t          |          t                    nt          }|rt          |          nt          }|r| 	                    |          nd}t          |||          }| j                            |           d S )NzThe section `z%` is malformed and will be discarded.r   r   r   r>   )r   r   r6   r    getmaxintDEFAULT_SAMPLE_SIZEDEFAULT_SEED_beautify_kwargsr   r   r@   )	r%   rB   r   msgr    r   r   r   samples	            r/   rA   z/ProviderMethodDocstring._process_sample_section}   s   $**733  	P'PPPCc"""F OO%%	}}V$$}}V$$x((6:Ss3t991222@S 2s4yyyl28@&&v...b dF++V$$$$$r1   c                     d }d }t          j        d||          }t          j        d||          }|                                S )Nc                 b    |                      d          p|                      d          }|r|ndS )N      r>   groupr   quoteds     r/   _repl_whitespacezBProviderMethodDocstring._beautify_kwargs.<locals>._repl_whitespace   s/    [[^^5u{{1~~F#+66+r1   c                 b    |                      d          p|                      d          }|r|ndS )NrO   rP   z, rQ   rS   s     r/   _repl_commaz=ProviderMethodDocstring._beautify_kwargs.<locals>._repl_comma   s/    [[^^5u{{1~~F#-66-r1   z("[^"]*")|(\'[^\']*\')|[ \t]+z("[^"]*")|(\'[^\']*\')|,)resubstrip)r%   r   rU   rW   results        r/   rJ   z(ProviderMethodDocstring._beautify_kwargs   s]    	, 	, 	,	. 	. 	.
 8:JFSS 3[&II ||~~r1   c                      t          |          S r8   )repr)r%   values     r/   _stringify_resultz)ProviderMethodDocstring._stringify_result   s    E{{r1   c                 8    ddl m} t          | j                 |dS )Nr   )OrderedDict)	generatorra   )collectionsra   _faker"   )r%   ra   s     r/   _generate_eval_scopez,ProviderMethodDocstring._generate_eval_scope   s2    ++++++ t|,&
 
 	
r1   c                 p    t          t          t          d          }| j                            |           d S )Nr>   )r   rH   rI   r   r@   )r%   default_samples     r/   _inject_default_sample_sectionz6ProviderMethodDocstring._inject_default_sample_section   s0     3\2FF^,,,,,r1   c           	      6     j         s                                  d}                                  j         D ]%}t                               j        |j                  t                    }|j        r)d j         d|j         d} 	                    |           h	 t          j        |j                   d                     fdt          |j                  D                       }|t                              |j         j        |j        |j        |          z  }# t           $ r, d	 j         d|j         d} 	                    |           Y #w xY w|r4d
|z   } j                            |                    d                     d S d S )Nr>   )r   r   zNInvalid code elements detected. Sample generation will be skipped for method `z` with arguments `z`.
c                 V    g | ]%}                     t                              &S  )r_   eval).0_command
eval_scoper%   s     r/   
<listcomp>z=ProviderMethodDocstring._generate_samples.<locals>.<listcomp>   s2    $s$s$s[\T%;%;D*<U<U%V%V$s$s$sr1   )r   r   r   r   resultsz%Sample generation failed for method `z:examples:

)r   rh   re   _command_templateformatr!   r   r   errorsr6   r   r   joinranger   _sample_output_template	Exceptionr   extendsplit)r%   outputrL   	validatorrK   rs   rp   rq   s   `     @@r/   r$   z)ProviderMethodDocstring._generate_samples   s   } 	2//111..00
m 	 	F'..dl6=.YYG+G44I ]+/<] ]KQ=] ] ]  !!#&&&
6;'''))$s$s$s$s$s$s`eflfq`r`r$s$s$stt 188<!=# 9       odloo^d^kooo!!#&&&  	:%.F%%fll4&8&899999	: 	:s   %AD**2E E c                     | j         S r8   )r   r%   s    r/   skippedzProviderMethodDocstring.skipped   s
    }r1   c                     | j         S r8   )r   r   s    r/   r+   zProviderMethodDocstring.lines   s    !!r1   N)__name__
__module____qualname____doc__r0   r6   r#   r:   rA   rJ   r_   re   rh   r$   propertyr   r+   rl   r1   r/   r   r   $   s         ! ! !@8 8 8* * *) ) )<% % %,  $  
 
 
- - -#: #: #:J   X " " X" " "r1   r   )r   loggingrX   rc   r   typingr   fakerr   faker.configr   r   faker.sphinx.validatorr   	getLoggerr   r4   rd   compiler	   __annotations__r
   r   r   rt   ry   rH   rI   r   r   rl   r1   r/   <module>r      s     				 " " " " " "             : : : : : : : : 6 6 6 6 6 6		8	$	$  )34h)i)i w i i i-7RZ8m-n-n !7 n n n+52:f, ,     !+
q! ! g    3    	H888	9	9{" {" {" {" {" {" {" {" {" {"r1   