MCPcopy Index your code
hub / github.com/RustPython/RustPython / __setitem__

Method __setitem__

Lib/mailbox.py:1055–1077  ·  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

1053 os.remove(path)
1054
1055 def __setitem__(self, key, message):
1056 """Replace the keyed message; raise KeyError if it doesn't exist."""
1057 path = os.path.join(self._path, str(key))
1058 try:
1059 f = open(path, 'rb+')
1060 except OSError as e:
1061 if e.errno == errno.ENOENT:
1062 raise KeyError('No message with key: %s' % key)
1063 else:
1064 raise
1065 try:
1066 if self._locked:
1067 _lock_file(f)
1068 try:
1069 os.close(os.open(path, os.O_WRONLY | os.O_TRUNC))
1070 self._dump_message(message, f)
1071 if isinstance(message, MHMessage):
1072 self._dump_sequences(message, key)
1073 finally:
1074 if self._locked:
1075 _unlock_file(f)
1076 finally:
1077 _sync_close(f)
1078
1079 def get_message(self, key):
1080 """Return a Message representation or raise a KeyError."""

Callers 2

__init__Method · 0.45
__setitem__Method · 0.45

Calls 11

_dump_sequencesMethod · 0.95
strFunction · 0.85
_lock_fileFunction · 0.85
isinstanceFunction · 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