ó
    ùÞ jò.  ã                   ó  • S SK r S SKrS SKrS SKJrJr  S SKJr  S SKJrJ	r	J
r
Jr  S SKJrJr  S SKJr  S SKJr  \R&                  " \5      r " S S	5      r " S
 S5      r " S S5      r " S S5      rS rS\ R6                  4S jrg)é    N)ÚdatetimeÚtimezone)Úsleep)ÚAnyÚ	AwaitableÚCallableÚUnion)ÚRequestTokenErrÚTokenRenewalErr)ÚIdentityProviderInterface)ÚTokenResponsec                   ó  • \ rS rSrSrS r\S\\\	/S4   \
4   4S j5       r\R                  S\\\	/S4   \
4   SS4S j5       r\S\\\/S4   \
4   4S	 j5       r\R                  S\\\/S4   \
4   SS4S
 j5       rSrg)ÚCredentialsListeneré   zn
Listeners that will be notified on events related to credentials.
Accepts callbacks and awaitable callbacks.
c                 ó    • S U l         S U l        g ©N)Ú_on_nextÚ	_on_error©Úselfs    ÚR/var/www/html/gaurav/venv/lib/python3.13/site-packages/redis/auth/token_manager.pyÚ__init__ÚCredentialsListener.__init__   s   € ØˆŒØˆ�ó    ÚreturnNc                 ó   • U R                   $ r   ©r   r   s    r   Úon_nextÚCredentialsListener.on_next   s   € à�}‰}Ðr   Úcallbackc                 ó   • Xl         g r   r   ©r   r    s     r   r   r      s   € à �r   c                 ó   • U R                   $ r   ©r   r   s    r   Úon_errorÚCredentialsListener.on_error!   s   € à�~‰~Ðr   c                 ó   • Xl         g r   r$   r"   s     r   r%   r&   %   s   € à!�r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Úpropertyr	   r   r   r   r   ÚsetterÚ	Exceptionr%   Ú__static_attributes__© r   r   r   r      så   † ñò
ð ð˜˜x¨¨¨t¨Ñ4°iÐ?Ñ@ó ó ðð ‡^�^ð!  h°¨u°d¨{Ñ&;¸YÐ&FÑ Gð !ÈDó !ó ð!ð ð˜% ¨)¨°dÐ):Ñ ;¸YÐ FÑGó ó ðð ‡_�_ð"  x°°¸TÐ0AÑ'BÀIÐ'MÑ!Nð "ÐSWó "ó ó"r   r   c                   óB   • \ rS rSrS\S\4S jrS\4S jrS\4S jrSr	g	)
ÚRetryPolicyé*   Úmax_attemptsÚdelay_in_msc                 ó   • Xl         X l        g r   )r5   r6   )r   r5   r6   s      r   r   ÚRetryPolicy.__init__+   s   € Ø(ÔØ&Õr   r   c                 ó   • U R                   $ )z?
Retry attempts before exception will be thrown.

:return: int
)r5   r   s    r   Úget_max_attemptsÚRetryPolicy.get_max_attempts/   s   € ð × Ñ Ð r   c                 ó   • U R                   $ )z1
Delay between retries in seconds.

:return: int
)r6   r   s    r   Úget_delay_in_msÚRetryPolicy.get_delay_in_ms7   s   € ð ×ÑÐr   )r6   r5   N)
r(   r)   r*   r+   ÚintÚfloatr   r:   r=   r0   r1   r   r   r3   r3   *   s-   † ð' Sð '°uô 'ð! #ô !ð  ÷  r   r3   c                   óf   • \ rS rSrS\S\S\S\4S jrS\4S jrS\4S	 jr	S\4S
 jr
S\4S jrSrg)ÚTokenManagerConfigé@   Úexpiration_refresh_ratioÚlower_refresh_bound_millisÚ%token_request_execution_timeout_in_msÚretry_policyc                 ó6   • Xl         X l        UU l        X@l        g r   )Ú_expiration_refresh_ratioÚ_lower_refresh_bound_millisÚ&_token_request_execution_timeout_in_msÚ_retry_policy)r   rD   rE   rF   rG   s        r   r   ÚTokenManagerConfig.__init__A   s$   € ð *BÔ&Ø+EÔ(à1ð 	Ô3ð *Õr   r   c                 ó   • U R                   $ )zþ
Represents the ratio of a token's lifetime at which a refresh should be triggered. # noqa: E501
For example, a value of 0.75 means the token should be refreshed
when 75% of its lifetime has elapsed (or when 25% of its lifetime remains).

:return: float
)rI   r   s    r   Úget_expiration_refresh_ratioÚ/TokenManagerConfig.get_expiration_refresh_ratioO   s   € ð ×-Ñ-Ð-r   c                 ó   • U R                   $ )ad  
Represents the minimum time in milliseconds before token expiration
to trigger a refresh, in milliseconds.
This value sets a fixed lower bound for when a token refresh should occur,
regardless of the token's total lifetime.
If set to 0 there will be no lower bound and the refresh will be triggered
based on the expirationRefreshRatio only.

:return: int
)rJ   r   s    r   Úget_lower_refresh_bound_millisÚ1TokenManagerConfig.get_lower_refresh_bound_millisZ   s   € ð ×/Ñ/Ð/r   c                 ó   • U R                   $ )zd
Represents the maximum time in milliseconds to wait
for a token request to complete.

:return: int
)rK   r   s    r   Ú)get_token_request_execution_timeout_in_msÚ<TokenManagerConfig.get_token_request_execution_timeout_in_msg   s   € ð ×:Ñ:Ð:r   c                 ó   • U R                   $ )zG
Represents the retry policy for token requests.

:return: RetryPolicy
)rL   r   s    r   Úget_retry_policyÚ#TokenManagerConfig.get_retry_policyp   s   € ð ×!Ñ!Ð!r   )rI   rJ   rL   rK   N)r(   r)   r*   r+   r@   r?   r3   r   rO   rR   rU   rX   r0   r1   r   r   rB   rB   @   s]   † ð*à"'ð*ð %(ð*ð 03ð	*ð
 "ô*ð	.¨eô 	.ð0°ô 0ð;¸3ô ;ð" +÷ "r   rB   c                   ó<  • \ rS rSrS\S\4S jrS r SS\S\	S\
/ S	4   4S
 jjr   SS\S\	S\S\	S\
/ S	4   4
S jjrS rSS\4S jjrSS\4S jjrS\S\S\4S jrS\4S jrS\S\4S jr SS\	S\R,                  4S jjr SS\	S\R,                  4S jjrSrg	)ÚTokenManageréy   Úidentity_providerÚconfigc                 óT   • Xl         X l        S U l        S U l        S U l        SU l        g )Nr   )Ú_idpÚ_configÚ_next_timerÚ	_listenerÚ_init_timerÚ_retries)r   r]   r^   s      r   r   ÚTokenManager.__init__z   s,   € ð &Œ	ØŒØˆÔØˆŒØˆÔØˆ�r   c                 óN   • [         R                  S5        U R                  5         g )NzToken manager are disposed)ÚloggerÚinfoÚstopr   s    r   Ú__del__ÚTokenManager.__del__„   s   € Ü�‰Ð0Ô1Ø�	‰	�r   ÚlistenerÚskip_initialr   Nc                 óð  • Xl          [        R                  " 5       n[        R                  " 5       nUR                  SU R                  X%5      U l        [        R                  S5        [        R                  " UR!                  5       U5      R#                  5         U R$                  $ ! [         aC    [        R                  " 5       n[
        R                  " [        U4SS9nUR                  5          N×f = f)NT)ÚtargetÚargsÚdaemonr   úToken manager started)rc   ÚasyncioÚget_running_loopÚRuntimeErrorÚnew_event_loopÚ	threadingÚThreadÚ_start_event_loop_in_threadÚstartÚEventÚ
call_laterÚ_renew_tokenrd   rh   ri   Úrun_coroutine_threadsafeÚwaitÚresultrj   )r   rm   rn   ÚloopÚthreadÚ
init_events         r   r{   ÚTokenManager.startˆ   sÅ   € ð
 "Œð	Ü×+Ò+Ó-ˆDô —]’]“_ˆ
ØŸ?™?Øˆt× Ñ  ,ó
ˆÔô 	�‰Ð+Ô,ô 	×(Ò(¨¯©Ó):¸DÓA×HÑHÔJØ�y‰yÐøô# ó 	ä×)Ò)Ó+ˆDÜ×%Ò%Ü2¸$¸ÈñˆFð �L‰LŽNð	ús   ˆB( Â(A
C5Ã4C5Úblock_for_initialÚinitial_delay_in_msc              ƒ   óN  #   • Xl         [        R                  " 5       n[        R                  " 5       n[	        XPR
                  XF5      nUR                  US-  U5      U l        [        R                  S5        U(       a  UR                  5       I S h  v•N   U R                  $  N7f)Néè  rs   )rc   rt   ru   r|   Ú_async_to_sync_wrapperÚ_renew_token_asyncr}   rd   rh   ri   r€   rj   )r   rm   r†   r‡   rn   r‚   r„   Úwrappeds           r   Ústart_asyncÚTokenManager.start_async¤   s†   é € ð "Œä×'Ò'Ó)ˆÜ—]’]“_ˆ
ô )Ø×)Ñ)¨<ó
ˆð  Ÿ?™?Ð+>ÀÑ+EÀwÓOˆÔÜ�‰Ð+Ô,æØ—/‘/Ó#×#Ð#à�y‰yÐñ $ùs   ‚BB%ÂB#ÂB%c                 ó¢   • U R                   b  U R                   R                  5         U R                  b  U R                  R                  5         g g r   )rd   Úcancelrb   r   s    r   rj   ÚTokenManager.stop¼   sC   € Ø×ÑÑ'Ø×Ñ×#Ñ#Ô%Ø×ÑÑ'Ø×Ñ×#Ñ#Õ%ð (r   c                 ó°  •  U R                   R                  U5      nSU l        [        U5      $ ! [         aœ  nU R                  U R                  R                  5       R                  5       :  a_  U =R                  S-  sl        [        U R                  R                  5       R                  5       S-  5        U R                  U5      s S nA$ UeS nAff = f©Né   r‰   r   )r`   Úrequest_tokenr
   re   ra   rX   r:   r   r=   Úacquire_tokenr   ©r   Úforce_refreshÚtokenÚes       r   r–   ÚTokenManager.acquire_tokenÂ   sª   € ð	Ø—I‘I×+Ñ+¨MÓ:ˆEð ˆŒÜ˜UÓ#Ð#øô ó 	Ø�}‰}˜tŸ|™|×<Ñ<Ó>×OÑOÓQÓQØ—’ Ñ"•Ü�d—l‘l×3Ñ3Ó5×EÑEÓGÈ$ÑNÔOØ×)Ñ)¨-Ó8Õ8à�ûð	ús!   ‚/ ¯
C¹BCÃCÃCÃCc              ƒ   óò  #   •  U R                   R                  U5      nSU l        [        U5      $ ! [         a¹  nU R                  U R                  R                  5       R                  5       :  a|  U =R                  S-  sl        [        R                  " U R                  R                  5       R                  5       S-  5      I S h  v•N    U R                  U5      I S h  v•N  s S nA$ UeS nAff = f7fr“   )r`   r•   r
   re   ra   rX   r:   rt   r   r=   Úacquire_token_asyncr   r—   s       r   r�   Ú TokenManager.acquire_token_asyncÐ   sÅ   é € ð
	Ø—I‘I×+Ñ+¨MÓ:ˆEð ˆŒÜ˜UÓ#Ð#øô ó 	Ø�}‰}˜tŸ|™|×<Ñ<Ó>×OÑOÓQÓQØ—’ Ñ"•Ü—m’mØ—L‘L×1Ñ1Ó3×CÑCÓEÈÑLó÷ ñ ð "×5Ñ5°mÓD×DÐDÕDà�ûð	üsO   ‚C7„1 ŸC7±
C4»BC/ÃCÃ	C/Ã"C%Ã#C/Ã'C4Ã(C7Ã-C/Ã/C4Ã4C7Úexpire_dateÚ
issue_datec                 óv   • U R                  U5      nU R                  X5      n[        XC5      nUS:  a  S$ US-  $ )Nr   r‰   )Ú_delay_for_lower_refreshÚ_delay_for_ratio_refreshÚmin)r   rŸ   r    Údelay_for_lower_refreshÚdelay_for_ratio_refreshÚdelays         r   Ú_calculate_renewal_delayÚ%TokenManager._calculate_renewal_delayà   sD   € Ø"&×"?Ñ"?ÀÓ"LÐØ"&×"?Ñ"?ÀÓ"XÐÜÐ+ÓEˆà˜A“IˆqÐ/ 5¨4¡<Ð/r   c                 ó¨   • UU R                   R                  5       -
  [        R                  " [        R
                  5      R                  5       S-  -
  $ ©Nr‰   )ra   rR   r   Únowr   ÚutcÚ	timestamp)r   rŸ   s     r   r¢   Ú%TokenManager._delay_for_lower_refreshç   sB   € àØ�l‰l×9Ñ9Ó;ñ<ä�|Š|œHŸL™LÓ)×3Ñ3Ó5¸Ñ<ñ>ð	
r   c                 ó¾   • X-
  nUX0R                   R                  5       -  -
  nUU-
  [        R                  " [        R
                  5      R                  5       S-  -
  $ r«   )ra   rO   r   r¬   r   r­   r®   )r   rŸ   r    Ú	token_ttlÚrefresh_befores        r   r£   Ú%TokenManager._delay_for_ratio_refreshî   s\   € ØÑ,ˆ	Ø"ØŸ™×AÑAÓCÑCñ
ˆð
 Øñä�|Š|œHŸL™LÓ)×3Ñ3Ó5¸Ñ<ñ>ð	
r   r„   c                 óN  •  U R                  SS9nU R                  UR                  5       R                  5       UR                  5       R	                  5       5      nUR                  5       R                  5       (       a  [        S5      eU R                  R                  c/  [        R                  S5         U(       a  UR                  5         ggU(       d*   U R                  R                  UR                  5       5        US::  a   U(       a  UR                  5         gg[        R                  " 5       nUR                  X@R                   5      U l        [        R%                  SU S35        UU(       a  UR                  5         $ $ ! [         a  n[        U5      eSnAff = f! [         a>  nU R                  R&                  c  UeU R                  R'                  U5         SnAOSnAff = f U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)	zY
Task to renew token from identity provider.
Schedules renewal tasks based on token TTL.
T©r˜   úRequested token is expiredNú@No registered callback for token renewal task. Renewal cancelledr   ú Next token renewal scheduled in ú seconds)r–   r¨   Ú	get_tokenÚget_expires_at_msÚget_received_at_msÚ
is_expiredr   rc   r   rh   ÚwarningÚsetr/   rt   ru   r}   r~   rb   ri   r%   )r   rn   r„   Ú	token_resr§   rš   r‚   s          r   r~   ÚTokenManager._renew_tokenú   sÍ  € ð$	!Ø×*Ñ*¸Ð*Ð>ˆIØ×1Ñ1Ø×#Ñ#Ó%×7Ñ7Ó9Ø×#Ñ#Ó%×8Ñ8Ó:óˆEð
 ×"Ñ"Ó$×/Ñ/×1Ñ1Ü%Ð&BÓCÐCà�~‰~×%Ñ%Ñ-Ü—‘ØVôð ö* Ø—‘Õ ð ö'  ð-Ø—N‘N×*Ñ*¨9×+>Ñ+>Ó+@ÔAð ˜‹zØö Ø—‘Õ ð ô ×+Ò+Ó-ˆDØ#Ÿ™¨u×6GÑ6GÓHˆDÔÜ�K‰KÐ:¸5¸'ÀÐJÔKØö Ø—‘Õ ð øô! !ó -Ü)¨!Ó,Ð,ûð-ûô ó 	'Ø�~‰~×&Ñ&Ñ.Ø�à�N‰N×#Ñ# A×&Ñ&ûð		'úð 'æØ—‘Õ ð øŽzØ—‘Õ ð ús[   ‚B3F% ÃF% Ã)F Ä F% Ä AF% Æ
F"ÆFÆF"Æ"F% Æ%
G-Æ/4G(Ç#H
 Ç(G-Ç-H
 È
H$c              ƒ   óh  #   •  U R                  SS9I Sh  v•N nU R                  UR                  5       R                  5       UR                  5       R	                  5       5      nUR                  5       R                  5       (       a  [        S5      eU R                  R                  c/  [        R                  S5         U(       a  UR                  5         ggU(       d2   U R                  R                  UR                  5       5      I Sh  v•N   US::  a   U(       a  UR                  5         gg[        R                  " 5       n[        X`R                   5      n[        R#                  SU S35        UR%                  XG5        U(       a  UR                  5         gg GN‰ N”! [         a  n[        U5      eSnAff = f! [         aG  nU R                  R&                  c  UeU R                  R'                  U5      I Sh  v•N     SnAN‡SnAff = f! U(       a  UR                  5         f f = f7f)	z`
Async task to renew tokens from identity provider.
Schedules renewal tasks based on token TTL.
Trµ   Nr¶   r·   r   r¸   r¹   )r�   r¨   rº   r»   r¼   r½   r   rc   r   rh   r¾   r¿   r/   rt   ru   rŠ   r‹   ri   r}   r%   )r   rn   r„   rÀ   r§   rš   r‚   rŒ   s           r   r‹   ÚTokenManager._renew_token_async(  sÓ  é € ð$	!Ø"×6Ñ6ÀTÐ6ÐJ×JˆIØ×1Ñ1Ø×#Ñ#Ó%×7Ñ7Ó9Ø×#Ñ#Ó%×8Ñ8Ó:óˆEð
 ×"Ñ"Ó$×/Ñ/×1Ñ1Ü%Ð&BÓCÐCà�~‰~×%Ñ%Ñ-Ü—‘ØVôð ö* Ø—‘Õ ð ö'  ð-ØŸ.™.×0Ñ0°×1DÑ1DÓ1FÓG×GÐGð ˜‹zØö Ø—‘Õ ð ô ×+Ò+Ó-ˆDÜ,¨T×3JÑ3JÓKˆGÜ�K‰KÐ:¸5¸'ÀÐJÔKØ�O‰O˜EÔ+ö Ø—‘Õ ð òE Kñ" HøÜ ó -Ü)¨!Ó,Ð,ûð-ûô ó 	-Ø�~‰~×&Ñ&Ñ.Ø�à—.‘.×)Ñ)¨!Ó,×,Ö,ûð		-ûö Ø—‘Õ ð üs¦   ‚H2„G –F—B(G Ã H2ÃG Ã!,F$ ÄF"ÄF$ ÄG ÄH2Ä2AG ÆH2ÆG Æ"F$ Æ$
F>Æ.F9Æ9F>Æ>G Ç
HÇ7HÈHÈHÈH ÈHÈH ÈH/È/H2)ra   r`   rd   rc   rb   re   )F)Fr   F)FN)r(   r)   r*   r+   r   rB   r   rk   r   Úboolr   r{   r@   r�   rj   r   r–   r�   r¨   r¢   r£   rt   r|   r~   r‹   r0   r1   r   r   r[   r[   y   s1  † ðØ!:ðØDVôòð #ñà%ðð ðð 
�"�d�(Ñ	õ	ð> #(Ø%&Ø"ñà%ðð  ðð #ð	ð
 ðð 
�"�d�(Ñ	õò0&ñ$°Mõ $ñ$Àõ $ð 0°Eð 0Àuð 0ÐQVô 0ð
°Eô 
ð

°Eð 

Àuô 

ð GKñ,!Ø ð,!Ø6=·m±mõ,!ð^ GKñ,!Ø ð,!Ø6=·m±m÷,!ð ,!r   r[   c                 ó    ^ ^^^• UUUU 4S jnU$ )aƒ  
Wraps an asynchronous function so it can be used with loop.call_later.

:param loop: The event loop in which the coroutine will be executed.
:param coro_func: The coroutine function to wrap.
:param args: Positional arguments to pass to the coroutine function.
:param kwargs: Keyword arguments to pass to the coroutine function.
:return: A regular function suitable for loop.call_later.
c                  ó<   >• [         R                  " T" T 0 TD6TS9  g )N)r‚   )rt   Úensure_future)rq   Ú	coro_funcÚkwargsr‚   s   €€€€r   rŒ   Ú'_async_to_sync_wrapper.<locals>.wrappedb  s   ø€ ä×Ò™i¨Ð8°Ñ8¸tÓDr   r1   )r‚   rÈ   rq   rÉ   rŒ   s   ```` r   rŠ   rŠ   W  s   û€ ÷Eð Eð €Nr   Ú
event_loopc                 óP   • [         R                  " U 5        U R                  5         g)zv
Starts event loop in a thread.
Used to be able to schedule tasks using loop.call_later.

:param event_loop:
:return:
N)rt   Úset_event_loopÚrun_forever)rË   s    r   rz   rz   i  s   € ô ×Ò˜:Ô&Ø×ÑÕr   )rt   Úloggingrx   r   r   Útimer   Útypingr   r   r   r	   Úredis.auth.errr
   r   Úredis.auth.idpr   Úredis.auth.tokenr   Ú	getLoggerr(   rh   r   r3   rB   r[   rŠ   ÚAbstractEventLooprz   r1   r   r   Ú<module>r×      sv   ðÛ Û Û ß 'Ý ß 2Ó 2ç ;Ý 4Ý *à	×	Ò	˜8Ó	$€÷"ñ "÷6 ñ  ÷,6"ñ 6"÷r[!ñ [!ò|ð$	¨G×,EÑ,Eõ 	r   