
    &g/                         d dl Z d dlZd dlZd dlmc mZ  ej        e          Z	 G d d          Z
 G d dej                  ZdS )    Nc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )RefreshThreadManagerzD
    Organizes exactly one background job that refresh a token.
    c                 D    d| _         t          j                    | _        dS )zInitializes the manager.N)_worker	threadingLock_lockselfs    M/var/www/api/venv/lib/python3.11/site-packages/google/auth/_refresh_worker.py__init__zRefreshThreadManager.__init__   s     ^%%


    c                 x   ||t          j        d          | j        5  | j        | j        j        	 ddd           dS | j        | j                                        sAt          |t          j        |                    | _        | j        	                                 ddd           n# 1 swxY w Y   dS )au  Starts a refresh thread for the given credentials.
        The credentials are refreshed using the request parameter.
        request and cred MUST not be None

        Returns True if a background refresh was kicked off. False otherwise.

        Args:
            cred: A credentials object.
            request: A request object.
        Returns:
          bool
        NzQUnable to start refresh. cred and request must be valid and instantiated objects.F)credrequestT)
eInvalidValuer	   r   _error_infois_aliveRefreshThreadcopydeepcopystart)r   r   r   s      r   start_refreshz"RefreshThreadManager.start_refresh#   s    <7?.c   Z 	% 	%|'DL,D,P	% 	% 	% 	% 	% 	% 	% 	% |#4<+@+@+B+B#,$g@V@VWWW""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% ts   B/A!B//B36B3c                 l    | j         5  | j        rd| j        _        ddd           dS # 1 swxY w Y   dS )zU
      Removes any errors that were stored from previous background refreshes.
      N)r	   r   r   r
   s    r   clear_errorz RefreshThreadManager.clear_error>   s     Z 	0 	0| 0+/(	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   )--c                 B    | j                                         }d|d<   |S )z2Pickle helper that serializes the _lock attribute.Nr	   )__dict__r   r   states     r   __getstate__z!RefreshThreadManager.__getstate__F   s#    ""$$gr   c                 f    t          j                    |d<   | j                            |           dS )z4Pickle helper that deserializes the _lock attribute.r	   N)r   r   r   updater   s     r   __setstate__z!RefreshThreadManager.__setstate__L   s/    "))gU#####r   N)	__name__
__module____qualname____doc__r   r   r   r!   r$    r   r   r   r      si         & & &  60 0 0  $ $ $ $ $r   r   c                   (     e Zd ZdZ fdZd Z xZS )r   z,
    Thread that refreshes credentials.
    c                 d     t                      j        di | || _        || _        d| _        dS )zInitializes the thread.

        Args:
            cred: A Credential object to refresh.
            request: A Request object used to perform a credential refresh.
            **kwargs: Additional keyword arguments.
        Nr)   )superr   _cred_requestr   )r   r   r   kwargs	__class__s       r   r   zRefreshThread.__init__W   s>     	""6"""
r   c                     	 | j                             | j                   dS # t          $ r/}t                              d|            || _        Y d}~dS d}~ww xY w)z1
        Perform the credential refresh.
        z"Background refresh failed due to: N)r-   refreshr.   	Exception_LOGGERerrorr   )r   errs     r   runzRefreshThread.rune   sy    	#Jt}----- 	# 	# 	#MMDsDDEEE"D	#s   # 
A$AA)r%   r&   r'   r(   r   r7   __classcell__)r0   s   @r   r   r   R   sQ                  # # # # # # #r   r   )r   loggingr   google.auth.exceptionsauth
exceptionsr   	getLoggerr%   r4   r   Threadr   r)   r   r   <module>r?      s          " " " " " " " " "
'
H
%
%7$ 7$ 7$ 7$ 7$ 7$ 7$ 7$t# # # # #I$ # # # # #r   