HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/faker/__pycache__/proxy.cpython-310.pyc
o

'wec1�@s�ddlZddlZddlZddlmZddlmZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZddlmZddlmZddlmZdd	lmZmZdd
lmZddlmZdZed
�ZGdd�d�ZGdd�d�Z Gdd�d�Z!dS)�N)�OrderedDict)�Random)
�Any�Callable�Dict�List�Optional�Pattern�Sequence�Tuple�TypeVar�Union�)�DEFAULT_LOCALE)�UniquenessException)�Factory)�	Generator�random)�SeedType)�choices_distributioni��RetTypecsVeZdZUdZe�d�Zeed<dd�e	e
�D�Z					dBdee
eeeeee
eefffd	eeed
ee
deeeded
eddfdd�Z�fdd�Zdede
fdd�Zdedef�fdd�Zdedefdd�Zifdeddfdd�Zdeddfdd�ZedCd!d"��ZedDd$d%��Zd&ede fd'd(�Z!d)d*�Z"d+d,�Z#d&ede$ee eeeffd-d.�Z%e&dEd/ee'ddfd0d1��Z(dEd/ee'ddfd2d3�Z)dEded/ee'ddfd4d5�Z*ede+fd6d7��Z,e,j-d8e+ddfd9d7��Z,edeefd:d;��Z.edeee
eeffd<d=��Z/edee
fd>d?��Z0dee$ee
ffd@dA�Z1�Z2S)F�Fakerz2Proxy class capable of supporting multiple localesz^_cached_\w*_mapping$�
cache_patterncCs"g|]
}|�d�s|dvr|�qS)�__)�seed�
seed_instancer��
startswith��.0�attr�r!�D/home/arjun/projects/env/lib/python3.10/site-packages/faker/proxy.py�
<listcomp>s
�zFaker.<listcomp>NT�locale�	providers�	generator�includes�
use_weighting�config�returncKsPt�|_d|_t|�|_t|�|_t|t�r|�	dd�g}ngt|t
ttf�rLg}|D] }t|t�s;t
dt|��d���|�	dd�}	|	|vrJ|�|	�q*n9t|t�r�tdd�|��D��s^J�t�}
|��D]\}}|�	dd�}
||
|
<qet
|
���}t
|
���|_ntg}|D]}tj||||fd|i|��|j|<q�||_t
|j���|_dS)N�-�_zThe locale "z" must be a string.css�|]
}t|ttf�VqdS�N)�
isinstance�int�float)r�vr!r!r"�	<genexpr>:s�z!Faker.__init__.<locals>.<genexpr>r()r�_factory_map�_weights�UniqueProxy�
_unique_proxy�
OptionalProxy�_optional_proxyr.�str�replace�list�tuple�set�	TypeError�append�all�values�items�keysrr�create�_locales�
_factories)�selfr$r%r&r'r(r)�locales�code�final_locale�odict�kr1�keyr!r!r"�__init__sL	




��

���	zFaker.__init__cs<ttt|����}|jD]
}|dd�t|�D�O}qt|�S)NcSsh|]	}|�d�s|�qS)r,rrr!r!r"�	<setcomp>U�z Faker.__dir__.<locals>.<setcomp>)r=�superr�__dir__�	factories�dir�sorted)rG�
attributes�factory��	__class__r!r"rRRs
z
Faker.__dir__cCs|j|�dd�S)Nr+r,)r3r:)rGr$r!r!r"�__getitem__XszFaker.__getitem__r cs |dkr
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
        rzZCalling `.seed()` on instances is deprecated. Use the class method `Faker.seed()` instead.)r>rQ�__getattribute__)rGr �msgrXr!r"r[[s	zFaker.__getattribute__cCsht|j�dkrt|jd|�S||jvrd|}t|��|j�|�r*d|}t|��|�|�}t||�S)z�
        Handles cache access and proxying behavior

        :param attr: attribute name
        :return: the appropriate attribute
        rrzBProxying calls to `%s` is not implemented in multiple locale mode.z$Cached attribute `%s` does not exist)	�lenrF�getattr�generator_attrs�NotImplementedErrorr�match�AttributeError�_select_factory)rGr r\rWr!r!r"�__getattr__js


zFaker.__getattr__�memodictcst|j}|�|��t�|j��_t�|j��_t�|j��_t�|j��_t|��_	�fdd�|j	j
��D��j	_
�S)Ncsi|]}|�jjh�qSr!)r6�	_sentinel)rrL��resultr!r"�
<dictcomp>�sz&Faker.__deepcopy__.<locals>.<dictcomp>)rY�__new__�copy�deepcopyrErFr3r4r5r6�_seenrC)rGre�clsr!rgr"�__deepcopy__}s

zFaker.__deepcopy__�statecC�|j�|�dSr-��__dict__�update�rGrpr!r!r"�__setstate__��zFaker.__setstate__r5cC�|jSr-)r6�rGr!r!r"�unique��zFaker.uniquer7cCrxr-)r8ryr!r!r"�optional�r{zFaker.optional�method_namecCsb|�|�\}}t|�dkrd|��}t|��t|�dkr |dS|r*|�||�}|S|�|�}|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
        rz"No generator object has attribute r)�_map_provider_methodr]rb�_select_factory_distribution�_select_factory_choice)rGr}rS�weightsr\rWr!r!r"rc�s

�zFaker._select_factorycCst||tdd�dS)Nr)�lengthr)rr)rGrSr�r!r!r"r�sz"Faker._select_factory_distributioncCs
t�|�Sr-)r�choice)rGrSr!r!r"r���
zFaker._select_factory_choicecs�d��d�}t||�rt||�S|jr0�fdd�t|j|j�D�}t|�\}}t|�t|�f}n�fdd�|jD�}|df}t|||�|S)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_�_mappingcs"g|]
\}}t|��r||f�qSr!��hasattr)rrW�weight�r}r!r"r#�s��z.Faker._map_provider_method.<locals>.<listcomp>csg|]	}t|��r|�qSr!r�)rrWr�r!r"r#�rPN)r�r^r4�ziprSr;�setattr)rGr}r �valuerSr��mappingr!r�r"r~�s


�zFaker._map_provider_methodrcCst�|�dS)zs
        Hashables the shared `random.Random` object across all factories

        :param seed: seed value
        N)rr)rnrr!r!r"r�sz
Faker.seedcCs|jD]}|�|�qdS)zr
        Creates and seeds a new `random.Random` object for each factory

        :param seed: seed value
        N)rFr)rGrrWr!r!r"r�s
�zFaker.seed_instancecCs|j|�dd��|�dS)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)r3r:r)rGr$rr!r!r"�seed_locale�szFaker.seed_localecCs&t|j�dkr
|jdjSd}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.
        rrzJProxying `random` getter calls is not implemented in multiple locale mode.�r]rFrr`)rGr\r!r!r"r�s
zFaker.randomr�cCs*t|j�dkr||jd_dSd}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.
        rrzJProxying `random` setter calls is not implemented in multiple locale mode.Nr�)rGr�r\r!r!r"r�s
cCs
t|j�Sr-)r;rEryr!r!r"rHs
z
Faker.localescCrxr-)r4ryr!r!r"r�r{z
Faker.weightscCrxr-)rFryr!r!r"rSr{zFaker.factoriescCst|j���Sr-)r;r3rBryr!r!r"rBszFaker.items)NNNNT)r*r5)r*r7r-)3�__name__�
__module__�__qualname__�__doc__�re�compilerr	�__annotations__rTrr_rr
r9r
rr/r0r�boolrrNrRrZr[rdrorv�propertyrzr|rrcrr�rr~�classmethodrrrr�rr�setterrHr�rSrB�
__classcell__r!r!rXr"rsn
��$�
��
���
�5&!		 "rc@s\eZdZdefdd�Zddd�Zdedefd	d
�Zdd�Z	d
d�Z
dededefdd�ZdS)r5�proxycCs||_i|_t�|_dSr-)�_proxyrm�objectrf�rGr�r!r!r"rNszUniqueProxy.__init__r*NcCs
i|_dSr-)rmryr!r!r"�clear!r�zUniqueProxy.clear�namecC�(t|j|�}t|�r|�||�Std��)Nz9Accessing non-functions through .unique is not supported.�r^r��callable�_wrapr>�rGr��objr!r!r"rd$�zUniqueProxy.__getattr__cC�|j��}|Sr-�rsrkrur!r!r"�__getstate__+�
zUniqueProxy.__getstate__cCrqr-rrrur!r!r"rv2rwzUniqueProxy.__setstate__�functioncst������fdd��}|S)Ncsv�|tt|����f}�j�|�jh�}�j}tt�D]}||vr#n�|i|��}qtdtd�d���|�	|�|S)NzGot duplicated values after �,z iterations.)
r<rUrBrm�
setdefaultrf�range�_UNIQUE_ATTEMPTSr�add)�args�kwargsrM�	generated�retval�i�r�r�rGr!r"�wrapper6s
z"UniqueProxy._wrap.<locals>.wrapper)�	functools�wraps�rGr�r�r�r!r�r"r�5szUniqueProxy._wrap)r*N)
r�r�r�rrNr�r9rrdr�rvrr�r!r!r!r"r5s
r5c	@sjeZdZdZdefdd�Zdedefdd�Zd	d
�Z	dd�Z
ded
edefdede
effdd�ZdS)r7zN
    Return either a fake value or None, with a customizable probability.
    r�cCs
||_dSr-)r�r�r!r!r"rNSr�zOptionalProxy.__init__r�r*cCr�)Nz;Accessing non-functions through .optional is not supported.r�r�r!r!r"rdVr�zOptionalProxy.__getattr__cCr�r-r�rur!r!r"r�]r�zOptionalProxy.__getstate__cCrqr-rrrur!r!r"rvdrwzOptionalProxy.__setstate__r�.cs8t���dd�dtdtdtdttf��fdd��}|S)	Ng�?)�probr�r�r�r*csLd|kr
dkstd��td���jjt|d�d�r$�|i|��SdS)Nrg�?zprob must be between 0 and 1�d)�chance_of_getting_true)�
ValueErrorr��booleanr/)r�r�r��r�rGr!r"r�hs
�(z$OptionalProxy._wrap.<locals>.wrapper)r�r�rr0rrr�r!r�r"r�gs,zOptionalProxy._wrapN)r�r�r�r�rrNr9rrdr�rvrrrr�r!r!r!r"r7Ns.r7)"rkr�r��collectionsrrr�typingrrrrrr	r
rrr
r)r�
exceptionsrrWrr&rr�utils.distributionrr�rrr5r7r!r!r!r"�<module>s&03