MCPcopy Create free account
hub / github.com/saltstack/salt / get

Method get

salt/utils/mmap_cache.py:1355–1407  ·  view source on GitHub ↗

Return the value stored for *key*, or *default* if not found. Values stored with ``value=None`` (set mode) return ``True``. String values are returned as ``str``; raw ``bytes`` values (stored via ``put(key, bytes_value)``) are returned as ``bytes``. Returns

(self, key, default=None)

Source from the content-addressed store, hash-verified

1353 return False
1354
1355 def get(self, key, default=None):
1356 """
1357 Return the value stored for *key*, or *default* if not found.
1358
1359 Values stored with ``value=None`` (set mode) return ``True``.
1360 String values are returned as ``str``; raw ``bytes`` values (stored via
1361 ``put(key, bytes_value)``) are returned as ``bytes``.
1362
1363 Returns *default* if the heap record fails a CRC check
1364 (``verify_checksums=True``), logging an error.
1365 """
1366 with self._thread_lock:
1367 if not self.open(write=False):
1368 return default
1369
1370 key_bytes = salt.utils.stringutils.to_bytes(key)[: self.key_size]
1371 h = self._hash(key_bytes)
1372 data_size = self.size - 1
1373
1374 for i in range(data_size):
1375 slot = ((h - 1 + i) % data_size) + 1
1376 offset = slot * self.slot_size
1377 status = self._mm[offset]
1378
1379 if status == EMPTY:
1380 return default
1381 if status == DELETED:
1382 continue
1383 if self._read_slot_key(offset) != key_bytes:
1384 continue
1385
1386 heap_off, length, _ = self._read_slot_pointer(offset)
1387 if length == 0:
1388 return True
1389
1390 raw = self._read_from_heap(heap_off, length)
1391 if raw is None:
1392 return default
1393
1394 # ``_read_from_heap`` returns exactly ``length`` value bytes
1395 # (CRC verified separately). Do NOT rstrip NUL bytes — that
1396 # would corrupt any binary value whose serialised form ends
1397 # in ``\x00`` (e.g. a msgpack-encoded dict with a trailing
1398 # zero integer). See BUG.md.
1399 if not raw:
1400 return True
1401
1402 try:
1403 return salt.utils.stringutils.to_unicode(raw)
1404 except (UnicodeDecodeError, AttributeError):
1405 return raw
1406
1407 return default
1408
1409 def get_mtime(self, key):
1410 """

Calls 5

openMethod · 0.95
_hashMethod · 0.95
_read_slot_keyMethod · 0.95
_read_slot_pointerMethod · 0.95
_read_from_heapMethod · 0.95