
    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y)    Nc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)RefreshThreadManagerzD
    Organizes exactly one background job that refresh a token.
    c                 D    d| _         t        j                         | _        y)zInitializes the manager.N)_worker	threadingLock_lockselfs    P/var/www/openai/venv/lib/python3.12/site-packages/google/auth/_refresh_worker.py__init__zRefreshThreadManager.__init__   s     ^^%
    c                    ||t        j                  d      | j                  5  | j                   | j                  j                  
	 ddd       y| j                  | j                  j                         s?t        |t        j                  |            | _        | j                  j                          ddd       y# 1 sw Y   yxY w)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  ZZ||'DLL,D,D,P Z ||#4<<+@+@+B,$g@VW""$    s   $CA%CC
c                     | j                   5  | j                  rd| j                  _        ddd       y# 1 sw Y   yxY w)zU
      Removes any errors that were stored from previous background refreshes.
      N)r	   r   r   r
   s    r   clear_errorz RefreshThreadManager.clear_error>   s(     ZZ||+/( ZZs   4=c                 D    | j                   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                 h    t        j                         |d<   | j                  j                  |       y)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      s     &6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                 N    t        |   di | || _        || _        d| _        y)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                  | j                         y# t        $ r)}t        j                  d|        || _        Y d}~y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   sL    	#JJt}}- 	#MM>seDE"D	#s   %( 	AAA)r%   r&   r'   r(   r   r7   __classcell__)r0   s   @r   r   r   R   s     #r   r   )r   loggingr   google.auth.exceptionsauth
exceptionsr   	getLoggerr%   r4   r   Threadr   r)   r   r   <module>r?      sE       " "
'

H
%7$ 7$t#I$$ #r   