MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / __setitem__

Method __setitem__

tools/python-3.11.9-amd64/Lib/mailbox.py:999–1021  ·  view source on GitHub ↗

Replace the keyed message; raise KeyError if it doesn't exist.

(self, key, message)

Source from the content-addressed store, hash-verified

997 os.remove(path)
998
999 def __setitem__(self, key, message):
1000 """Replace the keyed message; raise KeyError if it doesn't exist."""
1001 path = os.path.join(self._path, str(key))
1002 try:
1003 f = open(path, 'rb+')
1004 except OSError as e:
1005 if e.errno == errno.ENOENT:
1006 raise KeyError('No message with key: %s' % key)
1007 else:
1008 raise
1009 try:
1010 if self._locked:
1011 _lock_file(f)
1012 try:
1013 os.close(os.open(path, os.O_WRONLY | os.O_TRUNC))
1014 self._dump_message(message, f)
1015 if isinstance(message, MHMessage):
1016 self._dump_sequences(message, key)
1017 finally:
1018 if self._locked:
1019 _unlock_file(f)
1020 finally:
1021 _sync_close(f)
1022
1023 def get_message(self, key):
1024 """Return a Message representation or raise a KeyError."""

Callers 2

__init__Method · 0.45
__setitem__Method · 0.45

Calls 10

_dump_sequencesMethod · 0.95
strFunction · 0.85
_lock_fileFunction · 0.85
_unlock_fileFunction · 0.85
_sync_closeFunction · 0.85
_dump_messageMethod · 0.80
openFunction · 0.70
joinMethod · 0.45
closeMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected