MCPcopy Index your code
hub / github.com/python/cpython / __setitem__

Method __setitem__

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

1060 os.remove(path)
1061
1062 def __setitem__(self, key, message):
1063 """Replace the keyed message; raise KeyError if it doesn't exist."""
1064 path = os.path.join(self._path, str(key))
1065 try:
1066 f = open(path, 'rb+')
1067 except OSError as e:
1068 if e.errno == errno.ENOENT:
1069 raise KeyError('No message with key: %s' % key)
1070 else:
1071 raise
1072 try:
1073 if self._locked:
1074 _lock_file(f)
1075 try:
1076 os.close(os.open(path, os.O_WRONLY | os.O_TRUNC))
1077 self._dump_message(message, f)
1078 if isinstance(message, MHMessage):
1079 self._dump_sequences(message, key)
1080 finally:
1081 if self._locked:
1082 _unlock_file(f)
1083 finally:
1084 _sync_close(f)
1085
1086 def get_message(self, key):
1087 """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