
    =h                    6   d Z ddlmZ 	 ddlZddlmZmZmZ dZ	 dd	l	m
Z
mZ  ed       ddlmZmZmZmZmZ ddlZddlmZ ddlmZ ddlmZmZ erddlmZ ddlmZ ddlmZ  G d de      Z ddZ!y# e$ r  G d d      ZdZY nw xY w# e$ r dd
Z
Y lw xY w)z#MONGODB-AWS Authentication helpers.    )annotationsN)AwsCredentialAwsSaslContextPyMongoAuthAwsErrorTc                      e Zd ZddZy)r   c                     y N )selfcredentialss     `/var/www/html/phonemate/phone_mate_backend/venv/lib/python3.12/site-packages/pymongo/auth_aws.py__init__zAwsSaslContext.__init__   s        N)r   MongoCredential)__name__
__module____qualname__r   r
   r   r   r   r      s    	r   r   F)set_cached_credentialsset_use_cached_credentialsc                     y r	   r
   )_credss    r   r   r   &   s    r   )TYPE_CHECKINGAnyMappingOptionalTypeBinary)SON)ConfigurationErrorOperationFailure)_ReadableBuffer)r   )
Connectionc                  $    e Zd ZddZddZddZy)_AwsSaslContextc                    t         S )z#Return the bson.binary.Binary type.r   )r   s    r   binary_typez_AwsSaslContext.binary_type9   s    r   c                ,    t        j                  |      S )zEncode a dictionary to BSON.)bsonencode)r   docs     r   bson_encodez_AwsSaslContext.bson_encode=   s    {{3r   c                ,    t        j                  |      S )zDecode BSON to a dictionary.)r)   decode)r   datas     r   bson_decodez_AwsSaslContext.bson_decodeA   s    {{4  r   N)returnzType[Binary])r+   Mapping[str, Any]r1   bytes)r/   r"   r1   r2   )r   r   r   r'   r,   r0   r
   r   r   r%   r%   7   s     !r   r%   c                   t         st        d      |j                  dk  rt        d      	 t        t	        | j
                  | j                  | j                  j                              }|j                  d      }t        ddd|fg      }|j                  d|      }|}t        d	      D ]D  }|j                  |d         }t        d
d|d   fd|fg      }|j                  d|      }|d   sD y y# t        $ r0}	t        d       t        |	 dt         j"                   d      dd}	~	wt$        $ r t        d        w xY w)zAuthenticate using MONGODB-AWS.zhMONGODB-AWS authentication requires pymongo-auth-aws: install with: python -m pip install 'pymongo[aws]'	   z@MONGODB-AWS authentication requires MongoDB version 4.4 or laterN)	saslStart   )	mechanismzMONGODB-AWSpayloadz	$external
   )saslContinuer7   conversationIddonez (pymongo-auth-aws version ))_HAVE_MONGODB_AWSr    max_wire_versionr%   r   usernamepasswordmechanism_propertiesaws_session_tokenstepr   commandranger   r   r!   pymongo_auth_aws__version__	Exception)
r   connctxclient_payloadclient_firstserver_firstres_cmdexcs
             r   _authenticate_awsrT   F   sh    A
 	

 q  !cdd&$$$$00BB
 $;i=XY
 ||K>rA XXc)n5N'%|4D'EF/C ,,{C0C6{   t$e./?/K/K.LAN
	  t$s$   CC3 /C3 1C3 3	E <+D''E )r   zOptional[AwsCredential]r1   None)r   r   rK   r#   r1   rU   )"__doc__
__future__r   rH   r   r   r   r?   ImportErrorpymongo_auth_aws.authr   r   typingr   r   r   r   r   r)   bson.binaryr   bson.sonr   pymongo.errorsr    r!   bson.typingsr"   pymongo.authr   pymongo.poolr#   r%   rT   r
   r   r   <module>ra      s    * "SSX t$ ? >    ?,,'!n !1_      s"   A5 B 5B	B		BB