o
    ~j6h                     @   s   d Z ddlmZ ddlZddlZddlZddlZddlZzddlm	Z	 W n e
yA   zddlm	Z	 W n e
y>   e
dw Y nw ddlmZ dd	lmZ eeZd
ZedddZdd Zdd ZG dd dejZeedZdS )a  File based cache for the discovery document.

The cache is stored in a single file so that multiple processes can
share the same cache. It locks the file whenever accessing to the
file. When the cache content is corrupted, it will be initialized with
an empty cache.
    )divisionN)
LockedFilezIfile_cache is unavailable when using oauth2client >= 4.0.0 or google-auth   )base   )DISCOVERY_DOC_MAX_AGEz,google-api-python-client-discovery-doc.cachei  c                 C   sL   z| t   W S  ty%   | t  }|j|j|jd d  d  d  Y S w )N   i  i@B )EPOCHtotal_secondsAttributeErrormicrosecondssecondsdays)datedelta r   y/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/googleapiclient/discovery_cache/file_cache.py_to_timestamp4   s   r   c                 C   sh   |   d z
t|   }W |S  ty3   i }|   d |   d t||    Y |S w Nr   )file_handleseekjsonload	Exceptiontruncatedump)fcacher   r   r   _read_or_initialize_cache@   s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	Cachez/A file based cache for the discovery documents.c              
   C   s   || _ tjt t| _t| jdd}z6z|	  |
 r"t| W n ty< } ztj|dd W Y d}~nd}~ww W |  dS W |  dS |  w )zTConstructor.

        Args:
          max_age: Cache expiration in seconds.
        za+rTexc_infoN)_max_ageospathjointempfile
gettempdirFILENAME_filer   open_and_lock	is_lockedr   r   LOGGERwarningunlock_and_close)selfmax_ager   er   r   r   __init__Q   s    zCache.__init__c              
   C   s   t | jdd}zbzA|  | r=t|}||v r5||d\}}ttj || j	 k r5|W W |
  S W W |
  d S td W W |
  d S  tyb } ztj|dd W Y d }~nd }~ww W |
  d S |
  w )Nr+r    r   +Could not obtain a lock for the cache file.Tr!   )r   r*   r+   r,   r   getr   datetimenowr#   r/   r-   debugr   r.   )r0   urlr   r   contenttr2   r   r   r   r6   e   s*   

z	Cache.getc           	   
   C   s  t | jdd}zyzQ|  | rSt|}|ttj f||< t|	 D ]\}\}}ttj || j
 kr;||= q&| d | d t||  ntd W n tyr } ztj|dd W Y d }~nd }~ww W |  d S W |  d S |  w )Nr4   r    r   r5   Tr!   )r   r*   r+   r,   r   r   r7   r8   listitemsr#   r   r   r   r   r   r-   r9   r   r.   r/   )	r0   r:   r;   r   r   k_	timestampr2   r   r   r   setx   s2   
z	Cache.setN)__name__
__module____qualname____doc__r3   r6   rB   r   r   r   r   r   N   s
    r   )r1   )rF   
__future__r   r7   r   loggingr$   r'    oauth2client.contrib.locked_filer   ImportErroroauth2client.locked_file r   discovery_cacher   	getLoggerrC   r-   r)   r	   r   r   r   r   r   r   r   r   <module>   s8   

C