
    j	i                     F   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	 n'# e
$ r 	 ddlm	Z	 n# e
$ r  e
d          w xY wY nw xY w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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                     	 | t           z
                                  S # t          $ r0 | 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     b/srv/django_bis/venv311/lib/python3.11/site-packages/googleapiclient/discovery_cache/file_cache.py_to_timestampr   4   s|    u++---    u%-%*r/D2H"HE!QQ 	 	 		s    7AAc                    |                                                      d           	 t          j        |                                            }n# t          $ rz i }|                                                      d           |                                                      d           t          j        ||                                             Y nw xY w|S Nr   )file_handleseekjsonload	Exceptiontruncatedump)fcaches     r   _read_or_initialize_cacher    @   s    MMOO*	!--//** * * * 	  ###	Q	%)))))* Ls   &A BCCc                   $    e Zd ZdZd Zd Zd ZdS )Cachez/A file based cache for the discovery documents.c                    || _         t          j                            t	          j                    t                    | _        t          | j        dd          }	 |	                                 |
                                rt          |           n3# t          $ r&}t                              |d           Y d}~nd}~ww xY w|                                 dS # |                                 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      W\\("5"7"7BB
tz4--		!OO{{}} -)!,,,  	- 	- 	-NN1tN,,,,,,,,	-      A    s0   7B C 
CB=8C =CC C1c                    t          | j        dd          }	 |                                 |                                rt	          |          }||v rf|                    |d          \  }}t          t          j                                                  || j	        z   k     r||
                                 S 	 |
                                 d S t                              d           	 |
                                 d S # t          $ r&}t                              |d           Y d }~nd }~ww xY w	 |
                                 d S # |
                                 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   st   tz4--	!OO{{}} 	1!44%<<!&3	!:!:JGQ$X%6%:%:%<%<==DM@QQQ&             JKKK        	- 	- 	-NN1tN,,,,,,,,	-,     A    s0   BD D 
D1D,'E ,D11E E!c                    t          | j        dd          }	 |                                 |                                rt	          |          }|t          t          j                                                  f||<   t          |	                                          D ]B\  }\  }}t          t          j                                                  || j
        z   k    r||= C|                                                    d           |                                                    d           t          j        ||                                           nt                               d           n3# t$          $ r&}t                               |d           Y d }~nd }~ww xY w|                                 d S # |                                 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   s   tz4--	!OO{{}} L1!44%}X5F5J5J5L5L'M'MNc
)-ekkmm)<)< % %%A~9%h&7&;&;&=&=>>$t}45 5 "!H((+++$$Q'''	%1111JKKK 	- 	- 	-NN1tN,,,,,,,,	-      A    s0   EE5 4F> 5
F%?F F>  F%%F> >GN)__name__
__module____qualname____doc__r7   r;   rH        r   r"   r"   N   sG        9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              				 

;;;;;;; 
 
 

7777777 
 
 
kW
 
 	

 	87
       3 3 3 3 3 3		8	$	$9$1%%	 	 	  @! @! @! @! @!DJ @! @! @!F 	+,,,s#   % A	2A	AA	A	