o Sb; @s<dZddlmZddlmZddlmZGdddeZdS)z%Utilities for caching OCSP responses.) namedtuple)datetime)Lockc@s>eZdZdZedgdZddZddZdd Zd d Z d S) _OCSPCachezA cache for OCSP responses.ZOcspResponseCacheKeyhash_algorithmissuer_name_hashissuer_key_hash serial_numbercCsi|_t|_dS)N)_datar_lock)selfr9/tmp/pip-target-onvjaxws/lib/python/pymongo/ocsp_cache.py__init__s z_OCSPCache.__init__cCs |j|jj|j|j|jdS)Nr)CACHE_KEY_TYPErnamelowerrr r )r Z ocsp_requestrrr_get_cache_key#s  z_OCSPCache._get_cache_keycCs|jY||}|jdur|j|d WddS|jtkr,|jks6n WddS|j|d}|dusG|j|jkrT||j|<WddSWddS1s_wYdS)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 _datetimeutcnowget)r keyvalue cache_keyZ cached_valuerrr __setitem__+s    "z_OCSPCache.__setitem__cCsx|j/||}|j|}|jtkr|jkr'nn |WdS|j|dt|1s5wYdS)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 rr rrrrrKeyError)r itemrrrrr __getitem__Gs   z_OCSPCache.__getitem__N) __name__ __module__ __qualname____doc__rrrrrr!rrrrrs rN) r% collectionsrrr threadingrobjectrrrrrs