
    FCf                    |    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ e	rddlmZmZ  G d	 d
      Zy)z%Utilities for caching OCSP responses.    )annotations)
namedtuple)datetime)timezone)TYPE_CHECKINGAny)_create_lock)OCSPRequestOCSPResponsec                  F    e Zd ZdZ edg d      Zd	dZd
dZddZddZ	y)
_OCSPCachezA cache for OCSP responses.OcspResponseCacheKeyhash_algorithmissuer_name_hashissuer_key_hashserial_numberc                0    i | _         t               | _        y )N)_datar	   _lock)selfs    R/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/pymongo/ocsp_cache.py__init__z_OCSPCache.__init__&   s    .0
!^
    c                    | j                  |j                  j                  j                         |j                  |j
                  |j                        S )Nr   )CACHE_KEY_TYPEr   namelowerr   r   r   )r   ocsp_requests     r   _get_cache_keyz_OCSPCache._get_cache_key+   sM    ""'66;;AAC)::(88&44	 # 
 	
r   c                *   | j                   5  | j                  |      }|j                  &| j                  j	                  |d       	 ddd       y|j
                  t        j                  t        j                        j                  d      cxk  r|j                  k  sn 	 ddd       y| j                  j                  |d      }|%|j                  (|j                  |j                  k  r|| j                  |<   ddd       y# 1 sw Y   yxY w)zAdd/update a cache entry.

        'key' is of type cryptography.x509.ocsp.OCSPRequest
        'value' is of type cryptography.x509.ocsp.OCSPResponse

        Validity of the OCSP response must be checked by caller.
        Ntztzinfo)r   r    next_updater   popthis_update	_datetimenowr   utcreplaceget)r   keyvalue	cache_keycached_values        r   __setitem__z_OCSPCache.__setitem__3   s     ZZ 	.++C0I
   (

y$/	. 	. !!==HLL1999F$##$ !	. 	.(  ::>>)T:L#((4 ,,u/@/@@(-

9%3	. 	. 	.s   ;D	AD	.AD		Dc                   | j                   5  | j                  |      }| j                  |   }|j                  J |j                  J |j                  t        j                  t        j                        j                  d      cxk  r|j                  k  rn n|cddd       S | j                  j                  |d       t        |      # 1 sw Y   yxY w)zGet a cache entry if it exists.

        'item' is of type cryptography.x509.ocsp.OCSPRequest

        Raises KeyError if the item is not in the cache.
        Nr"   r$   )r   r    r   r(   r&   r)   r*   r   r+   r,   r'   KeyError)r   itemr0   r/   s       r   __getitem__z_OCSPCache.__getitem__V   s     ZZ 	&++D1IJJy)E $$000$$000!!==HLL1999F$##$ 	& 	& JJNN9d+9%%	& 	&s   BC)'CCN)returnNone)r   r
   r7   r   )r.   r
   r/   r   r7   r8   )r5   r
   r7   r   )
__name__
__module____qualname____doc__r   r   r   r    r2   r6    r   r   r   r      s*    %RN
$

!.F&r   r   N)r<   
__future__r   collectionsr   r   r)   r   typingr   r   pymongo.lockr	   cryptography.x509.ocspr
   r   r   r=   r   r   <module>rC      s.    , " " *  % %@N& N&r   