o
    0=jD  ã                   @   sr   d Z ddlZddlZddlmZ dd„ ZG dd„ dƒZG dd	„ d	ƒZG d
d„ dƒZG dd„ dƒZ	G dd„ dƒZ
dS )z Firebase user import sub module.é    N)Ú_auth_utilsc                 C   s   t  | ¡ ¡ S ©N)Úbase64Úurlsafe_b64encodeÚdecode)Zbytes_value© r   úeC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\firebase_admin/_user_import.pyÚ
b64_encode   s   r	   c                   @   s¤   e Zd ZdZddd„Zedd„ ƒZejdd„ ƒZedd	„ ƒZejd
d	„ ƒZedd„ ƒZ	e	jdd„ ƒZ	edd„ ƒZ
e
jdd„ ƒZ
edd„ ƒZejdd„ ƒZdd„ ZdS )ÚUserProvideraD  Represents a user identity provider that can be associated with a Firebase user.

    One or more providers can be specified in an ``ImportUserRecord`` when importing users via
    ``auth.import_users()``.

    Args:
        uid: User's unique ID assigned by the identity provider.
        provider_id: ID of the identity provider. This can be a short domain name or the identifier
            of an OpenID identity provider.
        email: User's email address (optional).
        display_name: User's display name (optional).
        photo_url: User's photo URL (optional).
    Nc                 C   s"   || _ || _|| _|| _|| _d S r   )ÚuidÚprovider_idÚemailÚdisplay_nameÚ	photo_url)Úselfr   r   r   r   r   r   r   r   Ú__init__*   s
   
zUserProvider.__init__c                 C   ó   | j S r   ©Ú_uid©r   r   r   r   r   1   ó   zUserProvider.uidc                 C   ó   t j|dd�| _d S ©NT©Úrequired©r   Zvalidate_uidr   ©r   r   r   r   r   r   5   ó   c                 C   r   r   )Ú_provider_idr   r   r   r   r   9   r   zUserProvider.provider_idc                 C   r   r   )r   Zvalidate_provider_idr   )r   r   r   r   r   r   =   r   c                 C   r   r   ©Ú_emailr   r   r   r   r   A   r   zUserProvider.emailc                 C   ó   t  |¡| _d S r   ©r   Zvalidate_emailr    ©r   r   r   r   r   r   E   ó   c                 C   r   r   ©Ú_display_namer   r   r   r   r   I   r   zUserProvider.display_namec                 C   r!   r   ©r   Zvalidate_display_namer&   ©r   r   r   r   r   r   M   r$   c                 C   r   r   ©Ú
_photo_urlr   r   r   r   r   Q   r   zUserProvider.photo_urlc                 C   r!   r   ©r   Zvalidate_photo_urlr*   ©r   r   r   r   r   r   U   r$   c                 C   s,   | j | j| j| j| jdœ}dd„ | ¡ D ƒS )N)ZrawIdZ
providerIdÚdisplayNamer   ÚphotoUrlc                 S   ó   i | ]\}}|d ur||“qS r   r   ©Ú.0ÚkÚvr   r   r   Ú
<dictcomp>a   ó    z(UserProvider.to_dict.<locals>.<dictcomp>)r   r   r   r   r   Úitems©r   Úpayloadr   r   r   Úto_dictY   s   ûzUserProvider.to_dict)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   Úsetterr   r   r   r   r9   r   r   r   r   r
      s0    










r
   c                   @   s,  e Zd ZdZ			d%dd„Zedd„ ƒZejdd„ ƒZedd	„ ƒZejd
d	„ ƒZedd„ ƒZ	e	jdd„ ƒZ	edd„ ƒZ
e
jdd„ ƒZ
edd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZed d!„ ƒZejd"d!„ ƒZd#d$„ ZdS )&ÚImportUserRecordar  Represents a user account to be imported to Firebase Auth.

    Must specify the ``uid`` field at a minimum. A sequence of ``ImportUserRecord`` objects can be
    passed to the ``auth.import_users()`` function, in order to import those users into Firebase
    Auth in bulk. If the ``password_hash`` is set on a user, a hash configuration must be
    specified when calling ``import_users()``.

    Args:
        uid: User's unique ID. Must be a non-empty string not longer than 128 characters.
        email: User's email address (optional).
        email_verified: A boolean indicating whether the user's email has been verified (optional).
        display_name: User's display name (optional).
        phone_number: User's phone number (optional).
        photo_url: User's photo URL (optional).
        disabled: A boolean indicating whether this user account has been disabled (optional).
        user_metadata: An ``auth.UserMetadata`` instance with additional user metadata (optional).
        provider_data: A list of ``auth.UserProvider`` instances (optional).
        custom_claims: A ``dict`` of custom claims to be set on the user account (optional).
        password_hash: User's password hash as a ``bytes`` sequence (optional).
        password_salt: User's password salt as a ``bytes`` sequence (optional).

    Raises:
        ValueError: If provided arguments are invalid.
    Nc                 C   sL   || _ || _|| _|| _|| _|| _|| _|| _|| _|| _	|	| _
|
| _d S r   )r   r   r   Úphone_numberr   Úpassword_hashÚpassword_saltÚemail_verifiedÚdisabledÚuser_metadataÚprovider_dataÚcustom_claims)r   r   r   rD   r   rA   r   rE   rF   rG   rH   rB   rC   r   r   r   r   ~   s   
zImportUserRecord.__init__c                 C   r   r   r   r   r   r   r   r   Ž   r   zImportUserRecord.uidc                 C   r   r   r   r   r   r   r   r   ’   r   c                 C   r   r   r   r   r   r   r   r   –   r   zImportUserRecord.emailc                 C   r!   r   r"   r#   r   r   r   r   š   r$   c                 C   r   r   r%   r   r   r   r   r   ž   r   zImportUserRecord.display_namec                 C   r!   r   r'   r(   r   r   r   r   ¢   r$   c                 C   r   r   )Ú_phone_numberr   r   r   r   rA   ¦   r   zImportUserRecord.phone_numberc                 C   r!   r   )r   Zvalidate_phonerI   )r   rA   r   r   r   rA   ª   r$   c                 C   r   r   r)   r   r   r   r   r   ®   r   zImportUserRecord.photo_urlc                 C   r!   r   r+   r,   r   r   r   r   ²   r$   c                 C   r   r   )Ú_password_hashr   r   r   r   rB   ¶   r   zImportUserRecord.password_hashc                 C   ó   t  |d¡| _d S )NrB   )r   Úvalidate_bytesrJ   )r   rB   r   r   r   rB   º   ó   c                 C   r   r   )Ú_password_saltr   r   r   r   rC   ¾   r   zImportUserRecord.password_saltc                 C   rK   )NrC   )r   rL   rN   )r   rC   r   r   r   rC   Â   rM   c                 C   r   r   )Ú_user_metadatar   r   r   r   rF   Æ   r   zImportUserRecord.user_metadatac                 C   sJ   |d ur|j nd }|d ur|jnd }t |d¡| _t |d¡| _|| _d S )NÚcreation_timestampÚlast_sign_in_timestamp)rP   rQ   r   Zvalidate_timestampÚ_created_atÚ_last_login_atrO   )r   rF   Z
created_atZlast_login_atr   r   r   rF   Ê   s   ÿ
c                 C   r   r   )Ú_provider_datar   r   r   r   rG   Ó   r   zImportUserRecord.provider_datac              
   C   sT   |d ur%zt dd„ |D ƒƒrtdƒ‚W n ty$ } ztdƒ|‚d }~ww || _d S )Nc                 s   s   � | ]	}t |tƒ V  qd S r   )Ú
isinstancer
   ©r1   Úpr   r   r   Ú	<genexpr>Û   s   € z1ImportUserRecord.provider_data.<locals>.<genexpr>z0One or more provider data instances are invalid.zprovider_data must be iterable.)ÚanyÚ
ValueErrorÚ	TypeErrorrT   )r   rG   Úerrr   r   r   rG   ×   s   ÿ
€ÿ
c                 C   r   r   )Ú_custom_claimsr   r   r   r   rH   á   r   zImportUserRecord.custom_claimsc                 C   s.   t |tƒr
t |¡n|}t |¡| _|| _d S r   )rU   ÚdictÚjsonÚdumpsr   Zvalidate_custom_claimsÚ_custom_claims_strr]   )r   rH   Zjson_claimsr   r   r   rH   å   s   ÿÿ
c                 C   s¢   | j | j| j| j| j| jdurt| jƒnd| jdurt| jƒnd| j| j	| j
| jr.t| jƒnd| jr7t| jƒnddœ}| jrHdd„ | jD ƒ|d< dd„ | ¡ D ƒS )zAReturns a dict representation of the user. For internal use only.N)ZlocalIdr   r-   ZphoneNumberr.   ZemailVerifiedrE   ZcustomAttributesZ	createdAtZlastLoginAtZpasswordHashZsaltc                 S   s   g | ]}|  ¡ ‘qS r   )r9   rV   r   r   r   Ú
<listcomp>þ   ó    z,ImportUserRecord.to_dict.<locals>.<listcomp>ZproviderUserInfoc                 S   r/   r   r   r0   r   r   r   r4   ÿ   r5   z,ImportUserRecord.to_dict.<locals>.<dictcomp>)r   r   r   rA   r   rD   ÚboolrE   ra   rR   rS   rB   r	   rC   rG   r6   r7   r   r   r   r9   ì   s$   ÿózImportUserRecord.to_dict)NNNNNNNNNNN)r:   r;   r<   r=   r   r>   r   r?   r   r   rA   r   rB   rC   rF   rG   rH   r9   r   r   r   r   r@   d   s^    
þ

















	

r@   c                   @   sÌ   e Zd ZdZd#dd„Zdd„ Zedd„ ƒZed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed#dd„ƒZedd „ ƒZed!d"„ ƒZdS )$ÚUserImportHasha‰  Represents a hash algorithm used to hash user passwords.

    An instance of this class must be specified when importing users with passwords via the
    ``auth.import_users()`` API. Use one of the provided class methods to obtain new
    instances when required. Refer to `documentation`_ for more details.

    .. _documentation: https://firebase.google.com/docs/auth/admin/import-users
    Nc                 C   s   || _ || _d S r   )Ú_nameÚ_data)r   ÚnameÚdatar   r   r   r     s   
zUserImportHash.__init__c                 C   s    d| j i}| jr| | j¡ |S )NZhashAlgorithm)rf   rg   Úupdater7   r   r   r   r9     s   
zUserImportHash.to_dictc                 C   s"   dt tj|ddd�ƒi}t||ƒS )NÚ	signerKeyÚkeyTr   )r	   r   rL   re   )Úclsrh   rl   ri   r   r   r   Ú_hmac  s   ÿ
zUserImportHash._hmacc                 C   ó   |   d|¡S )z½Creates a new HMAC SHA512 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ZHMAC_SHA512N©rn   ©rm   rl   r   r   r   Úhmac_sha512  ó   
zUserImportHash.hmac_sha512c                 C   ro   )z½Creates a new HMAC SHA256 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ZHMAC_SHA256Nrp   rq   r   r   r   Úhmac_sha256)  rs   zUserImportHash.hmac_sha256c                 C   ro   )z»Creates a new HMAC SHA1 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        Z	HMAC_SHA1Nrp   rq   r   r   r   Ú	hmac_sha15  rs   zUserImportHash.hmac_sha1c                 C   ro   )zºCreates a new HMAC MD5 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ZHMAC_MD5Nrp   rq   r   r   r   Úhmac_md5A  rs   zUserImportHash.hmac_md5c              	   C   ó   t ddt |ddd¡iƒS )zÒCreates a new MD5 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚMD5Úroundsr   é    N©re   r   Úvalidate_int©rm   ry   r   r   r   Úmd5M  ó   
þzUserImportHash.md5c              	   C   rw   )zÓCreates a new SHA1 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚSHA1ry   é   rz   Nr{   r}   r   r   r   Úsha1[  r   zUserImportHash.sha1c              	   C   rw   )zÕCreates a new SHA256 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚSHA256ry   r�   rz   Nr{   r}   r   r   r   Úsha256i  r   zUserImportHash.sha256c              	   C   rw   )zÕCreates a new SHA512 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ÚSHA512ry   r�   rz   Nr{   r}   r   r   r   Úsha512w  r   zUserImportHash.sha512c              	   C   rw   )zÛCreates a new PBKDF SHA1 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 120000.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        Z
PBKDF_SHA1ry   r   éÀÔ Nr{   r}   r   r   r   Ú
pbkdf_sha1…  r   zUserImportHash.pbkdf_sha1c              	   C   rw   )zÞCreates a new PBKDF2 SHA256 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 120000.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ZPBKDF2_SHA256ry   r   r‡   Nr{   r}   r   r   r   Úpbkdf2_sha256“  r   zUserImportHash.pbkdf2_sha256c                 C   sV   t tj|ddd�ƒt |ddd¡t |ddd¡d	œ}|r&t t |d
¡ƒ|d< td|ƒS )a$  Creates a new Scrypt algorithm instance.

        This is the modified Scrypt algorithm used by Firebase Auth. See ``standard_scrypt()``
        function for the standard Scrypt algorith,

        Args:
            key: Signer key as a byte sequence.
            rounds: Number of rounds. Must be an integer between 1 and 8.
            memory_cost: Memory cost as an integer between 1 and 14.
            salt_separator: Salt separator as a byte sequence (optional).

        Returns:
            UserImportHash: A new ``UserImportHash``.
        rl   Tr   ry   r�   é   Úmemory_costé   )rk   ry   Z
memoryCostÚsalt_separatorZsaltSeparatorZSCRYPTN)r	   r   rL   r|   re   )rm   rl   ry   r‹   r�   ri   r   r   r   Úscrypt¡  s   ý
ÿ
zUserImportHash.scryptc                 C   s   t dƒS )zyCreates a new Bcrypt algorithm instance.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        ZBCRYPTN)re   )rm   r   r   r   Úbcrypt»  s   zUserImportHash.bcryptc                 C   sH   t j|ddd�t j|ddd�t j|ddd�t j|ddd�dœ}td|ƒS )
a©  Creates a new standard Scrypt algorithm instance.

        Args:
            memory_cost: CPU Memory cost as a non-negative integer.
            parallelization: Parallelization as a non-negative integer.
            block_size: Block size as a non-negative integer.
            derived_key_length: Derived key length as a non-negative integer.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        r‹   r   )ÚlowÚparallelizationÚ
block_sizeÚderived_key_length)Z
cpuMemCostr‘   Z	blockSizeZdkLenZSTANDARD_SCRYPTN)r   r|   re   )rm   r‹   r‘   r’   r“   ri   r   r   r   Ústandard_scryptÄ  s   ü
zUserImportHash.standard_scryptr   )r:   r;   r<   r=   r   r9   Úclassmethodrn   rr   rt   ru   rv   r~   r‚   r„   r†   rˆ   r‰   rŽ   r�   r”   r   r   r   r   re     s@    
	











re   c                   @   s0   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdS )	Ú	ErrorInfoz‡Represents an error encountered while performing a batch operation such
    as importing users or deleting multiple user accounts.
    c                 C   s   |d | _ |d | _d S )NÚindexÚmessage)Ú_indexÚ_reason)r   Úerrorr   r   r   r   â  s   
zErrorInfo.__init__c                 C   r   r   )r™   r   r   r   r   r—   æ  r   zErrorInfo.indexc                 C   r   r   )rš   r   r   r   r   Úreasonê  r   zErrorInfo.reasonN)r:   r;   r<   r=   r   r>   r—   rœ   r   r   r   r   r–   Ú  s    
r–   c                   @   s<   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZd
S )ÚUserImportResultzrRepresents the result of a bulk user import operation.

    See ``auth.import_users()`` API for more details.
    c                 C   s8   |  dg ¡}|t|ƒ | _t|ƒ| _dd„ |D ƒ| _d S )Nr›   c                 S   s   g | ]}t |ƒ‘qS r   )r–   )r1   r\   r   r   r   rb   ù  rc   z-UserImportResult.__init__.<locals>.<listcomp>)ÚgetÚlenÚ_success_countÚ_failure_countÚ_errors)r   ÚresultÚtotalÚerrorsr   r   r   r   õ  s   
zUserImportResult.__init__c                 C   r   )z2Returns the number of users successfully imported.N)r    r   r   r   r   Úsuccess_countû  ó   zUserImportResult.success_countc                 C   r   )z7Returns the number of users that failed to be imported.N)r¡   r   r   r   r   Úfailure_count   r§   zUserImportResult.failure_countc                 C   r   )zQReturns a list of ``auth.ErrorInfo`` instances describing the errors encountered.N)r¢   r   r   r   r   r¥     r§   zUserImportResult.errorsN)	r:   r;   r<   r=   r   r>   r¦   r¨   r¥   r   r   r   r   r�   ï  s    

r�   )r=   r   r_   Zfirebase_adminr   r	   r
   r@   re   r–   r�   r   r   r   r   Ú<module>   s   I  Y