MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / __getitem__

Method __getitem__

pymongo/ocsp_cache.py:107–131  ·  view source on GitHub ↗

Get a cache entry if it exists. 'item' is of type cryptography.x509.ocsp.OCSPRequest Raises KeyError if the item is not in the cache.

(self, item: OCSPRequest)

Source from the content-addressed store, hash-verified

105 self._data[cache_key] = value
106
107 def __getitem__(self, item: OCSPRequest) -> OCSPResponse:
108 """Get a cache entry if it exists.
109
110 'item' is of type cryptography.x509.ocsp.OCSPRequest
111
112 Raises KeyError if the item is not in the cache.
113 """
114 with self._lock:
115 cache_key = self._get_cache_key(item)
116 value = self._data[cache_key]
117
118 # Return cached response if it is still valid.
119 this_update = _this_update(value)
120 next_update = _next_update(value)
121 assert this_update is not None
122 assert next_update is not None
123 now = _datetime.now(tz=timezone.utc)
124 if this_update.tzinfo is None:
125 # Make naive to match cryptography.
126 now = now.replace(tzinfo=None)
127 if this_update <= now < next_update:
128 return value
129
130 self._data.pop(cache_key, None)
131 raise KeyError(cache_key)

Callers

nothing calls this directly

Calls 4

_get_cache_keyMethod · 0.95
_this_updateFunction · 0.85
_next_updateFunction · 0.85
popMethod · 0.45

Tested by

no test coverage detected