o
    ~j6h/                     @   sX   d dl Z d dlZd dlZd dlm  mZ eeZ	G dd dZ
G dd dejZdS )    Nc                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )RefreshThreadManagerzD
    Organizes exactly one background job that refresh a token.
    c                 C   s   d| _ t | _dS )zInitializes the manager.N)_worker	threadingLock_lockself r	   j/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/google/auth/_refresh_worker.py__init__   s   zRefreshThreadManager.__init__c                 C   s   |du s|du rt d| j> | jdur%| jjdur%	 W d   dS | jdu s/| j sFt|t|d| _| j	  W d   dS W d   dS 1 sQw   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   r	   r	   r
   start_refresh#   s$   

z"RefreshThreadManager.start_refreshc                 C   sJ   | j  | jrd| j_W d   dS W d   dS 1 sw   Y  dS )zU
      Removes any errors that were stored from previous background refreshes.
      N)r   r   r   r   r	   r	   r
   clear_error>   s   
"z RefreshThreadManager.clear_errorc                 C   s   | j  }d|d< |S )z2Pickle helper that serializes the _lock attribute.Nr   )__dict__r   r   stater	   r	   r
   __getstate__F   s   
z!RefreshThreadManager.__getstate__c                 C   s   t  |d< | j| dS )z4Pickle helper that deserializes the _lock attribute.r   N)r   r   r   updater   r	   r	   r
   __setstate__L   s   z!RefreshThreadManager.__setstate__N)	__name__
__module____qualname____doc__r   r   r   r   r   r	   r	   r	   r
   r      s    r   c                       s(   e Zd ZdZ fddZdd Z  ZS )r   z,
    Thread that refreshes credentials.
    c                    s(   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__r	   r
   r   W   s   	
zRefreshThread.__init__c              
   C   sR   z
| j | j W dS  ty( } ztd|  || _W Y d}~dS d}~ww )z1
        Perform the credential refresh.
        z"Background refresh failed due to: N)r#   refreshr$   	Exception_LOGGERerrorr   )r   errr	   r	   r
   rune   s   zRefreshThread.run)r   r   r    r!   r   r-   __classcell__r	   r	   r&   r
   r   R   s    r   )r   loggingr   google.auth.exceptionsauth
exceptionsr   	getLoggerr   r*   r   Threadr   r	   r	   r	   r
   <module>   s   
: