
    1~hD3                        d dl m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
mZmZmZm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 ddlmZ dZ ed      Z G d d      Z G d d      Z G d d      Zy)    )annotationsN)OrderedDict)Random)AnyCallablePatternSequenceTypeVar   )DEFAULT_LOCALE)UniquenessException)Factory)	Generatorrandom)SeedType)choices_distributioni  RetTypec                     e Zd ZU dZ ej
                  d      Zded<    ee	      D  cg c]  }|j                  d      r|dvs| c}} Z	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZfdZdd	Zd fd
Zd dZd Zd!dZed"d       Zed#d       Zd$dZd Zd Zd%dZed&d'd       Zd&d'dZd&d(dZed)d       Zej>                  d*d       Zed+d       Z ed,d       Z!ed-d       Z"d.dZ#xZ$S c c}} w )/Fakerz2Proxy class capable of supporting multiple localesz^_cached_\w*_mapping$r   cache_pattern__)seedseed_instancer   c                &   t               | _        d | _        t        |       | _        t        |       | _        t        |t              r|j                  dd      g}n%t        |t        t        t        f      rZg }|D ]R  }t        |t              st        dt        |       d      |j                  dd      }	|	|vsB|j                  |	       T nt        |t         t        f      rt!        d |j#                         D              sJ t               }
|j%                         D ]  \  }}|j                  dd      }||
|<    t        |
j'                               }t        |
j#                               | _        nt(        g}t+        |      dk(  r/t-        j.                  |d   |||fd|i|| j                  |d   <   n%|D ]   }t1        ||||fd|i|| j                  |<   " || _        t        | j                  j#                               | _        y )	N-_zThe locale "z" must be a string.c              3  H   K   | ]  }t        |t        t        f        y wN)
isinstanceintfloat).0vs     T/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/faker/proxy.py	<genexpr>z!Faker.__init__.<locals>.<genexpr><   s     Lqz!c5\2Ls    "r   r   use_weighting)r   _factory_map_weightsUniqueProxy_unique_proxyOptionalProxy_optional_proxyr   strreplacelisttupleset	TypeErrorappenddictallvaluesitemskeysr   lenr   creater   _locales
_factories)selflocale	providers	generatorincludesr&   configlocalescodefinal_localeodictkr#   keys                 r$   __init__zFaker.__init__   s    BM(.,T2fc"~~c3/0G uc 23G 1!$,#l3t9+=P$QRR#||C5w.NN<01 d 34LFMMOLLLLME 1iiS)c
 5::<(G 0DM &&Gw<1,3NN
	-
 ,- -Dgaj) " ,1	-
 #0- -!!&)  t00779:    c                    t        t        | 	               }| j                  D ]0  }|t	        |      D ch c]  }|j                  d      r| c}z  }2 t        |      S c c}w )Nr   )r1   super__dir__	factoriesdir
startswithsorted)r=   
attributesfactoryattr	__class__s       r$   rM   zFaker.__dir__^   s_    *+
~~ 	VGCLUDPS@T4UUJ	Vj!! Vs   A#A#c                    |j                  dd      | j                  v rt        | j                        dk(  r| S | j                  |j                  dd         }t	        |t
              sJ |S )Nr   r   r   )r.   rC   r9   r'   r   r   )r=   r>   instances      r$   __getitem__zFaker.__getitem__d   s^    >>#s#t||3DLL8IQ8NK$$V^^C%=>(E***rJ   c                F    |dk(  rd}t        |      t        | 	  |      S )z
        Handles the "attribute resolution" behavior for declared members of this proxy class

        The class method `seed` cannot be called from an instance.

        :param attr: attribute name
        :return: the appropriate attribute
        r   zZCalling `.seed()` on instances is deprecated. Use the class method `Faker.seed()` instead.)r2   rL   __getattribute__)r=   rT   msgrU   s      r$   rZ   zFaker.__getattribute__k   s+     6>qCC. 7+D11rJ   c                0   t        | j                        dk(  rt        | j                  d   |      S || j                  v rd|z  }t	        |      | j
                  j                  |      rd|z  }t        |      | j                  |      }t        ||      S )z
        Handles cache access and proxying behavior

        :param attr: attribute name
        :return: the appropriate attribute
        r   r   zBProxying calls to `%s` is not implemented in multiple locale mode.z$Cached attribute `%s` does not exist)	r9   r<   getattrgenerator_attrsNotImplementedErrorr   matchAttributeError_select_factory)r=   rT   r[   rS   s       r$   __getattr__zFaker.__getattr__z   s     t1$4??1-t44T)))VY]]C%c**%%d+84?C %%**40G7D))rJ   c                8   | j                   }|j                  |      }t        j                  | j                        |_        t        j                  | j
                        |_        t        j                  | j                        |_        t        j                  | j                        |_        t        |       |_	        | j                  j                  j                         D ci c]  }||j                  j                  h c}|j                  _
        |S c c}w r   )rU   __new__copydeepcopyr;   r<   r'   r(   r)   r*   _seenr8   	_sentinel)r=   memodictclsresultrG   s        r$   __deepcopy__zFaker.__deepcopy__   s    nnS!--6 MM$//:"mmD,=,=>--6*40SWSeSeSkSkSpSpSr%saa&*>*>*H*H)I&I%s" &ts   $Dc                :    | j                   j                  |       y r   __dict__updater=   states     r$   __setstate__zFaker.__setstate__       U#rJ   c                    | j                   S r   )r*   r=   s    r$   uniquezFaker.unique   s    !!!rJ   c                    | j                   S r   )r,   rw   s    r$   optionalzFaker.optional   s    ###rJ   c                    | j                  |      \  }}t        |      dk(  rd|}t        |      t        |      dk(  r|d   S |r| j                  ||      }|S | j	                  |      }|S )z
        Returns a random factory that supports the provider method

        :param method_name: Name of provider method
        :return: A factory that supports the provider method
        r   z"No generator object has attribute r   )_map_provider_methodr9   ra   _select_factory_distribution_select_factory_choice)r=   method_namerN   weightsr[   rS   s         r$   rb   zFaker._select_factory   s     "66{C	7y>Q6{oFC %%^q Q<77	7KG  11)<GrJ   c                .    t        ||t        d      d   S )Nr   )lengthr   )r   r   )r=   rN   r   s      r$   r}   z"Faker._select_factory_distribution   s    #IwqI!LLrJ   c                ,    t        j                  |      S r   )r   choice)r=   rN   s     r$   r~   zFaker._select_factory_choice   s    }}Y''rJ   c                   d| d}t        | |      rt        | |      S | j                  rbt        | j                  | j                        D cg c]  \  }}t        ||      r||f }}}t        | \  }}t        |      t        |      f}n*| j                  D cg c]  }t        ||      s| }}|df}t        | ||       |S c c}}w c c}w )ad  
        Creates a 2-tuple of factories and weights for the given provider method name

        The first element of the tuple contains a list of compatible factories.
        The second element of the tuple contains a list of distribution weights.

        :param method_name: Name of provider method
        :return: 2-tuple (factories, weights)
        _cached__mappingN)hasattrr]   r(   ziprN   r/   setattr)	r=   r   rT   rS   weightvaluerN   r   mappings	            r$   r|   zFaker._map_provider_method   s     +h/44&& == (+4>>4=='I#GV7K0 &!E 
 "%eIw9otG}4G,0NN\gg{>[W\E\TkG 	dG$ ]s   CC-Cc                .    t        j                  |       y)zs
        Hashables the shared `random.Random` object across all factories

        :param seed: seed value
        N)r   r   )rk   r   s     r$   r   z
Faker.seed   s     	trJ   c                H    | j                   D ]  }|j                  |        y)zr
        Creates and seeds a new `random.Random` object for each factory

        :param seed: seed value
        N)r<   r   )r=   r   rS   s      r$   r   zFaker.seed_instance   s%      	(G!!$'	(rJ   c                `    | j                   |j                  dd         j                  |       y)z
        Creates and seeds a new `random.Random` object for the factory of the specified locale

        :param locale: locale string
        :param seed: seed value
        r   r   N)r'   r.   r   )r=   r>   r   s      r$   seed_localezFaker.seed_locale   s(     	&..c23AA$GrJ   c                ~    t        | j                        dk(  r| j                  d   j                  S d}t        |      )a   
        Proxies `random` getter calls

        In single locale mode, this will be proxied to the `random` getter
        of the only internal `Generator` object. Subclasses will have to
        implement desired behavior in multiple locale mode.
        r   r   zJProxying `random` getter calls is not implemented in multiple locale mode.r9   r<   r   r_   )r=   r[   s     r$   r   zFaker.random   s:     t1$??1%,,,^C%c**rJ   c                v    t        | j                        dk(  r|| j                  d   _        yd}t        |      )a   
        Proxies `random` setter calls

        In single locale mode, this will be proxied to the `random` setter
        of the only internal `Generator` object. Subclasses will have to
        implement desired behavior in multiple locale mode.
        r   r   zJProxying `random` setter calls is not implemented in multiple locale mode.Nr   )r=   r   r[   s      r$   r   zFaker.random  s6     t1$(-DOOA%^C%c**rJ   c                ,    t        | j                        S r   )r/   r;   rw   s    r$   rC   zFaker.locales  s    DMM""rJ   c                    | j                   S r   )r(   rw   s    r$   r   zFaker.weights  s    }}rJ   c                    | j                   S r   )r<   rw   s    r$   rN   zFaker.factories#  s    rJ   c                H    t        | j                  j                               S r   )r/   r'   r7   rw   s    r$   r7   zFaker.items'  s    D%%++-..rJ   )NNNNT)r>   z3str | Sequence[str] | dict[str, int | float] | Noner?   list[str] | Noner@   zGenerator | NonerA   r   r&   boolrB   r   returnNone)r>   r-   r   r   )rT   r-   r   r   )rs   r   r   r   )r   r)   )r   r+   )r   r-   r   r   )r   r-   r   z(tuple[list[Factory], list[float] | None]r   )r   SeedType | Noner   r   )r>   r-   r   r   r   r   )r   r   )r   r   r   r   )r   z	list[str])r   zlist[int | float] | None)r   zlist[Generator | Faker])r   z#list[tuple[str, Generator | Faker]])%__name__
__module____qualname____doc__recompiler   __annotations__rO   r   rP   r^   rI   rM   rX   rZ   rc   rm   rt   propertyrx   rz   rb   r}   r~   r|   classmethodr   r   r   r   setterrC   r   rN   r7   __classcell__)r"   rT   rU   s   00@r$   r   r      s   <'RZZ(@AM7AYtt/DUxIxO GK&*&*%)"=;C=; $=; $	=;
 #=; =; =; 
=;~"2*&	$ " " $ $,M(B  (H + + ]]+ + # #    /Ys   C3C3C3r   c                  8    e Zd ZddZd	dZd
dZd Zd ZddZy)r)   c                >    || _         i | _        t               | _        y r   )_proxyrh   objectri   r=   proxys     r$   rI   zUniqueProxy.__init__,  s    
rJ   c                    i | _         y r   )rh   rw   s    r$   clearzUniqueProxy.clear1  s	    
rJ   c                ~    t        | j                  |      }t        |      r| j                  ||      S t	        d      )Nz9Accessing non-functions through .unique is not supported.r]   r   callable_wrapr2   r=   nameobjs      r$   rc   zUniqueProxy.__getattr__4  s6    dkk4(C=::dC((WXXrJ   c                :    | j                   j                         }|S r   rp   rf   rr   s     r$   __getstate__zUniqueProxy.__getstate__;       ""$rJ   c                :    | j                   j                  |       y r   ro   rr   s     r$   rt   zUniqueProxy.__setstate__B  ru   rJ   c                J     t        j                         fd       }|S )Nc                 F   | t        t        |j                                     f}j                  j	                  |j
                  h      }j
                  }t        t              D ]  }||vr n | i |} t        dt        dd      |j                  |       |S )NzGot duplicated values after ,z iterations.)
r0   rQ   r7   rh   
setdefaultri   range_UNIQUE_ATTEMPTSr   add)	argskwargsrH   	generatedretvalifunctionr   r=   s	         r$   wrapperz"UniqueProxy._wrap.<locals>.wrapperF  s    uVFLLN%;<=C

--cDNN3CDI ^^F+, k*!4262k
 *,HIYZ[H\\h*ijjMM&!MrJ   	functoolswrapsr=   r   r   r   s   ``` r$   r   zUniqueProxy._wrapE  s%    		"	 
#	( rJ   Nr   r   )r   r   r   r-   r   r   )r   r-   r   r   r   r   )	r   r   r   rI   r   rc   r   rt   r    rJ   r$   r)   r)   +  s!    "
Y$rJ   r)   c                  4    e Zd ZdZddZd	dZd Zd Zd
dZy)r+   zN
    Return either a fake value or None, with a customizable probability.
    c                    || _         y r   )r   r   s     r$   rI   zOptionalProxy.__init__c  s	    rJ   c                ~    t        | j                  |      }t        |      r| j                  ||      S t	        d      )Nz;Accessing non-functions through .optional is not supported.r   r   s      r$   rc   zOptionalProxy.__getattr__f  s6    dkk4(C=::dC((YZZrJ   c                :    | j                   j                         }|S r   r   rr   s     r$   r   zOptionalProxy.__getstate__m  r   rJ   c                :    | j                   j                  |       y r   ro   rr   s     r$   rt   zOptionalProxy.__setstate__t  ru   rJ   c                N     t        j                        ddd fd       }|S )Ng      ?)probc                    d| cxk  rdk  st        d       t        d      j                  j                  t        | dz              r |i |S d S )Nr   g      ?zprob must be between 0 and 1d   )chance_of_getting_true)
ValueErrorr   booleanr    )r   r   r   r   r=   s      r$   r   z$OptionalProxy._wrap.<locals>.wrapperx  sb    t?s? !?@@ # !?@@040C0C[^_cfi_i[j0C0k8T,V,uquurJ   )r   r   r   r!   r   r   r   zRetType | Noner   r   s   ` ` r$   r   zOptionalProxy._wrapw  s*    		".1 	v 
#	v
 rJ   Nr   r   )r   r-   r   zCallable[..., RetType]r   zCallable[..., RetType | None])	r   r   r   r   rI   rc   r   rt   r   r   rJ   r$   r+   r+   ^  s!    [$rJ   r+   )
__future__r   rf   r   r   collectionsr   r   r   typingr   r   r   r	   r
   rB   r   
exceptionsr   rS   r   r@   r   r   utils.distributionr   r   r   r   r)   r+   r   rJ   r$   <module>r      sa    "   	 #  < < " +  (  4 
)
Q/ Q/h0 0f   rJ   