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

Method __setitem__

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

351 pass
352
353 def __setitem__(self, key, message):
354 """Replace the keyed message; raise KeyError if it doesn't exist."""
355 old_subpath = self._lookup(key)
356 temp_key = self.add(message)
357 temp_subpath = self._lookup(temp_key)
358 if isinstance(message, MaildirMessage):
359 # temp's subdir and suffix were specified by message.
360 dominant_subpath = temp_subpath
361 else:
362 # temp's subdir and suffix were defaults from add().
363 dominant_subpath = old_subpath
364 subdir = os.path.dirname(dominant_subpath)
365 if self.colon in dominant_subpath:
366 suffix = self.colon + dominant_subpath.split(self.colon)[-1]
367 else:
368 suffix = ''
369 self.discard(key)
370 tmp_path = os.path.join(self._path, temp_subpath)
371 new_path = os.path.join(self._path, subdir, key + suffix)
372 if isinstance(message, MaildirMessage):
373 os.utime(tmp_path,
374 (os.path.getatime(tmp_path), message.get_date()))
375 # No file modification should be done after the file is moved to its
376 # final position in order to prevent race conditions with changes
377 # from other programs
378 os.rename(tmp_path, new_path)
379
380 def get_message(self, key):
381 """Return a Message representation or raise a KeyError."""

Callers

nothing calls this directly

Calls 9

_lookupMethod · 0.95
addMethod · 0.95
discardMethod · 0.95
utimeMethod · 0.80
get_dateMethod · 0.80
dirnameMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45
renameMethod · 0.45

Tested by

no test coverage detected