
    g                     B   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	 ddlm	Z	 ddlmZ dd	lmZ  ej                   e      Zd
Z ej                  ddd      Zd Zd Z G d dej.                        Z ee      Zy# e
$ r 	 ddlm	Z	 n# e
$ r	  e
d      w xY wY yw xY w)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                     	 | t         z
  j                         S # t        $ r> | t         z
  }|j                  |j                  |j
                  dz  dz  z   dz  z   dz  cY S w xY w)N   i  i@B )EPOCHtotal_secondsAttributeErrormicrosecondssecondsdays)datedeltas     /var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/googleapiclient/discovery_cache/file_cache.py_to_timestampr   4   sj    u++--  u%--%**r/D2H"HE!QQ 		s    AA A c                 t   | j                         j                  d       	 t        j                  | j                               }|S # t        $ rh i }| j                         j                  d       | j                         j                  d       t        j                  || j                                Y |S w xY wNr   )file_handleseekjsonload	Exceptiontruncatedump)fcaches     r   _read_or_initialize_cacher    @   s    MMO*		!--/* L  * 	  #	Q		%)L*s   #A A-B76B7c                   "    e Zd ZdZd Zd Zd Zy)Cachez/A file based cache for the discovery documents.c                    || _         t        j                  j                  t	        j
                         t              | _        t        | j                  dd      }	 |j                          |j                         rt        |       |j                          y# t        $ r!}t        j                  |d       Y d}~6d}~ww xY w# |j                          w xY 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   es       r   __init__zCache.__init__Q   s      WW\\("5"5"7B
tzz4-		!OO{{})!,    	-NN1tN,,	-  s*   +B 	C B<7C <CC Cc                 f   t        | j                  dd      }	 |j                          |j                         rt	        |      }||v r^|j                  |d      \  }}t        t        j                  j                               || j                  z   k  r||j                          S 	 |j                          y t        j                  d       	 |j                          y # t        $ r!}t        j                  |d       Y d }~nd }~ww xY w	 |j                          y # |j                          w xY w)Nr+r$   r   +Could not obtain a lock for the cache file.Tr%   )r   r.   r/   r0   r    getr   datetimenowr'   r3   r1   debugr   r2   )r4   urlr   r   contenttr6   s          r   r;   z	Cache.gete   s    tzz4-	!OO{{}1!4%<!&3	!:JGQ$X%6%6%:%:%<=DMM@QQ&      JK    	-NN1tN,,	-, A s0   A<C 8C 	D	(D?D D		D D0c                 4   t        | j                  dd      }	 |j                          |j                         rt	        |      }|t        t        j                  j                               f||<   t        |j                               D ]C  \  }\  }}t        t        j                  j                               || j                  z   k\  sA||= E |j                         j                  d       |j                         j                  d       t        j                  ||j                                nt         j#                  d       |j)                          y # t$        $ r!}t         j'                  |d       Y d }~6d }~ww xY w# |j)                          w xY w)Nr9   r$   r   r:   Tr%   )r   r.   r/   r0   r    r   r<   r=   listitemsr'   r   r   r   r   r   r1   r>   r   r2   r3   )	r4   r?   r@   r   r   k_	timestampr6   s	            r   setz	Cache.setx   s9   tzz4-	!OO{{}1!4%}X5F5F5J5J5L'MNc
)-ekkm)< %%A~9%h&7&7&;&;&=>$t}}45 "!H% ((+$$Q'		%1JK    	-NN1tN,,	-  s1   B0E 
A=E 	F!E=8F =FF FN)__name__
__module____qualname____doc__r7   r;   rH        r   r"   r"   N   s    9!(!&!rN   r"   )r5   )rL   
__future__r   r<   r   loggingr(   r+    oauth2client.contrib.locked_filer   ImportErroroauth2client.locked_file r   discovery_cacher   	getLoggerrI   r1   r-   r   r   r    r"   r   rM   rN   r   <module>rW      s         	 

;  3			8	$9$1%	@!DJJ @!F 	+,a  

7 
W
 	

 	8
s)   A= =BB
	B
BBB