3
O6b                 @   s<   d Z ddlmZ ddlmZ ddlmZ G dd deZdS )z%Utilities for caching OCSP responses.    )
namedtuple)datetime)Lockc               @   sB   e Zd ZdZedddddgZdd Zd	d
 Zdd Zdd Z	dS )
_OCSPCachezA cache for OCSP responses.ZOcspResponseCacheKeyhash_algorithmissuer_name_hashissuer_key_hashserial_numberc             C   s   i | _ t | _d S )N)_datar   _lock)self r   Q/var/www/html/sandeepIITI/myenv/lib/python3.6/site-packages/pymongo/ocsp_cache.py__init__   s    z_OCSPCache.__init__c             C   s    | j |jjj |j|j|jdS )N)r   r   r   r	   )CACHE_KEY_TYPEr   namelowerr   r   r	   )r   Zocsp_requestr   r   r   _get_cache_key!   s
    
z_OCSPCache._get_cache_keyc          
   C   s   | j | | j|}|jdkr.| jj|d dS |jtj   koH|jk n  sRdS | jj|d}|dkst|j|jk r~|| j|< W dQ R X dS )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)	r   r   next_updater
   popthis_update	_datetimeutcnowget)r   keyvalue	cache_keyZcached_valuer   r   r   __setitem__(   s    

z_OCSPCache.__setitem__c          
   C   sd   | j T | j|}| j| }|jtj   ko6|jk n  r@|S | jj|d t|W dQ R X dS )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.
        N)	r   r   r
   r   r   r   r   r   KeyError)r   itemr   r   r   r   r   __getitem__F   s    

z_OCSPCache.__getitem__N)
__name__
__module____qualname____doc__r   r   r   r   r   r    r   r   r   r   r      s   
r   N)	r$   collectionsr   r   r   	threadingr   objectr   r   r   r   r   <module>   s   