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

Method __setitem__

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

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected